@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,555 @@
1
+ import DeckKit
2
+ import Foundation
3
+
4
+ struct LatticesCompanionCockpitLayout: Codable, Equatable {
5
+ struct Page: Codable, Equatable, Identifiable {
6
+ var id: String
7
+ var title: String
8
+ var subtitle: String?
9
+ var columns: Int
10
+ var slotIDs: [String]
11
+
12
+ init(
13
+ id: String,
14
+ title: String,
15
+ subtitle: String? = nil,
16
+ columns: Int = 4,
17
+ slotIDs: [String]
18
+ ) {
19
+ self.id = id
20
+ self.title = title
21
+ self.subtitle = subtitle
22
+ self.columns = columns
23
+ self.slotIDs = slotIDs
24
+ }
25
+ }
26
+
27
+ var pages: [Page]
28
+ }
29
+
30
+ enum LatticesCompanionShortcutCategory: String, CaseIterable, Identifiable {
31
+ case voice
32
+ case agent
33
+ case system
34
+ case switching
35
+ case layout
36
+ case mouse
37
+ case dev
38
+ case media
39
+
40
+ var id: String { rawValue }
41
+
42
+ var title: String {
43
+ switch self {
44
+ case .voice:
45
+ return "Voice"
46
+ case .agent:
47
+ return "Agent"
48
+ case .system:
49
+ return "System"
50
+ case .switching:
51
+ return "Switching"
52
+ case .layout:
53
+ return "Layout"
54
+ case .mouse:
55
+ return "Mouse"
56
+ case .dev:
57
+ return "Dev"
58
+ case .media:
59
+ return "Media"
60
+ }
61
+ }
62
+
63
+ var tintToken: String {
64
+ switch self {
65
+ case .voice:
66
+ return "red"
67
+ case .agent:
68
+ return "violet"
69
+ case .system:
70
+ return "amber"
71
+ case .switching, .layout:
72
+ return "blue"
73
+ case .mouse:
74
+ return "teal"
75
+ case .dev:
76
+ return "green"
77
+ case .media:
78
+ return "pink"
79
+ }
80
+ }
81
+ }
82
+
83
+ struct LatticesCompanionShortcutDefinition: Identifiable {
84
+ let id: String
85
+ let title: String
86
+ let subtitle: String?
87
+ let iconSystemName: String
88
+ let accentToken: String?
89
+ let category: LatticesCompanionShortcutCategory
90
+ let deckID: String? = nil
91
+ }
92
+
93
+ enum LatticesCompanionCockpitCatalog {
94
+ private struct RenderedShortcut {
95
+ var title: String
96
+ var subtitle: String?
97
+ var iconSystemName: String
98
+ var accentToken: String?
99
+ var deckID: String? = nil
100
+ var categoryTint: String? = nil
101
+ var actionID: String?
102
+ var payload: [String: DeckValue]
103
+ var isEnabled: Bool
104
+ var isActive: Bool
105
+ }
106
+
107
+ static let slotCount = 16
108
+
109
+ static let defaultLayout = LatticesCompanionCockpitLayout(
110
+ pages: [
111
+ .init(
112
+ id: "command",
113
+ title: "Command",
114
+ subtitle: "Core voice, system, and workspace moves",
115
+ columns: 4,
116
+ slotIDs: [
117
+ "voice-toggle", "voice-cancel", "key-escape", "key-enter",
118
+ "switch-app-prev", "switch-app-next", "switch-window-prev", "switch-window-next",
119
+ "layout-optimize", "mouse-find", "mouse-summon", "key-space",
120
+ "place-left", "place-right", "place-center", "place-maximize"
121
+ ]
122
+ ),
123
+ .init(
124
+ id: "dev",
125
+ title: "Dev",
126
+ subtitle: "Terminal, agent, and edit shortcuts",
127
+ columns: 4,
128
+ slotIDs: [
129
+ "key-copy", "key-paste", "key-undo", "key-shift-tab",
130
+ "place-left", "place-right", "resize-wider", "resize-narrower",
131
+ "switch-window-prev", "switch-window-next", "switch-app-prev", "switch-app-next",
132
+ "layout-optimize", "mouse-find", "key-up", "key-down"
133
+ ]
134
+ ),
135
+ .init(
136
+ id: "media",
137
+ title: "Media",
138
+ subtitle: "Media-friendly window and keyboard controls",
139
+ columns: 4,
140
+ slotIDs: [
141
+ "key-space", "key-escape", "key-left", "key-right",
142
+ "place-center", "place-maximize", "resize-grow", "resize-shrink",
143
+ "switch-app-prev", "switch-app-next", "mouse-summon", "mouse-find",
144
+ "place-top-left", "place-top-right", "place-bottom-left", "place-bottom-right"
145
+ ]
146
+ ),
147
+ .init(
148
+ id: "windows",
149
+ title: "Windows",
150
+ subtitle: "Placement and resize macros for the frontmost window",
151
+ columns: 4,
152
+ slotIDs: [
153
+ "place-top-left", "place-top-right", "place-bottom-left", "place-bottom-right",
154
+ "place-left-third", "place-center-third", "place-right-third", "place-center",
155
+ "resize-wider", "resize-narrower", "resize-taller", "resize-shorter",
156
+ "resize-grow", "resize-shrink", "place-left", "place-right"
157
+ ]
158
+ ),
159
+ .init(
160
+ id: "voice",
161
+ title: "Voice",
162
+ subtitle: "Hands-off voice and transcript controls",
163
+ columns: 4,
164
+ slotIDs: [
165
+ "voice-toggle", "voice-cancel", "key-escape", "key-enter",
166
+ "layout-optimize", "switch-app-prev", "switch-app-next", "mouse-find",
167
+ "place-left", "place-right", "place-center", "place-maximize",
168
+ "key-copy", "key-paste", "key-undo", "key-space"
169
+ ]
170
+ ),
171
+ ]
172
+ )
173
+
174
+ static let shortcuts: [LatticesCompanionShortcutDefinition] = [
175
+ .init(id: "", title: "Empty", subtitle: "Leave this slot unused", iconSystemName: "square.dashed", accentToken: nil, category: .layout),
176
+ .init(id: "voice-toggle", title: "Voice Toggle", subtitle: "Start or stop hands-off voice", iconSystemName: "waveform.badge.mic", accentToken: "voice", category: .voice),
177
+ .init(id: "voice-cancel", title: "Voice Cancel", subtitle: "Cancel the current voice turn", iconSystemName: "xmark.circle.fill", accentToken: "rose", category: .voice),
178
+ .init(id: "switch-app-prev", title: "Previous App", subtitle: "Focus the prior visible application", iconSystemName: "chevron.left.square.fill", accentToken: "switch", category: .switching),
179
+ .init(id: "switch-app-next", title: "Next App", subtitle: "Focus the next visible application", iconSystemName: "chevron.right.square.fill", accentToken: "switch", category: .switching),
180
+ .init(id: "switch-window-prev", title: "Previous Window", subtitle: "Step backward through visible windows", iconSystemName: "rectangle.on.rectangle.circle.fill", accentToken: "switch", category: .switching),
181
+ .init(id: "switch-window-next", title: "Next Window", subtitle: "Step forward through visible windows", iconSystemName: "rectangle.on.rectangle.circle", accentToken: "switch", category: .switching),
182
+ .init(id: "layout-optimize", title: "Optimize", subtitle: "Retile visible windows", iconSystemName: "rectangle.3.group.fill", accentToken: "layout", category: .layout),
183
+ .init(id: "place-left", title: "Place Left", subtitle: "Snap the frontmost window left", iconSystemName: "rectangle.leadinghalf.filled", accentToken: "layout", category: .layout),
184
+ .init(id: "place-right", title: "Place Right", subtitle: "Snap the frontmost window right", iconSystemName: "rectangle.trailinghalf.filled", accentToken: "layout", category: .layout),
185
+ .init(id: "place-top-left", title: "Top Left", subtitle: "Move to the upper-left quarter", iconSystemName: "rectangle.inset.topleft.filled", accentToken: "layout", category: .layout),
186
+ .init(id: "place-top-right", title: "Top Right", subtitle: "Move to the upper-right quarter", iconSystemName: "rectangle.inset.topright.filled", accentToken: "layout", category: .layout),
187
+ .init(id: "place-bottom-left", title: "Bottom Left", subtitle: "Move to the lower-left quarter", iconSystemName: "rectangle.inset.bottomleft.filled", accentToken: "layout", category: .layout),
188
+ .init(id: "place-bottom-right", title: "Bottom Right", subtitle: "Move to the lower-right quarter", iconSystemName: "rectangle.inset.bottomright.filled", accentToken: "layout", category: .layout),
189
+ .init(id: "place-center", title: "Center", subtitle: "Center the frontmost window", iconSystemName: "plus.rectangle.on.rectangle", accentToken: "layout", category: .layout),
190
+ .init(id: "place-maximize", title: "Maximize", subtitle: "Expand to the visible screen", iconSystemName: "macwindow", accentToken: "layout", category: .layout),
191
+ .init(id: "place-left-third", title: "Left Third", subtitle: "Move into the left third", iconSystemName: "rectangle.leadingthird.inset.filled", accentToken: "layout", category: .layout),
192
+ .init(id: "place-center-third", title: "Center Third", subtitle: "Move into the center third", iconSystemName: "rectangle.center.inset.filled", accentToken: "layout", category: .layout),
193
+ .init(id: "place-right-third", title: "Right Third", subtitle: "Move into the right third", iconSystemName: "rectangle.trailingthird.inset.filled", accentToken: "layout", category: .layout),
194
+ .init(id: "resize-wider", title: "Wider", subtitle: "Increase width", iconSystemName: "arrow.left.and.right.circle.fill", accentToken: "layout", category: .layout),
195
+ .init(id: "resize-narrower", title: "Narrower", subtitle: "Reduce width", iconSystemName: "arrow.left.and.right.circle", accentToken: "layout", category: .layout),
196
+ .init(id: "resize-taller", title: "Taller", subtitle: "Increase height", iconSystemName: "arrow.up.and.down.circle.fill", accentToken: "layout", category: .layout),
197
+ .init(id: "resize-shorter", title: "Shorter", subtitle: "Reduce height", iconSystemName: "arrow.up.and.down.circle", accentToken: "layout", category: .layout),
198
+ .init(id: "resize-grow", title: "Grow", subtitle: "Expand both dimensions", iconSystemName: "plus.rectangle.fill.on.rectangle.fill", accentToken: "layout", category: .layout),
199
+ .init(id: "resize-shrink", title: "Shrink", subtitle: "Reduce both dimensions", iconSystemName: "minus.rectangle", accentToken: "layout", category: .layout),
200
+ .init(id: "mouse-find", title: "Find Mouse", subtitle: "Pulse the current cursor position", iconSystemName: "scope", accentToken: "mouse", category: .mouse),
201
+ .init(id: "mouse-summon", title: "Summon Mouse", subtitle: "Bring the cursor to center screen", iconSystemName: "dot.scope", accentToken: "mouse", category: .mouse),
202
+ .init(id: "key-escape", title: "Escape", subtitle: "Send Escape", iconSystemName: "escape", accentToken: "system", category: .system),
203
+ .init(id: "key-copy", title: "Copy", subtitle: "Send Command-C", iconSystemName: "doc.on.doc", accentToken: "system", category: .system),
204
+ .init(id: "key-paste", title: "Paste", subtitle: "Send Command-V", iconSystemName: "doc.on.clipboard", accentToken: "system", category: .system),
205
+ .init(id: "key-undo", title: "Undo", subtitle: "Send Command-Z", iconSystemName: "arrow.uturn.backward", accentToken: "system", category: .system),
206
+ .init(id: "key-shift-tab", title: "Back Tab", subtitle: "Send Shift-Tab", iconSystemName: "arrowshape.turn.up.left", accentToken: "system", category: .system),
207
+ .init(id: "key-space", title: "Space", subtitle: "Send Space", iconSystemName: "space", accentToken: "system", category: .system),
208
+ .init(id: "key-enter", title: "Enter", subtitle: "Send Return", iconSystemName: "return", accentToken: "system", category: .system),
209
+ .init(id: "key-left", title: "Left", subtitle: "Send Left Arrow", iconSystemName: "arrow.left", accentToken: "system", category: .system),
210
+ .init(id: "key-right", title: "Right", subtitle: "Send Right Arrow", iconSystemName: "arrow.right", accentToken: "system", category: .system),
211
+ .init(id: "key-up", title: "Up", subtitle: "Send Up Arrow", iconSystemName: "arrow.up", accentToken: "system", category: .system),
212
+ .init(id: "key-down", title: "Down", subtitle: "Send Down Arrow", iconSystemName: "arrow.down", accentToken: "system", category: .system),
213
+ ]
214
+
215
+ static func definition(for shortcutID: String) -> LatticesCompanionShortcutDefinition? {
216
+ shortcuts.first(where: { $0.id == shortcutID })
217
+ }
218
+
219
+ static func normalized(_ layout: LatticesCompanionCockpitLayout) -> LatticesCompanionCockpitLayout {
220
+ let blueprintPages = defaultLayout.pages
221
+ let existing = Dictionary(uniqueKeysWithValues: layout.pages.map { ($0.id, $0) })
222
+
223
+ return LatticesCompanionCockpitLayout(
224
+ pages: blueprintPages.map { blueprint in
225
+ let current = existing[blueprint.id]
226
+ let slots = normalizedSlots(current?.slotIDs ?? blueprint.slotIDs)
227
+ return .init(
228
+ id: blueprint.id,
229
+ title: current?.title ?? blueprint.title,
230
+ subtitle: current?.subtitle ?? blueprint.subtitle,
231
+ columns: max(2, current?.columns ?? blueprint.columns),
232
+ slotIDs: slots
233
+ )
234
+ }
235
+ )
236
+ }
237
+
238
+ static func renderedState(
239
+ layout: LatticesCompanionCockpitLayout,
240
+ voice: DeckVoiceState?,
241
+ desktop: DeckDesktopSummary?,
242
+ layoutState: DeckLayoutState?
243
+ ) -> DeckCockpitState {
244
+ let normalizedLayout = normalized(layout)
245
+ let focusName = layoutState?.frontmostWindow?.appName ?? desktop?.activeAppName ?? "Mac"
246
+ let detail = desktop?.activeLayerName.map { "Layer: \($0)" } ?? "Quick controls for \(focusName)."
247
+
248
+ return DeckCockpitState(
249
+ title: focusName,
250
+ detail: detail,
251
+ pages: normalizedLayout.pages.map { page in
252
+ DeckCockpitPage(
253
+ id: page.id,
254
+ title: page.title,
255
+ subtitle: page.subtitle,
256
+ columns: page.columns,
257
+ tiles: page.slotIDs.enumerated().map { index, shortcutID in
258
+ renderedTile(
259
+ shortcutID: shortcutID,
260
+ pageID: page.id,
261
+ slotIndex: index,
262
+ voice: voice,
263
+ desktop: desktop,
264
+ layoutState: layoutState
265
+ )
266
+ }
267
+ )
268
+ }
269
+ )
270
+ }
271
+
272
+ private static func normalizedSlots(_ slots: [String]) -> [String] {
273
+ let trimmed = Array(slots.prefix(slotCount))
274
+ if trimmed.count == slotCount {
275
+ return trimmed
276
+ }
277
+ return trimmed + Array(repeating: "", count: slotCount - trimmed.count)
278
+ }
279
+
280
+ private static func renderedTile(
281
+ shortcutID: String,
282
+ pageID: String,
283
+ slotIndex: Int,
284
+ voice: DeckVoiceState?,
285
+ desktop: DeckDesktopSummary?,
286
+ layoutState: DeckLayoutState?
287
+ ) -> DeckCockpitTile {
288
+ let rendered = renderedShortcut(
289
+ for: shortcutID,
290
+ voice: voice,
291
+ desktop: desktop,
292
+ layoutState: layoutState
293
+ )
294
+
295
+ return DeckCockpitTile(
296
+ id: "\(pageID)-\(slotIndex)",
297
+ shortcutID: shortcutID,
298
+ title: rendered.title,
299
+ subtitle: rendered.subtitle,
300
+ iconSystemName: rendered.iconSystemName,
301
+ accentToken: rendered.accentToken,
302
+ deckID: rendered.deckID ?? pageID,
303
+ categoryTint: rendered.categoryTint ?? definition(for: shortcutID)?.category.tintToken,
304
+ actionID: rendered.actionID,
305
+ payload: rendered.payload,
306
+ isEnabled: rendered.isEnabled,
307
+ isActive: rendered.isActive
308
+ )
309
+ }
310
+
311
+ private static func renderedShortcut(
312
+ for shortcutID: String,
313
+ voice: DeckVoiceState?,
314
+ desktop: DeckDesktopSummary?,
315
+ layoutState: DeckLayoutState?
316
+ ) -> RenderedShortcut {
317
+ let frontmostWindow = layoutState?.frontmostWindow
318
+ let activeAppName = desktop?.activeAppName ?? frontmostWindow?.appName
319
+
320
+ if let keyShortcut = keyboardShortcut(for: shortcutID) {
321
+ return keyShortcut
322
+ }
323
+
324
+ switch shortcutID {
325
+ case "voice-toggle":
326
+ let listening = voice?.phase == .listening
327
+ return RenderedShortcut(
328
+ title: listening ? "Stop Voice" : "Start Voice",
329
+ subtitle: listening ? "Stop the current voice capture" : "Begin a hands-off voice turn",
330
+ iconSystemName: listening ? "stop.fill" : "mic.fill",
331
+ accentToken: "voice",
332
+ actionID: "voice.toggle",
333
+ payload: [:],
334
+ isEnabled: true,
335
+ isActive: listening
336
+ )
337
+
338
+ case "voice-cancel":
339
+ return RenderedShortcut(
340
+ title: "Cancel Voice",
341
+ subtitle: "Dismiss the current voice turn",
342
+ iconSystemName: "xmark.circle.fill",
343
+ accentToken: "rose",
344
+ actionID: "voice.cancel",
345
+ payload: [:],
346
+ isEnabled: true,
347
+ isActive: false
348
+ )
349
+
350
+ case "switch-app-prev":
351
+ return RenderedShortcut(
352
+ title: "Prev App",
353
+ subtitle: activeAppName.map { "Now: \($0)" } ?? "Focus the previous visible app",
354
+ iconSystemName: "chevron.left.square.fill",
355
+ accentToken: "switch",
356
+ actionID: "switch.cycleApplication",
357
+ payload: ["direction": .string("previous")],
358
+ isEnabled: true,
359
+ isActive: false
360
+ )
361
+
362
+ case "switch-app-next":
363
+ return RenderedShortcut(
364
+ title: "Next App",
365
+ subtitle: activeAppName.map { "Now: \($0)" } ?? "Focus the next visible app",
366
+ iconSystemName: "chevron.right.square.fill",
367
+ accentToken: "switch",
368
+ actionID: "switch.cycleApplication",
369
+ payload: ["direction": .string("next")],
370
+ isEnabled: true,
371
+ isActive: false
372
+ )
373
+
374
+ case "switch-window-prev":
375
+ return RenderedShortcut(
376
+ title: "Prev Window",
377
+ subtitle: frontmostWindow?.title ?? activeAppName ?? "Focus the previous visible window",
378
+ iconSystemName: "rectangle.on.rectangle.circle.fill",
379
+ accentToken: "switch",
380
+ actionID: "switch.cycleWindow",
381
+ payload: ["direction": .string("previous")],
382
+ isEnabled: true,
383
+ isActive: false
384
+ )
385
+
386
+ case "switch-window-next":
387
+ return RenderedShortcut(
388
+ title: "Next Window",
389
+ subtitle: frontmostWindow?.title ?? activeAppName ?? "Focus the next visible window",
390
+ iconSystemName: "rectangle.on.rectangle.circle",
391
+ accentToken: "switch",
392
+ actionID: "switch.cycleWindow",
393
+ payload: ["direction": .string("next")],
394
+ isEnabled: true,
395
+ isActive: false
396
+ )
397
+
398
+ case "layout-optimize":
399
+ return RenderedShortcut(
400
+ title: "Optimize",
401
+ subtitle: desktop?.activeLayerName ?? "Retile the visible workspace",
402
+ iconSystemName: "rectangle.3.group.fill",
403
+ accentToken: "layout",
404
+ actionID: "layout.optimize",
405
+ payload: [:],
406
+ isEnabled: true,
407
+ isActive: false
408
+ )
409
+
410
+ case "place-left":
411
+ return placementShortcut(title: "Left", subtitle: "Snap left", icon: "rectangle.leadinghalf.filled", placement: "left")
412
+ case "place-right":
413
+ return placementShortcut(title: "Right", subtitle: "Snap right", icon: "rectangle.trailinghalf.filled", placement: "right")
414
+ case "place-top-left":
415
+ return placementShortcut(title: "Top Left", subtitle: "Upper-left quarter", icon: "rectangle.inset.topleft.filled", placement: "top-left")
416
+ case "place-top-right":
417
+ return placementShortcut(title: "Top Right", subtitle: "Upper-right quarter", icon: "rectangle.inset.topright.filled", placement: "top-right")
418
+ case "place-bottom-left":
419
+ return placementShortcut(title: "Bottom Left", subtitle: "Lower-left quarter", icon: "rectangle.inset.bottomleft.filled", placement: "bottom-left")
420
+ case "place-bottom-right":
421
+ return placementShortcut(title: "Bottom Right", subtitle: "Lower-right quarter", icon: "rectangle.inset.bottomright.filled", placement: "bottom-right")
422
+ case "place-center":
423
+ return placementShortcut(title: "Center", subtitle: "Center on screen", icon: "plus.rectangle.on.rectangle", placement: "center")
424
+ case "place-maximize":
425
+ return placementShortcut(title: "Maximize", subtitle: "Fill visible screen", icon: "macwindow", placement: "maximize")
426
+ case "place-left-third":
427
+ return placementShortcut(title: "Left Third", subtitle: "Left column", icon: "rectangle.leadingthird.inset.filled", placement: "left-third")
428
+ case "place-center-third":
429
+ return placementShortcut(title: "Center Third", subtitle: "Middle column", icon: "rectangle.center.inset.filled", placement: "center-third")
430
+ case "place-right-third":
431
+ return placementShortcut(title: "Right Third", subtitle: "Right column", icon: "rectangle.trailingthird.inset.filled", placement: "right-third")
432
+
433
+ case "resize-wider":
434
+ return resizeShortcut(title: "Wider", subtitle: "Increase width", icon: "arrow.left.and.right.circle.fill", dimension: "width", direction: "grow")
435
+ case "resize-narrower":
436
+ return resizeShortcut(title: "Narrower", subtitle: "Reduce width", icon: "arrow.left.and.right.circle", dimension: "width", direction: "shrink")
437
+ case "resize-taller":
438
+ return resizeShortcut(title: "Taller", subtitle: "Increase height", icon: "arrow.up.and.down.circle.fill", dimension: "height", direction: "grow")
439
+ case "resize-shorter":
440
+ return resizeShortcut(title: "Shorter", subtitle: "Reduce height", icon: "arrow.up.and.down.circle", dimension: "height", direction: "shrink")
441
+ case "resize-grow":
442
+ return resizeShortcut(title: "Grow", subtitle: "Expand both axes", icon: "plus.rectangle.fill.on.rectangle.fill", dimension: "both", direction: "grow")
443
+ case "resize-shrink":
444
+ return resizeShortcut(title: "Shrink", subtitle: "Reduce both axes", icon: "minus.rectangle", dimension: "both", direction: "shrink")
445
+
446
+ case "mouse-find":
447
+ return RenderedShortcut(
448
+ title: "Find Mouse",
449
+ subtitle: "Pulse the cursor position",
450
+ iconSystemName: "scope",
451
+ accentToken: "mouse",
452
+ actionID: "mouse.find",
453
+ payload: [:],
454
+ isEnabled: true,
455
+ isActive: false
456
+ )
457
+
458
+ case "mouse-summon":
459
+ return RenderedShortcut(
460
+ title: "Summon Mouse",
461
+ subtitle: "Bring cursor to center",
462
+ iconSystemName: "dot.scope",
463
+ accentToken: "mouse",
464
+ actionID: "mouse.summon",
465
+ payload: [:],
466
+ isEnabled: true,
467
+ isActive: false
468
+ )
469
+
470
+ default:
471
+ return RenderedShortcut(
472
+ title: "Empty",
473
+ subtitle: "Assign an action on the Mac",
474
+ iconSystemName: "square.dashed",
475
+ accentToken: nil,
476
+ actionID: nil,
477
+ payload: [:],
478
+ isEnabled: false,
479
+ isActive: false
480
+ )
481
+ }
482
+ }
483
+
484
+ private static func placementShortcut(
485
+ title: String,
486
+ subtitle: String,
487
+ icon: String,
488
+ placement: String
489
+ ) -> RenderedShortcut {
490
+ RenderedShortcut(
491
+ title: title,
492
+ subtitle: subtitle,
493
+ iconSystemName: icon,
494
+ accentToken: "layout",
495
+ actionID: "layout.placeFrontmost",
496
+ payload: ["placement": .string(placement)],
497
+ isEnabled: true,
498
+ isActive: false
499
+ )
500
+ }
501
+
502
+ private static func resizeShortcut(
503
+ title: String,
504
+ subtitle: String,
505
+ icon: String,
506
+ dimension: String,
507
+ direction: String
508
+ ) -> RenderedShortcut {
509
+ RenderedShortcut(
510
+ title: title,
511
+ subtitle: subtitle,
512
+ iconSystemName: icon,
513
+ accentToken: "layout",
514
+ actionID: "layout.resizeFrontmost",
515
+ payload: [
516
+ "dimension": .string(dimension),
517
+ "direction": .string(direction)
518
+ ],
519
+ isEnabled: true,
520
+ isActive: false
521
+ )
522
+ }
523
+
524
+ private static func keyboardShortcut(for shortcutID: String) -> RenderedShortcut? {
525
+ let shortcuts: [String: (title: String, subtitle: String, icon: String, key: String, modifiers: [String])] = [
526
+ "key-escape": ("Escape", "Send Escape", "escape", "escape", []),
527
+ "key-copy": ("Copy", "Send Command-C", "doc.on.doc", "c", ["command"]),
528
+ "key-paste": ("Paste", "Send Command-V", "doc.on.clipboard", "v", ["command"]),
529
+ "key-undo": ("Undo", "Send Command-Z", "arrow.uturn.backward", "z", ["command"]),
530
+ "key-shift-tab": ("Back Tab", "Send Shift-Tab", "arrowshape.turn.up.left", "tab", ["shift"]),
531
+ "key-space": ("Space", "Send Space", "space", "space", []),
532
+ "key-enter": ("Enter", "Send Return", "return", "enter", []),
533
+ "key-left": ("Left", "Send Left Arrow", "arrow.left", "left", []),
534
+ "key-right": ("Right", "Send Right Arrow", "arrow.right", "right", []),
535
+ "key-up": ("Up", "Send Up Arrow", "arrow.up", "up", []),
536
+ "key-down": ("Down", "Send Down Arrow", "arrow.down", "down", []),
537
+ ]
538
+
539
+ guard let shortcut = shortcuts[shortcutID] else { return nil }
540
+ return RenderedShortcut(
541
+ title: shortcut.title,
542
+ subtitle: shortcut.subtitle,
543
+ iconSystemName: shortcut.icon,
544
+ accentToken: "system",
545
+ categoryTint: LatticesCompanionShortcutCategory.system.tintToken,
546
+ actionID: "keys.send",
547
+ payload: [
548
+ "key": .string(shortcut.key),
549
+ "modifiers": .array(shortcut.modifiers.map { .string($0) })
550
+ ],
551
+ isEnabled: true,
552
+ isActive: false
553
+ )
554
+ }
555
+ }