@snap/valdi 1.0.8 → 1.1.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 (121) hide show
  1. package/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
  2. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
  3. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
  4. package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
  5. package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
  6. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
  7. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  8. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
  9. package/.bootstrap/apps/ui_application/package.json +24 -0
  10. package/.bootstrap/modules/polyglot_bridge_module/BUILD.bazel.template +54 -0
  11. package/.bootstrap/modules/polyglot_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
  12. package/.bootstrap/modules/polyglot_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
  13. package/.bootstrap/modules/polyglot_bridge_module/src/Calculator.d.ts +4 -0
  14. package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
  15. package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
  16. package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
  17. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
  18. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
  19. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
  20. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
  21. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
  22. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
  23. package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
  24. package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
  25. package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
  26. package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
  27. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
  28. package/.metadata/.bazelrc.template +92 -0
  29. package/.metadata/.bazelversion.template +1 -0
  30. package/.metadata/.editorconfig.template +37 -0
  31. package/.metadata/.eslintrc.js.template +27 -0
  32. package/.metadata/.gitignore.template +4 -0
  33. package/.metadata/.prettierrc.json.template +7 -0
  34. package/.metadata/.watchmanconfig.template +8 -0
  35. package/.metadata/AGENTS.md.template +16 -0
  36. package/.metadata/MODULE.bazel.template +62 -0
  37. package/.metadata/README.md.template +31 -0
  38. package/.metadata/config.yaml.template +1 -0
  39. package/.metadata/package.json.template +23 -0
  40. package/.metadata/skill-reference.tsx.template +8 -0
  41. package/.metadata/skill-tests-BUILD.bazel.template +21 -0
  42. package/.metadata/skill-tests-README.md.template +17 -0
  43. package/.metadata/skill.md.template +27 -0
  44. package/bundled-skills/registry.json +14 -2
  45. package/bundled-skills/skills/valdi-animations/skill.md +197 -0
  46. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
  47. package/bundled-skills/skills/valdi-bazel/skill.md +21 -2
  48. package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
  49. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
  50. package/bundled-skills/skills/valdi-custom-view/skill.md +49 -5
  51. package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
  52. package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
  53. package/bundled-skills/skills/valdi-inspect/skill.md +217 -0
  54. package/bundled-skills/skills/valdi-localization/skill.md +142 -0
  55. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
  56. package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
  57. package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
  58. package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
  59. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
  60. package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
  61. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
  62. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
  63. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
  64. package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
  65. package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
  66. package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
  67. package/bundled-skills/skills/valdi-overview/skill.md +7 -4
  68. package/bundled-skills/skills/valdi-perf/skill.md +223 -0
  69. package/bundled-skills/skills/valdi-polyglot-module/skill.md +131 -12
  70. package/bundled-skills/skills/valdi-preview/skill.md +303 -0
  71. package/bundled-skills/skills/valdi-profile/skill.md +126 -0
  72. package/bundled-skills/skills/valdi-setup/skill.md +55 -5
  73. package/bundled-skills/skills/valdi-testing/skill.md +23 -7
  74. package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
  75. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
  76. package/dist/commands/agentCheck.js +184 -0
  77. package/dist/commands/analyze.js +16 -0
  78. package/dist/commands/analyze_commands/duplicates.js +134 -0
  79. package/dist/commands/bootstrap.js +57 -73
  80. package/dist/commands/doctor.js +40 -203
  81. package/dist/commands/hotreload.js +15 -0
  82. package/dist/commands/inspect.js +16 -0
  83. package/dist/commands/inspect_commands/contexts.js +55 -0
  84. package/dist/commands/inspect_commands/devices.js +53 -0
  85. package/dist/commands/inspect_commands/heap.js +59 -0
  86. package/dist/commands/inspect_commands/select.js +43 -0
  87. package/dist/commands/inspect_commands/snapshot.js +129 -0
  88. package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
  89. package/dist/commands/inspect_commands/status.js +68 -0
  90. package/dist/commands/inspect_commands/tree.js +86 -0
  91. package/dist/commands/preview.js +81 -0
  92. package/dist/commands/profile.js +16 -0
  93. package/dist/commands/profile_commands/capture.js +106 -0
  94. package/dist/commands/projectsync.js +9 -7
  95. package/dist/commands/skills_commands/install.js +6 -1
  96. package/dist/commands/skills_commands/update.js +2 -1
  97. package/dist/core/analyze/clusterer.js +150 -0
  98. package/dist/core/analyze/fingerprint.js +2 -0
  99. package/dist/core/analyze/knownPatterns.js +76 -0
  100. package/dist/core/analyze/parser.js +177 -0
  101. package/dist/core/analyze/reporter.js +83 -0
  102. package/dist/core/analyze/scanner.js +172 -0
  103. package/dist/core/analyze/similarity.js +56 -0
  104. package/dist/core/constants.js +1 -1
  105. package/dist/core/packageFiles.spec.js +29 -0
  106. package/dist/preview/previewGenerator.js +240 -0
  107. package/dist/preview/previewGenerator.spec.js +203 -0
  108. package/dist/preview/viewModelParser.js +86 -0
  109. package/dist/preview/viewModelParser.spec.js +171 -0
  110. package/dist/setup/DevSetupHelper.js +0 -51
  111. package/dist/setup/linuxSetup.js +0 -2
  112. package/dist/setup/macOSSetup.js +1 -4
  113. package/dist/utils/BazelClient.js +15 -0
  114. package/dist/utils/daemonClient.js +344 -0
  115. package/dist/utils/hermesClient.js +252 -0
  116. package/dist/utils/skillsAdapters.js +86 -5
  117. package/dist/utils/skillsAdapters.spec.js +60 -0
  118. package/dist/utils/skillsRegistry.js +8 -0
  119. package/dist/utils/stringUtils.spec.js +1 -1
  120. package/package.json +30 -12
  121. package/dist/setup/versions.js +0 -8
