@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
@@ -0,0 +1,522 @@
1
+ # LAT-001: Gesture Visual Customization and Renderer Hooks
2
+
3
+ ## Status
4
+
5
+ Partially implemented.
6
+
7
+ The current implementation supports shape triggers, optional `visual` rule metadata, legacy `events` marker mappings, and `markers` mappings. Native gesture rendering remains inside `MouseGestureController`; moving gesture visuals onto the shared overlay canvas is still pending.
8
+
9
+ This is the first Lattices engineering proposal in the `LAT-00n` series, following the same proposal-numbering spirit as the `SCO-00n` documents used for Scout/OpenScout planning.
10
+
11
+ This document covers how to productize the recent mouse gesture and visual customization prototypes without letting decoration leak into the recognition or action-dispatch fast path.
12
+
13
+ ## Summary
14
+
15
+ Lattices now has the bones of a gesture system that feels unusually alive for a macOS workspace tool: low-level mouse capture, shape recognition, shortcut matching, immediate native action dispatch, and a fallback overlay that can draw paths, markers, and result labels.
16
+
17
+ The next question is whether customization should become a supported product surface. The answer proposed here is yes, but with a hard boundary:
18
+
19
+ - gesture recognition and action dispatch remain native, synchronous, and fast
20
+ - custom rendering is declarative, best-effort, and optional
21
+ - user assets and external renderers never block or decide actions
22
+ - normal customization should not require recompiling the app
23
+
24
+ The first supported model should be a declarative `visual` block on mouse shortcut rules, backed by native theme presets and marker-to-animation mappings. Real Lottie playback can follow once the configuration model is stable. A plugin or XPC renderer can come later, after the native path has proven the contract.
25
+
26
+ ## Current Gesture Pipeline
27
+
28
+ The gesture pipeline lives mainly in:
29
+
30
+ - `apps/mac/Sources/Core/Input/MouseGestureController.swift`
31
+ - `apps/mac/Sources/Core/Input/MouseGestureConfig.swift`
32
+ - `apps/mac/Sources/Core/Input/MouseShortcutStore.swift`
33
+ - `apps/mac/Sources/Core/Input/ShapeRecognizer.swift`
34
+
35
+ The current/prototyped flow is:
36
+
37
+ 1. A CG event tap captures mouse button and movement events.
38
+ 2. `MouseGestureController` starts and updates gesture sessions, tracking button state, phase, and path points.
39
+ 3. Movement points are fed to `ShapeRecognizer`, which compresses raw motion into direction runs.
40
+ 4. Recognized shapes such as `l-shape-down-right` become trigger facts.
41
+ 5. `MouseShortcutStore` matches a `MouseShortcutTriggerEvent` against enabled `MouseShortcutRule` entries.
42
+ 6. The matched rule dispatches its native action immediately.
43
+ 7. `MouseGestureOverlay` and `MouseGestureOverlayView`, currently nested in `MouseGestureController.swift`, render the fallback/native gesture feedback.
44
+
45
+ The important split is already visible: input capture, recognition, rule matching, and action dispatch form the control path. Overlay drawing is feedback.
46
+
47
+ ## What Was Prototyped
48
+
49
+ Recent prototype work explored both input semantics and visual expression.
50
+
51
+ Input and matching:
52
+
53
+ - shape triggers
54
+ - right, back, forward, and middle button handling
55
+ - MX back/forward aliases
56
+ - a back-button L shape that activates iTerm
57
+ - native action dispatch that stays immediate
58
+
59
+ Visual feedback:
60
+
61
+ - path drawing instead of a single direction arrow
62
+ - Bezier/graffiti trail rendering
63
+ - guide dots inspired by Android pattern lock
64
+ - satisfying result labels such as `iTerm FOCUSED`
65
+ - a `visual` block on shortcut rules
66
+ - a native stand-in for a custom animated character
67
+
68
+ The visual customization proof of concept added optional rule metadata:
69
+
70
+ ```json
71
+ {
72
+ "visual": {
73
+ "renderer": "lottie",
74
+ "asset": "~/.lattices/gesture-assets/cat.json",
75
+ "character": "cat",
76
+ "events": {
77
+ "updated": "follow",
78
+ "recognized:l-shape-down-right": "pounce",
79
+ "completed.success": "celebrate",
80
+ "completed.failure": "confused"
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ Today, `renderer: "lottie"` is a shim/POC name, not a real Lottie dependency. The native renderer draws a small reactive cat/avatar as a stand-in for an eventual Lottie asset.
87
+
88
+ That is a good prototype shape because it tests the user-facing contract without prematurely committing to a rendering engine.
89
+
90
+ ## Architecture Principle
91
+
92
+ Recognition and action dispatch are the fast path. They must never wait on:
93
+
94
+ - custom rendering
95
+ - scripts
96
+ - Lottie playback
97
+ - XPC processes
98
+ - user-provided assets
99
+ - filesystem reads after gesture start
100
+ - network access
101
+
102
+ Visual customization is decorative. It can make gestures more legible, delightful, and personal, but it cannot become part of whether a gesture succeeds.
103
+
104
+ In practical terms:
105
+
106
+ - if a renderer fails, the action still runs
107
+ - if an asset is missing, the native fallback overlay appears
108
+ - if an external renderer is slow, it drops frames or misses the gesture
109
+ - if config is invalid, the rule can still match using native trigger/action fields
110
+ - action success/failure is reported from the action layer, not inferred from animation state
111
+
112
+ This boundary should be visible in the code. The gesture controller can emit visual events, but renderers should consume snapshots or markers asynchronously. They should not own recognition state.
113
+
114
+ ## Proposed Customization Model
115
+
116
+ ### 1. Declarative `visual` block first
117
+
118
+ Mouse shortcut rules should support a stable optional `visual` block:
119
+
120
+ ```json
121
+ {
122
+ "id": "back-l-iterm",
123
+ "enabled": true,
124
+ "device": "any",
125
+ "trigger": {
126
+ "button": "back",
127
+ "kind": "shape",
128
+ "shape": "l-shape-down-right"
129
+ },
130
+ "action": {
131
+ "type": "app.activate",
132
+ "app": "iTerm"
133
+ },
134
+ "visual": {
135
+ "renderer": "native",
136
+ "theme": "graffiti",
137
+ "markers": {
138
+ "updated": "follow",
139
+ "recognized:l-shape-down-right": "commit",
140
+ "completed.success": "success",
141
+ "completed.failure": "error"
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ The `visual` block should be optional and ignored by older versions where possible. Its first stable fields should be:
148
+
149
+ | Field | Type | Purpose |
150
+ |---|---|---|
151
+ | `renderer` | string | Selects renderer family: `native`, later `lottie`, later `external` |
152
+ | `theme` | string? | Native preset name such as `minimal`, `graffiti`, `pattern`, `avatar` |
153
+ | `asset` | string? | Local asset reference for renderer families that need it |
154
+ | `character` | string? | Optional named character/avatar inside a renderer or asset pack |
155
+ | `markers` or `events` | object | Maps gesture markers to renderer actions |
156
+
157
+ The POC uses `events`; the product model should choose one name. `markers` is slightly clearer because the keys are not all raw system events. They are renderer-facing semantic markers derived from gesture state.
158
+
159
+ ### 2. Theme presets
160
+
161
+ Before exposing arbitrary assets as the main path, ship native presets:
162
+
163
+ - `minimal`: simple path and endpoint feedback
164
+ - `graffiti`: Bezier trail with energetic completion burst
165
+ - `pattern`: guide dots and shape lock-in feedback
166
+ - `avatar`: native character-style feedback, similar to the POC cat
167
+ - `quiet`: subtle feedback for users who want confirmation without flourish
168
+
169
+ Presets give users customization without loading code or assets. They also give maintainers a reference for the renderer contract.
170
+
171
+ ### 3. Marker mapping
172
+
173
+ Renderer-facing markers should be small, named, and phase-based:
174
+
175
+ | Marker | Meaning |
176
+ |---|---|
177
+ | `started` | Gesture session began |
178
+ | `updated` | Path changed |
179
+ | `recognized:<shape>` | Recognizer has a likely shape |
180
+ | `matched:<rule-id>` | Rule matched |
181
+ | `completed.success` | Action completed successfully |
182
+ | `completed.failure` | Action failed or no rule matched |
183
+ | `cancelled` | Gesture was cancelled |
184
+
185
+ Renderers can map these to animation names, effects, or state transitions:
186
+
187
+ ```json
188
+ {
189
+ "markers": {
190
+ "started": "wake",
191
+ "updated": "follow",
192
+ "recognized:l-shape-down-right": "pounce",
193
+ "completed.success": "celebrate",
194
+ "completed.failure": "confused",
195
+ "cancelled": "hide"
196
+ }
197
+ }
198
+ ```
199
+
200
+ The control path emits facts. The renderer interprets those facts.
201
+
202
+ ### 4. Asset references
203
+
204
+ Asset references should be local file paths or app-bundled names:
205
+
206
+ ```json
207
+ {
208
+ "visual": {
209
+ "renderer": "lottie",
210
+ "asset": "~/.lattices/gesture-assets/cat.json",
211
+ "markers": {
212
+ "updated": "follow",
213
+ "completed.success": "celebrate"
214
+ }
215
+ }
216
+ }
217
+ ```
218
+
219
+ Rules:
220
+
221
+ - expand `~` explicitly
222
+ - resolve relative paths relative to `~/.lattices/`, not the current project
223
+ - do not fetch remote URLs
224
+ - validate extension and size before loading
225
+ - cache parsed assets outside the gesture hot path
226
+ - fall back to `native` if loading fails
227
+
228
+ ### 5. Real Lottie player later
229
+
230
+ The current native shim should not pretend to be production Lottie. The roadmap should be:
231
+
232
+ 1. stabilize the rule schema and marker model
233
+ 2. ship native presets
234
+ 3. add a real Lottie player behind the same renderer protocol
235
+ 4. keep Lottie playback isolated from recognition and action dispatch
236
+
237
+ This avoids coupling the configuration surface to the first graphics library chosen.
238
+
239
+ ### 6. Optional external renderer or XPC later
240
+
241
+ External renderers are powerful, but they are also where latency, crash, and security complexity enters. They should be a later feature, probably via XPC rather than arbitrary process execution.
242
+
243
+ The contract should look like a one-way visual event stream:
244
+
245
+ - Lattices sends gesture snapshots and markers.
246
+ - The renderer returns nothing that affects recognition or actions.
247
+ - The renderer may request drawing surfaces only through a narrow API.
248
+ - Timeouts and crashes are expected and non-fatal.
249
+
250
+ The open source nature of Lattices means users can always recompile experiments. Product customization should be easier and safer than that.
251
+
252
+ ## Config Examples
253
+
254
+ ### Back Button L to iTerm with Native Visual Markers
255
+
256
+ ```json
257
+ {
258
+ "id": "back-l-iterm",
259
+ "enabled": true,
260
+ "device": "any",
261
+ "trigger": {
262
+ "button": "back",
263
+ "kind": "shape",
264
+ "shape": "l-shape-down-right"
265
+ },
266
+ "action": {
267
+ "type": "app.activate",
268
+ "app": "iTerm"
269
+ },
270
+ "visual": {
271
+ "renderer": "native",
272
+ "theme": "pattern",
273
+ "markers": {
274
+ "started": "show-guides",
275
+ "updated": "draw-path",
276
+ "recognized:l-shape-down-right": "lock-shape",
277
+ "completed.success": "success-label",
278
+ "completed.failure": "miss-label"
279
+ }
280
+ }
281
+ }
282
+ ```
283
+
284
+ ### Back Button L to iTerm with Future Lottie Asset
285
+
286
+ ```json
287
+ {
288
+ "id": "back-l-iterm",
289
+ "enabled": true,
290
+ "device": "any",
291
+ "trigger": {
292
+ "button": "back",
293
+ "kind": "shape",
294
+ "shape": "l-shape-down-right"
295
+ },
296
+ "action": {
297
+ "type": "app.activate",
298
+ "app": "iTerm"
299
+ },
300
+ "visual": {
301
+ "renderer": "lottie",
302
+ "asset": "~/.lattices/gesture-assets/cat.json",
303
+ "character": "cat",
304
+ "markers": {
305
+ "started": "wake",
306
+ "updated": "follow",
307
+ "recognized:l-shape-down-right": "pounce",
308
+ "completed.success": "celebrate",
309
+ "completed.failure": "confused",
310
+ "cancelled": "hide"
311
+ }
312
+ }
313
+ }
314
+ ```
315
+
316
+ ### Quiet Native Preset
317
+
318
+ ```json
319
+ {
320
+ "id": "middle-l-palette",
321
+ "enabled": true,
322
+ "trigger": {
323
+ "button": "middle",
324
+ "kind": "shape",
325
+ "shape": "l-shape-down-right"
326
+ },
327
+ "action": {
328
+ "type": "palette.open"
329
+ },
330
+ "visual": {
331
+ "renderer": "native",
332
+ "theme": "quiet"
333
+ }
334
+ }
335
+ ```
336
+
337
+ ## Latency Considerations
338
+
339
+ Gesture UX is latency-sensitive in two places:
340
+
341
+ - recognition should keep up with pointer movement
342
+ - action dispatch should happen as soon as the gesture commits
343
+
344
+ Renderer latency is allowed to be worse than action latency. The user should never feel that an animation is in charge of the system.
345
+
346
+ Implementation guidelines:
347
+
348
+ - use immutable gesture snapshots for renderer updates
349
+ - throttle rendering updates independently from event capture
350
+ - pre-load and validate assets when config changes, not when the gesture begins
351
+ - cap path point history passed to renderers
352
+ - drop visual frames under pressure
353
+ - keep completion labels tied to action receipts, not animation callbacks
354
+
355
+ Target behavior:
356
+
357
+ - action dispatch remains effectively immediate after match
358
+ - native visual feedback tracks the pointer smoothly
359
+ - custom renderer failure is invisible except for fallback visuals or debug logs
360
+
361
+ ## Stability Considerations
362
+
363
+ The gesture system sits near global input, so failure modes must be boring.
364
+
365
+ Renderer failures should not:
366
+
367
+ - disable the event tap
368
+ - wedge gesture state
369
+ - prevent shortcut matching
370
+ - crash the app
371
+ - leave persistent overlay windows stuck on screen
372
+
373
+ Recommended boundaries:
374
+
375
+ - a `GestureVisualRenderer` protocol with small methods such as `start`, `update`, `mark`, `complete`, `cancel`
376
+ - a native fallback renderer that is always available
377
+ - renderer selection that can fail closed to `native`
378
+ - defensive validation of unknown marker names
379
+ - debug logging for invalid visuals, but no noisy user-facing alerts during gestures
380
+
381
+ ## Security Considerations
382
+
383
+ Even though Lattices is open source, normal customization should not require recompilation. That means configuration and assets become part of the product surface and need constraints.
384
+
385
+ For MVP:
386
+
387
+ - no remote asset URLs
388
+ - no shell commands in `visual`
389
+ - no arbitrary scripts
390
+ - no executable plugins
391
+ - local assets only
392
+ - size limits for loaded assets
393
+ - clear fallback when assets are missing or invalid
394
+
395
+ For a future external renderer:
396
+
397
+ - prefer XPC over raw process execution
398
+ - use a narrow, documented message protocol
399
+ - treat renderer output as pixels or visual state only
400
+ - never accept action decisions from the renderer
401
+ - add a user-visible trust/install flow if third-party renderer bundles are supported
402
+
403
+ ## Proposed Internal Shape
404
+
405
+ The implementation should keep the current architecture but name the boundary more explicitly.
406
+
407
+ Possible types:
408
+
409
+ ```swift
410
+ struct GestureVisualConfig {
411
+ let renderer: GestureVisualRendererID
412
+ let theme: String?
413
+ let asset: String?
414
+ let character: String?
415
+ let markers: [String: String]
416
+ }
417
+
418
+ struct GestureVisualSnapshot {
419
+ let sessionID: UUID
420
+ let phase: GesturePhase
421
+ let button: MouseShortcutButton
422
+ let points: [CGPoint]
423
+ let recognizedShape: String?
424
+ let matchedRuleID: String?
425
+ }
426
+
427
+ protocol GestureVisualRenderer {
428
+ func start(_ snapshot: GestureVisualSnapshot, config: GestureVisualConfig)
429
+ func update(_ snapshot: GestureVisualSnapshot)
430
+ func mark(_ marker: String, snapshot: GestureVisualSnapshot)
431
+ func complete(_ marker: String, snapshot: GestureVisualSnapshot)
432
+ func cancel(_ snapshot: GestureVisualSnapshot)
433
+ }
434
+ ```
435
+
436
+ The exact Swift names can differ. The important part is that renderers consume snapshots and markers; they do not mutate recognition state or decide actions.
437
+
438
+ ## Phased Roadmap
439
+
440
+ ### Phase 0: POC Cleanup
441
+
442
+ Goal: make the prototype understandable and safe to keep iterating.
443
+
444
+ - keep native avatar/Lottie shim clearly labeled as POC
445
+ - document current supported marker keys
446
+ - ensure missing or invalid visual config falls back to native overlay
447
+ - verify back/forward button aliases and shape matching remain independent from visuals
448
+
449
+ ### Phase 1: MVP Native Customization
450
+
451
+ Goal: support real user customization without external dependencies.
452
+
453
+ - stabilize the `visual` schema
454
+ - support `renderer: "native"`
455
+ - ship a small set of native themes
456
+ - support marker mapping for native themes
457
+ - load visual config from normal shortcut config
458
+ - add diagnostics for invalid visuals
459
+ - keep existing native overlay as fallback
460
+
461
+ ### Phase 2: Real Lottie Integration
462
+
463
+ Goal: make `renderer: "lottie"` honest.
464
+
465
+ - add a real Lottie player dependency or embedded playback implementation
466
+ - validate and cache Lottie assets outside the gesture hot path
467
+ - map markers to animation segments or named states
468
+ - enforce size and complexity limits
469
+ - provide at least one bundled example asset
470
+
471
+ ### Phase 3: Renderer Hooks and XPC
472
+
473
+ Goal: enable deeper experiments without compromising the app.
474
+
475
+ - define a one-way renderer event protocol
476
+ - run external renderers out of process
477
+ - add crash and timeout handling
478
+ - add user trust/install UX for third-party renderers
479
+ - keep all action decisions inside Lattices
480
+
481
+ ## Open Questions
482
+
483
+ - Should the field be named `events` to match the prototype, or `markers` to better describe the stable concept?
484
+ - Should visual config live only on individual rules, or should users be able to define reusable named visual profiles?
485
+ - How much of `MouseGestureOverlay` should become a renderer implementation versus remaining a fallback shell?
486
+ - Should marker names be fully free-form, or should unknown keys be rejected during config validation?
487
+ - Do we want app-level theme defaults, per-device defaults, or only per-rule visuals for MVP?
488
+ - Should `completed.failure` mean "no rule matched", "action failed", or both with more specific submarkers?
489
+ - Where should user assets live: `~/.lattices/gesture-assets/`, app support, or both?
490
+
491
+ ## Acceptance Criteria
492
+
493
+ For the MVP:
494
+
495
+ - A shortcut rule can include a `visual` block without changing trigger or action behavior.
496
+ - A back-button `l-shape-down-right` rule can activate iTerm and show native marker-based feedback.
497
+ - Invalid visual config falls back to the native overlay and does not prevent the action.
498
+ - Missing assets do not crash the app or delay gesture completion.
499
+ - Recognition and action dispatch do not wait on renderer work.
500
+ - Native themes can render started, updated, recognized, success, failure, and cancelled states.
501
+ - The config format is documented with at least one complete example.
502
+ - Debug diagnostics make renderer fallback understandable to maintainers.
503
+
504
+ For later Lottie support:
505
+
506
+ - `renderer: "lottie"` uses a real Lottie player, not the native shim.
507
+ - Lottie assets are validated and cached before gesture start.
508
+ - Marker mappings can target named animations or segments.
509
+ - Lottie renderer failure falls back to native rendering without affecting actions.
510
+
511
+ ## Recommendation
512
+
513
+ Productize visual customization, but productize it as a renderer contract rather than as a graphics feature.
514
+
515
+ The useful product surface is not "play a cat animation." It is:
516
+
517
+ - gestures have stable semantic markers
518
+ - users can bind visual feedback to those markers
519
+ - Lattices keeps input and action dispatch fast
520
+ - renderers are replaceable decoration
521
+
522
+ That gives maintainers room to ship the fun parts without letting them become load-bearing.