@@ -0,0 +1,238 @@
1
+ # Valdi Error Handling
2
+
3
+ Error handling, promise rejection, and lifecycle safety patterns.
4
+
5
+ ## When to use
6
+
7
+ When dealing with async operations, network requests, component lifecycle boundaries, or any code that can fail at runtime.
8
+
9
+ ## Key concepts
10
+
11
+ Valdi runs on a JavaScript runtime (Hermes/V8) with native platform integration. Unhandled errors crash the app. The primary error sources are:
12
+
13
+ 1. **Async operations** completing after component destruction
14
+ 2. **Network failures** from HTTPClient
15
+ 3. **Uncaught promise rejections**
16
+ 4. **Type mismatches** from native/JS boundary
17
+
18
+ ## CancelablePromise — the first line of defense
19
+
20
+ Most Valdi errors stem from async work completing after a component is destroyed. `CancelablePromise` + `registerDisposable` prevents this entirely:
21
+
22
+ ```tsx
23
+ import { promiseToCancelablePromise } from 'valdi_core/src/CancelablePromise';
24
+
25
+ // ✅ Safe async — cancelled on component destruction
26
+ onCreate() {
27
+ const cancelable = promiseToCancelablePromise(this.fetchData(), () => {});
28
+ this.registerDisposable(() => cancelable.cancel?.());
29
+ cancelable.then(
30
+ data => { this.setState({ data, loading: false }); },
31
+ error => { this.setState({ error: error.message, loading: false }); },
32
+ );
33
+ }
34
+ ```
35
+
36
+ ```tsx
37
+ // ❌ WRONG — Raw promise with no lifecycle safety
38
+ onCreate() {
39
+ this.fetchData().then(data => {
40
+ this.setState({ data }); // Crashes if component is destroyed
41
+ });
42
+ }
43
+ ```
44
+
45
+ See the `valdi-async` skill for comprehensive CancelablePromise patterns.
46
+
47
+ ## HTTPClient error handling
48
+
49
+ `HTTPClient` is an instance, not static. Methods return `CancelablePromise<HTTPResponse>`.
50
+
51
+ ```tsx
52
+ import { HTTPClient } from 'valdi_http/src/HTTPClient';
53
+
54
+ private httpClient = new HTTPClient('https://api.example.com');
55
+
56
+ // ✅ Handle network errors with lifecycle safety
57
+ private fetchData = () => {
58
+ const cancelable = this.httpClient.get('/data');
59
+ this.registerDisposable(() => cancelable.cancel?.());
60
+ cancelable.then(
61
+ response => {
62
+ if (response.statusCode !== 200) {
63
+ this.setState({ error: `HTTP ${response.statusCode}`, loading: false });
64
+ return;
65
+ }
66
+ const decoder = new TextDecoder();
67
+ const data = JSON.parse(decoder.decode(response.body));
68
+ this.setState({ data, loading: false });
69
+ },
70
+ error => {
71
+ this.setState({ error: (error as Error).message, loading: false });
72
+ },
73
+ );
74
+ };
75
+ ```
76
+
77
+ `HTTPResponse` shape: `{ statusCode: number, headers: StringMap<string>, body?: Uint8Array }`. Decode `body` with `TextDecoder` before parsing.
78
+
79
+ ## isDestroyed() guard
80
+
81
+ For callbacks that can't use CancelablePromise (e.g., native callbacks, timers):
82
+
83
+ ```tsx
84
+ // ✅ Guard against use-after-destroy
85
+ private onNativeCallback = (result: string) => {
86
+ if (this.isDestroyed()) return;
87
+ this.setState({ result });
88
+ };
89
+ ```
90
+
91
+ `isDestroyed()` is a method — always call with parentheses.
92
+
93
+ ## try/catch in async methods
94
+
95
+ ```tsx
96
+ import { promiseToCancelablePromise } from 'valdi_core/src/CancelablePromise';
97
+
98
+ // ✅ Catch errors from async operations
99
+ private loadProfile = () => {
100
+ const cancelable = promiseToCancelablePromise(
101
+ (async () => {
102
+ try {
103
+ const profile = await this.api.getProfile();
104
+ return { profile, error: undefined };
105
+ } catch (e) {
106
+ return { profile: undefined, error: (e as Error).message };
107
+ }
108
+ })(),
109
+ () => {},
110
+ );
111
+ this.registerDisposable(() => cancelable.cancel?.());
112
+
113
+ cancelable.then(result => {
114
+ this.setState({
115
+ profile: result.profile,
116
+ error: result.error,
117
+ loading: false,
118
+ });
119
+ });
120
+ };
121
+ ```
122
+
123
+ ## Error states in UI
124
+
125
+ ```tsx
126
+ // ✅ Show error state to the user
127
+ onRender(): void {
128
+ if (this.state.loading) {
129
+ <AnimationShimmer width="100%" height={200} />;
130
+ return;
131
+ }
132
+
133
+ if (this.state.error) {
134
+ <view alignItems="center" justifyContent="center" padding={16}>
135
+ <label value="Something went wrong" font={systemBoldFont(16)} />
136
+ <label value={this.state.error} color="#999" />
137
+ <CoreButton text="Retry" onTap={this.handleRetry} />
138
+ </view>;
139
+ return;
140
+ }
141
+
142
+ <label value={this.state.data.name} />;
143
+ }
144
+ ```
145
+
146
+ ## Defensive ViewModel access
147
+
148
+ ViewModels come from parent components and may have optional fields:
149
+
150
+ ```tsx
151
+ // ✅ Defensive access with defaults
152
+ onRender(): void {
153
+ const title = this.viewModel.title ?? 'Untitled';
154
+ const items = this.viewModel.items ?? [];
155
+
156
+ <view>
157
+ <label value={title} />
158
+ {items.forEach(item => { <label value={item.name} />; })}
159
+ </view>;
160
+ }
161
+ ```
162
+
163
+ ## Timer cleanup
164
+
165
+ ```tsx
166
+ // ✅ Use setTimeoutDisposable for automatic cleanup
167
+ onCreate() {
168
+ this.setTimeoutDisposable(this.tick, 1000);
169
+ }
170
+ ```
171
+
172
+ ```tsx
173
+ // ✅ Manual cleanup for setInterval
174
+ private timerId?: number;
175
+
176
+ onCreate() {
177
+ this.timerId = setInterval(this.tick, 1000);
178
+ }
179
+
180
+ onDestroy() {
181
+ if (this.timerId !== undefined) {
182
+ clearInterval(this.timerId);
183
+ }
184
+ }
185
+ ```
186
+
187
+ Or use `registerDisposable` with a disposable wrapper — see `valdi-async` skill.
188
+
189
+ ## Common mistakes
190
+
191
+ ```tsx
192
+ // ❌ WRONG — HTTPClient is not static
193
+ const data = await HTTPClient.send(request); // No static send() method
194
+
195
+ // ✅ Correct — instantiate then call methods
196
+ const client = new HTTPClient('https://api.example.com');
197
+ const cancelable = client.get('/data');
198
+
199
+ // ❌ WRONG — .catch() is not available on CancelablePromise
200
+ cancelable.catch(error => { ... }); // CancelablePromise only has .then()
201
+
202
+ // ✅ Correct — use second argument of .then() for error handling
203
+ cancelable.then(
204
+ response => { /* success */ },
205
+ error => { /* failure */ },
206
+ );
207
+
208
+ // ❌ WRONG — React error boundaries don't exist
209
+ <ErrorBoundary fallback={<Error />}> // Not a Valdi concept
210
+ <MyComponent />
211
+ </ErrorBoundary>
212
+
213
+ // ❌ WRONG — window.onerror / global error handlers
214
+ window.addEventListener('error', handler); // No window object
215
+
216
+ // ❌ WRONG — isDestroyed without parentheses
217
+ if (this.isDestroyed) return; // It's a method, not a property
218
+
219
+ // ✅ Correct
220
+ if (this.isDestroyed()) return;
221
+
222
+ // ❌ WRONG — Passing CancelablePromise directly to registerDisposable
223
+ this.registerDisposable(cancelable); // Wrong type
224
+
225
+ // ✅ Correct — wrap cancel in a callback
226
+ this.registerDisposable(() => cancelable.cancel?.());
227
+ ```
228
+
229
+ ## Summary
230
+
231
+ | Pattern | When to use |
232
+ |---------|------------|
233
+ | `promiseToCancelablePromise` + `registerDisposable` | Any async work in a component |
234
+ | `isDestroyed()` guard | Native callbacks, external event handlers |
235
+ | `try/catch` | Operations that can throw |
236
+ | Error state in UI | User-facing failure recovery |
237
+ | `onDestroy` cleanup | Timers, subscriptions, manual resources |
238
+ | `setTimeoutDisposable` | One-shot timers (auto-cleaned) |
@@ -0,0 +1,198 @@
1
+ # Valdi Gestures
2
+
3
+ Touch and gesture handling: tap, long press, drag, pinch, and rotate.
4
+
5
+ ## When to use
6
+
7
+ When handling user touch interactions beyond basic `onTap` — drag-to-reorder, pinch-to-zoom, long press menus, custom gesture recognition.
8
+
9
+ ## Key concepts
10
+
11
+ Valdi gesture handling is **attribute-based on `<view>` elements**. Each gesture type has three attributes:
12
+ - `on<Gesture>` — the callback
13
+ - `<gesture>Enabled` — boolean to enable/disable (default: true when callback is set)
14
+ - `on<Gesture>Predicate` — function returning boolean, controls whether the gesture should fire
15
+
16
+ The topmost visible element with a matching gesture wins. Conflicting gestures on parent elements are suppressed.
17
+
18
+ ## TouchEvent interface
19
+
20
+ All gesture callbacks receive a `TouchEvent` (or extension of it):
21
+
22
+ ```tsx
23
+ interface TouchEvent {
24
+ x: number; // X relative to the element
25
+ y: number; // Y relative to the element
26
+ absoluteX: number; // X relative to root Valdi view
27
+ absoluteY: number; // Y relative to root Valdi view
28
+ pointerCount: number;
29
+ pointerLocations: Pointer[];
30
+ }
31
+ ```
32
+
33
+ ## Basic gestures
34
+
35
+ ### onTap
36
+
37
+ ```tsx
38
+ // ✅ Simple tap handler
39
+ <view onTap={this.handleTap}>
40
+ <label value="Tap me" />
41
+ </view>
42
+
43
+ private handleTap = (event: TouchEvent) => {
44
+ console.log(`Tapped at ${event.x}, ${event.y}`);
45
+ };
46
+ ```
47
+
48
+ ### onDoubleTap
49
+
50
+ ```tsx
51
+ // ✅ Double tap to zoom
52
+ <view onDoubleTap={this.handleDoubleTap}>
53
+ <image src={this.viewModel.photo} />
54
+ </view>
55
+ ```
56
+
57
+ ### onLongPress
58
+
59
+ ```tsx
60
+ // ✅ Long press with custom duration
61
+ <view
62
+ onLongPress={this.handleLongPress}
63
+ longPressDuration={500} // milliseconds before trigger
64
+ >
65
+ <label value="Hold me" />
66
+ </view>
67
+ ```
68
+
69
+ ## Continuous gestures
70
+
71
+ ### onDrag
72
+
73
+ ```tsx
74
+ // ✅ Drag to move — fires continuously during the drag
75
+ <view onDrag={this.handleDrag}>
76
+ <label value="Drag me" />
77
+ </view>
78
+
79
+ private handleDrag = (event: DragEvent) => {
80
+ // event extends TouchEvent with drag-specific data
81
+ this.cardRef.setAttribute('translateX', event.x);
82
+ this.cardRef.setAttribute('translateY', event.y);
83
+ };
84
+ ```
85
+
86
+ ### onPinch
87
+
88
+ ```tsx
89
+ // ✅ Pinch to zoom — requires 2+ pointers
90
+ <view onPinch={this.handlePinch}>
91
+ <image src={this.viewModel.photo} ref={this.imageRef} />
92
+ </view>
93
+
94
+ private handlePinch = (event: PinchEvent) => {
95
+ this.imageRef.setAttribute('scale', event.scale);
96
+ };
97
+ ```
98
+
99
+ ### onRotate
100
+
101
+ ```tsx
102
+ // ✅ Rotate with two fingers — requires 2+ pointers
103
+ <view onRotate={this.handleRotate}>
104
+ <image src={this.viewModel.sticker} ref={this.stickerRef} />
105
+ </view>
106
+ ```
107
+
108
+ ## Simultaneous gestures
109
+
110
+ `onDrag`, `onPinch`, and `onRotate` can run simultaneously. This enables multitouch interactions like pinch-zoom-rotate on a photo:
111
+
112
+ ```tsx
113
+ // ✅ Combined pinch + drag + rotate on same element
114
+ <view
115
+ onDrag={this.handleDrag}
116
+ onPinch={this.handlePinch}
117
+ onRotate={this.handleRotate}
118
+ >
119
+ <image src={this.viewModel.photo} ref={this.photoRef} />
120
+ </view>
121
+ ```
122
+
123
+ ## Touch area extension
124
+
125
+ Expand the tappable area beyond the visible bounds:
126
+
127
+ ```tsx
128
+ // ✅ Small button with larger touch target
129
+ <view
130
+ onTap={this.handleTap}
131
+ touchAreaExtension={10} // extends hit area by 10pt in each direction
132
+ width={24} height={24}
133
+ >
134
+ <image src={SIGIcon.checkmarkFill} />
135
+ </view>
136
+ ```
137
+
138
+ ## Touch delay in scroll views
139
+
140
+ Inside a `<scroll>`, touches are delayed to avoid conflicts with scrolling:
141
+
142
+ ```tsx
143
+ // ✅ Delay touch recognition inside scrollable content
144
+ <view
145
+ onTouch={this.handleTouch}
146
+ onTouchDelayDuration={150} // ms before onTouch fires during scroll
147
+ />
148
+ ```
149
+
150
+ ## Gesture predicates
151
+
152
+ Control whether a gesture should activate:
153
+
154
+ ```tsx
155
+ // ✅ Only allow drag when in edit mode
156
+ <view
157
+ onDrag={this.handleDrag}
158
+ onDragPredicate={() => this.state.editMode}
159
+ />
160
+ ```
161
+
162
+ ## onTouch (raw)
163
+
164
+ Low-level touch events that fire on all elements in the hierarchy:
165
+
166
+ ```tsx
167
+ // ✅ Raw touch tracking — fires for all touch phases
168
+ <view onTouch={this.handleTouch}>
169
+ <label value="Touch me" />
170
+ </view>
171
+
172
+ private handleTouch = (event: TouchEvent) => {
173
+ // Fires on begin, move, end, cancel
174
+ };
175
+ ```
176
+
177
+ Unlike other gestures, `onTouch` propagates to parents/siblings — it doesn't suppress other handlers.
178
+
179
+ ## Common mistakes
180
+
181
+ ```tsx
182
+ // ❌ WRONG — React-style event handlers
183
+ <div onClick={handler} /> // ❌ No <div>, no onClick
184
+ <button onMouseDown={handler} /> // ❌ No mouse events
185
+
186
+ // ❌ WRONG — addEventListener
187
+ element.addEventListener('touchstart', handler); // ❌
188
+
189
+ // ❌ WRONG — Gesture on <layout> (use <view>)
190
+ <layout onTap={handler} /> // ❌ Gestures go on <view> elements
191
+
192
+ // ✅ Correct — gestures on <view>
193
+ <view onTap={handler}>
194
+ <layout>
195
+ <label value="Content" />
196
+ </layout>
197
+ </view>
198
+ ```
@@ -0,0 +1,217 @@
1
+ # valdi-inspect
2
+
3
+ Use this skill when you need to inspect a **live running Valdi app** — to see what components are on screen, traverse the rendered virtual node tree, capture element screenshots, or check JS heap usage.
4
+
5
+ ## When to use
6
+
7
+ - User asks "what's on screen?", "what component is rendering here?", "what contexts are active?"
8
+ - You need to diagnose a layout or rendering issue in a running app
9
+ - You want to verify a component tree change after a hot-reload
10
+ - User asks about memory usage or wants a JS heap dump
11
+
12
+ ## Prerequisites
13
+
14
+ The Valdi app must be **running on a connected device or emulator**. No hot-reloader required — the CLI connects directly to the app's DebuggerService.
15
+
16
+ **Port reference** — determined by how the app is built, not the OS:
17
+
18
+ | Target | Port | When |
19
+ |--------|------|------|
20
+ | iOS in-app (e.g. Snapchat) | **13592** (default) | `isStandalone = false` |
21
+ | Android in-app | **13592** (default) | `isStandalone = false` |
22
+ | macOS Valdi app | **13591** | `isStandalone = true` |
23
+ | Standalone runner / CLI runner | **13591** | `isStandalone = true` |
24
+
25
+ For **Android**, `adb forward` runs automatically. For **iOS simulator**, connect directly to `localhost`.
26
+
27
+ All commands output **JSON by default** (for AI parsing). Add `--pretty` for human-readable output.
28
+
29
+ ---
30
+
31
+ ## Commands
32
+
33
+ ### `valdi inspect status`
34
+
35
+ Check whether the Valdi daemon is reachable and how many devices are connected.
36
+
37
+ ```
38
+ valdi inspect status
39
+ valdi inspect status --pretty
40
+ ```
41
+
42
+ Output: `{ connected: bool, port: number, connectedDevices: number, portName: string }`
43
+
44
+ ---
45
+
46
+ ### `valdi inspect devices`
47
+
48
+ List all devices connected to the Valdi daemon.
49
+
50
+ ```
51
+ valdi inspect devices
52
+ valdi inspect devices --pretty
53
+ ```
54
+
55
+ Output: `[{ client_id, platform, application_id }, ...]`
56
+
57
+ Use `client_id` values with `--client` in other commands. If only one device is connected, other commands auto-select it.
58
+
59
+ ---
60
+
61
+ ### `valdi inspect select`
62
+
63
+ Interactively choose a device and save it to `~/.valdi-inspect.json`. Subsequent commands use this device without prompting.
64
+
65
+ ```
66
+ valdi inspect select
67
+ ```
68
+
69
+ ---
70
+
71
+ ### `valdi inspect contexts`
72
+
73
+ List all active root components (contexts) on the device. A **context** is one mounted Valdi component tree — typically one per screen or overlay.
74
+
75
+ ```
76
+ valdi inspect contexts
77
+ valdi inspect contexts --pretty
78
+ valdi inspect contexts --client <client_id>
79
+ ```
80
+
81
+ Output: `[{ id: string, rootComponentName: string }, ...]`
82
+
83
+ The `id` is the **contextId** used by `tree` and `snapshot`. If there is only one context, commands that take a contextId will auto-select it.
84
+
85
+ ---
86
+
87
+ ### `valdi inspect tree [contextId]`
88
+
89
+ Get the full rendered virtual node tree for a context. If `contextId` is omitted, auto-selects the single context or prompts when there are multiple.
90
+
91
+ ```
92
+ valdi inspect tree
93
+ valdi inspect tree <contextId>
94
+ valdi inspect tree <contextId> --pretty
95
+ valdi inspect tree <contextId> --max-depth <n>
96
+ ```
97
+
98
+ Output: a nested tree where each node has:
99
+ - `tag`: element type (e.g. `"view"`, `"label"`, `"image"`, or a component name)
100
+ - `key`: the Valdi TSX key assigned in source
101
+ - `element.id`: numeric element ID (use this for `snapshot`)
102
+ - `element.frame`: `{ x, y, width, height }` in screen coordinates
103
+ - `element.attributes`: rendered prop values (style, value, etc.)
104
+ - `children`: array of child nodes (same shape)
105
+ - `_childrenTrimmed`: count of trimmed children when `--max-depth` is used
106
+
107
+ **Tip**: Use `--max-depth 3` or `--max-depth 4` first to get a summary, then drill in.
108
+
109
+ ---
110
+
111
+ ### `valdi inspect snapshot <elementId> [contextId]`
112
+
113
+ Capture a screenshot of a specific element and save it as a PNG. If `contextId` is omitted, auto-selects or prompts.
114
+
115
+ ```
116
+ valdi inspect snapshot <elementId>
117
+ valdi inspect snapshot <elementId> <contextId>
118
+ valdi inspect snapshot <elementId> <contextId> --output /tmp/my-snap.png
119
+ ```
120
+
121
+ Output: `{ path: "/var/folders/.../valdi-snapshot-<elementId>.png" }`
122
+
123
+ The PNG is written to disk. Read it with the `Read` tool to view it visually.
124
+
125
+ **Getting elementId**: Use `element.id` from the `tree` output (a number, e.g. `1`, `5`, `42`).
126
+
127
+ #### Using `--key` instead of numeric IDs (recommended)
128
+
129
+ Instead of looking up numeric element IDs from the tree, use the `--key` flag to resolve by component tag name or element `key` prop:
130
+
131
+ ```
132
+ valdi inspect snapshot --key PreviewRoot
133
+ valdi inspect snapshot --key weather-card --port 13591
134
+ ```
135
+
136
+ The `--key` flag searches the component tree for a matching tag name or `key` prop and resolves it to the element ID automatically.
137
+
138
+ **This is stable across hot-reloads** — element IDs change on every reload, but component names and `key` props stay the same. Use `--key` instead of numeric IDs to avoid re-querying the tree after each hot-reload cycle.
139
+
140
+ Custom keys can be set on any element in TSX:
141
+ ```tsx
142
+ <view key="weather-card" style={styles.card}>
143
+ ```
144
+
145
+ ---
146
+
147
+ ### `valdi inspect heap`
148
+
149
+ Dump JS heap statistics for the connected device.
150
+
151
+ ```
152
+ valdi inspect heap
153
+ valdi inspect heap --pretty
154
+ valdi inspect heap --gc
155
+ ```
156
+
157
+ Options:
158
+ - `--gc`: run garbage collection before dumping (more accurate free memory reading)
159
+
160
+ Output: `{ memoryUsageBytes: number, heapDumpJSON: string }`
161
+
162
+ `heapDumpJSON` is a serialized heap snapshot in V8 format. Note: heap dumps can crash small/toy apps — this works best on full production apps.
163
+
164
+ ---
165
+
166
+ ## Common workflows
167
+
168
+ ### "What is rendering on screen right now?"
169
+
170
+ ```
171
+ valdi inspect tree --pretty
172
+ ```
173
+
174
+ (contextId is auto-selected if there's only one)
175
+
176
+ ### "Show me what a specific component looks like"
177
+
178
+ 1. Run `valdi inspect tree --pretty` to find the node — note its `element.id`
179
+ 2. Run `valdi inspect snapshot <element.id>` to capture it
180
+ 3. Read the PNG with the `Read` tool
181
+
182
+ ### "Diagnose a layout issue at position X,Y"
183
+
184
+ Run `valdi inspect tree --pretty` and look for `element.frame` values overlapping with the target position.
185
+
186
+ ### "Check memory usage"
187
+
188
+ ```
189
+ valdi inspect heap --pretty
190
+ ```
191
+
192
+ ### "Verify a hot-reload applied correctly"
193
+
194
+ Run `valdi inspect tree` before and after the edit, compare the JSON output.
195
+
196
+ ---
197
+
198
+ ## Options reference
199
+
200
+ | Option | Commands | Description |
201
+ |--------|----------|-------------|
202
+ | `--port <n>` | all | Daemon TCP port (default: 13592 mobile, 13591 standalone) |
203
+ | `--client <id>` | contexts, tree, snapshot, heap | Target a specific connected device |
204
+ | `--pretty` | devices, status, contexts, tree, heap | Human-readable output |
205
+ | `--max-depth <n>` | tree | Trim tree to N levels deep |
206
+ | `--output <path>` | snapshot | Custom PNG output path |
207
+ | `--gc` | heap | GC before heap dump |
208
+
209
+ ---
210
+
211
+ ## Troubleshooting
212
+
213
+ **"Valdi daemon not running on port 13592"** — Make sure the app is running. macOS Valdi apps and standalone runners use port 13591: add `--port 13591`.
214
+
215
+ **"No devices connected"** — Make sure the Valdi app is running. For Android, ensure a device or emulator is connected via `adb`.
216
+
217
+ **"Timeout waiting for device response"** — The app may be frozen or the JS runtime may be busy. Try again after a moment.