@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,303 @@
1
+ # valdi-preview
2
+
3
+ Use this skill to **understand and visually preview a Valdi module or component** — read its API, render it in the preview harness app, inspect the view hierarchy, and capture a screenshot.
4
+
5
+ ## When to use
6
+
7
+ - You need to understand what a Valdi component looks like before using it
8
+ - You want to see a component's rendered output to verify your code
9
+ - User asks "what does X component look like?" or "show me how X renders"
10
+ - You're building a UI and need to evaluate which widget to use
11
+ - You want to explore a component's API (viewModel, slots, styling)
12
+
13
+ ## Overview
14
+
15
+ The workflow has two phases:
16
+
17
+ 1. **Static analysis** — read source files to understand the component's API
18
+ 2. **Live preview** (optional) — render it in the preview harness, inspect the tree, screenshot it
19
+
20
+ You can stop after phase 1 if you only need API understanding. Phase 2 requires a running app.
21
+
22
+ ---
23
+
24
+ ## Phase 1: Understand the component
25
+
26
+ ### Step 1: Find the module source
27
+
28
+ Given a component name or module path, locate its source files:
29
+
30
+ ```bash
31
+ # Find by component class name
32
+ grep -r "export class CoreButton" --include="*.tsx" --include="*.ts"
33
+
34
+ # Find by module name in BUILD.bazel
35
+ grep -r "name = \"valdi_widgets_core\"" --include="BUILD.bazel"
36
+ ```
37
+
38
+ ### Step 2: Read the API surface
39
+
40
+ Read the component's main `.tsx` file and look for:
41
+
42
+ 1. **ViewModel interface** — the props the component accepts. Look for `@ViewModel` JSDoc tag:
43
+ ```typescript
44
+ /**
45
+ * @ViewModel
46
+ */
47
+ export interface CoreButtonViewModel {
48
+ title: string;
49
+ onPress: () => void;
50
+ disabled?: boolean;
51
+ }
52
+ ```
53
+
54
+ 2. **Component class** — the rendering logic. Look for `@Component` JSDoc tag and the `onRender()` method.
55
+
56
+ 3. **Slots** — child content areas. Look for `AnyRenderFunction` or `$slot` usage in the viewModel or render.
57
+
58
+ 4. **JSDoc** — descriptions, `@example` tags, parameter docs.
59
+
60
+ 5. **State interface** — if it's a `StatefulComponent`, read the state shape.
61
+
62
+ ### Step 3: Find usage examples
63
+
64
+ Search the codebase for real usage of the component:
65
+
66
+ ```bash
67
+ # Find files that import this component
68
+ grep -r "import.*CoreButton" --include="*.tsx" --include="*.ts" -l
69
+
70
+ # Find JSX usage
71
+ grep -r "<CoreButton" --include="*.tsx"
72
+ ```
73
+
74
+ Pick 2-3 representative usages to understand common prop combinations.
75
+
76
+ ### Step 4: Summarize
77
+
78
+ Report to the user:
79
+ - Component name and location
80
+ - ViewModel props (required and optional)
81
+ - What it renders (layout structure from `onRender()`)
82
+ - How it's typically used (from real examples)
83
+
84
+ ---
85
+
86
+ ## Phase 2: Live preview
87
+
88
+ ### Option A: `valdi preview` CLI (recommended)
89
+
90
+ The fastest path — automatically generates the preview harness and builds:
91
+
92
+ ```bash
93
+ # By import path
94
+ valdi preview widgets/src/components/button/Checkbox
95
+
96
+ # By file path
97
+ valdi preview ./valdi_modules/widgets/src/components/button/Checkbox.tsx
98
+ ```
99
+
100
+ This command:
101
+ 1. Resolves the component file
102
+ 2. Parses the ViewModel to extract props
103
+ 3. Generates `apps/preview/PreviewRoot.tsx` with sample props and interactive state
104
+ 4. Generates `apps/preview/BUILD.bazel` with correct deps
105
+ 5. Generates `apps/preview/tsconfig.json` with correct path mappings
106
+ 6. Builds and launches `//apps/preview:preview_app_macos`
107
+
108
+ First build takes 2-5 minutes; subsequent builds ~5-15 seconds.
109
+
110
+ ### Option B: Manual harness setup
111
+
112
+ For full control or when `valdi preview` doesn't support your use case.
113
+
114
+ Requires a running Valdi app. If no app is running, tell the user to start one first.
115
+
116
+ ### Step 1: Edit the preview harness
117
+
118
+ The preview harness app lives at `apps/preview/` in the Valdi repo. It has three files:
119
+
120
+ | File | Purpose |
121
+ |------|---------|
122
+ | `PreviewRoot.tsx` | Root component — **edit this** to render your target |
123
+ | `BUILD.bazel` | Module deps — **add deps here** if the target is in another module |
124
+ | `tsconfig.json` | Path mappings — **add path entries** for new module deps |
125
+
126
+ **Edit `PreviewRoot.tsx`** to import and render the target component:
127
+
128
+ ```typescript
129
+ import { Component } from 'valdi_core/src/Component';
130
+ import { CoreButton } from 'valdi_widgets_core/src/components/button/CoreButton';
131
+
132
+ /**
133
+ * @ViewModel
134
+ * @ExportModel
135
+ */
136
+ export interface ViewModel {}
137
+
138
+ /**
139
+ * @Context
140
+ * @ExportModel
141
+ */
142
+ export interface ComponentContext {}
143
+
144
+ /**
145
+ * @Component
146
+ * @ExportModel
147
+ */
148
+ export class PreviewRoot extends Component<ViewModel, ComponentContext> {
149
+ onRender(): void {
150
+ <view backgroundColor="#ffffff" width="100%" height="100%" padding={24}
151
+ alignItems="center" justifyContent="center">
152
+ <CoreButton title="Example Button" onPress={() => {}} />
153
+ </view>;
154
+ }
155
+ }
156
+ ```
157
+
158
+ **If the component is in another module**, add it to `BUILD.bazel` deps:
159
+
160
+ ```python
161
+ deps = [
162
+ "//src/valdi_modules/src/valdi/valdi_core",
163
+ "//src/valdi_modules/src/valdi/valdi_tsx",
164
+ "//path/to/target_module", # Add this
165
+ ],
166
+ ```
167
+
168
+ And add the path mapping to `tsconfig.json`:
169
+
170
+ ```json
171
+ {
172
+ "compilerOptions": {
173
+ "paths": {
174
+ "target_module/*": ["../../path/to/target_module/*"]
175
+ }
176
+ }
177
+ }
178
+ ```
179
+
180
+ ### Step 2: Build and hot-reload
181
+
182
+ **Recommended workflow** — build once, then use hot-reload for instant iteration:
183
+
184
+ ```bash
185
+ # 1. Build the macOS app once
186
+ bazel build //apps/preview:preview_app_macos
187
+
188
+ # 2. Launch it directly (stays alive as background process)
189
+ open bazel-bin/apps/preview/preview_app_macos_archive-root/Valdi\ Preview.app
190
+
191
+ # 3. Start the hot-reloader
192
+ valdi hotreload --target //apps/preview:preview_app_hotreload
193
+ ```
194
+
195
+ Now any edit to `PreviewRoot.tsx` is automatically recompiled and pushed to the running app in ~1s.
196
+
197
+ **Alternative** — full rebuild (slower but simpler):
198
+
199
+ ```bash
200
+ # macOS (fastest for preview)
201
+ bazel run //apps/preview:preview_app_macos
202
+
203
+ # iOS simulator
204
+ bazel run //apps/preview:preview_app_ios_sim
205
+ ```
206
+
207
+ ### Step 3: Inspect the rendered output
208
+
209
+ Once the component is on screen, use **port 13591** for standalone macOS apps:
210
+
211
+ ```bash
212
+ # Capture a screenshot by component name (stable across hot-reloads)
213
+ valdi inspect snapshot --key PreviewRoot --port 13591
214
+
215
+ # Or by a custom key prop you set on an element
216
+ valdi inspect snapshot --key my-card --port 13591
217
+
218
+ # Or by numeric element ID (from tree output — changes on each hot-reload)
219
+ valdi inspect snapshot <elementId> 2 --port 13591
220
+ ```
221
+
222
+ **Prefer `--key`** — it resolves the component tag or element key to its numeric ID automatically, so you don't need to re-query the tree after every hot-reload.
223
+
224
+ If you're previewing inside a mobile app (Snapchat, etc.), use the default port 13592 instead.
225
+
226
+ Then read the PNG file to see what it looks like.
227
+
228
+ ### Step 4: Iterate
229
+
230
+ If the rendering doesn't look right:
231
+
232
+ 1. Adjust props, styles, or container layout in `PreviewRoot.tsx`
233
+ 2. Hot-reload picks up the change automatically (~1s)
234
+ 3. Re-query tree for new element IDs, then `valdi inspect snapshot`
235
+ 4. Repeat until the component renders as expected
236
+
237
+ **Iteration priority** — for fastest convergence, fix in this order:
238
+ 1. Font sizes (almost always too small on first pass)
239
+ 2. Vertical spacing between sections
240
+ 3. Text colors
241
+ 4. Element sizing (padding, border radius)
242
+ 5. Decorative elements (fills, shadows)
243
+
244
+ ---
245
+
246
+ ## Previewing multiple components
247
+
248
+ To compare several components side by side, render them all in `PreviewRoot.tsx`:
249
+
250
+ ```typescript
251
+ onRender(): void {
252
+ <view backgroundColor="#ffffff" width="100%" height="100%" padding={24}>
253
+ <scroll height="100%" width="100%">
254
+ <label value="CoreButton" font="system-bold 14" color="#666" marginBottom={8} />
255
+ <CoreButton title="Primary" onPress={() => {}} />
256
+
257
+ <view height={24} />
258
+
259
+ <label value="PillButton" font="system-bold 14" color="#666" marginBottom={8} />
260
+ <PillButton title="Secondary" onPress={() => {}} />
261
+ </scroll>
262
+ </view>;
263
+ }
264
+ ```
265
+
266
+ ---
267
+
268
+ ## Previewing with sample data
269
+
270
+ When a component needs complex viewModel data, create realistic sample data:
271
+
272
+ ```typescript
273
+ // For a component that needs a list of items
274
+ const sampleItems = [
275
+ { id: '1', title: 'First item', subtitle: 'Description' },
276
+ { id: '2', title: 'Second item', subtitle: 'Another one' },
277
+ { id: '3', title: 'Third item', subtitle: 'And another' },
278
+ ];
279
+
280
+ onRender(): void {
281
+ <MyListComponent items={sampleItems} onItemTap={() => {}} />;
282
+ }
283
+ ```
284
+
285
+ ---
286
+
287
+ ## Cleanup
288
+
289
+ After previewing, restore `PreviewRoot.tsx` to its placeholder state so the harness is ready for the next preview. Revert any deps added to `BUILD.bazel` and `tsconfig.json` unless the user wants to keep them.
290
+
291
+ ---
292
+
293
+ ## Troubleshooting
294
+
295
+ **"Module not found"** — You forgot to add the dep to `BUILD.bazel` or the path mapping to `tsconfig.json`.
296
+
297
+ **"Cannot resolve import"** — The tsconfig path is wrong. Check the relative path from `apps/preview/` to the target module.
298
+
299
+ **Hot-reload not picking up changes** — Stop and restart `valdi hotreload`. If that doesn't work, do a full `bazel run`.
300
+
301
+ **"Valdi daemon not running"** — The app isn't running. Build and launch it first with `bazel run`.
302
+
303
+ **Component renders blank** — Check that you're passing all required viewModel props. Read the ViewModel interface again.
@@ -0,0 +1,126 @@
1
+ # valdi-profile
2
+
3
+ Use this skill when you need to capture a **CPU profile from a running Valdi app** — to diagnose slow renders, identify hot functions, or understand JS thread activity.
4
+
5
+ ## When to use
6
+
7
+ - User asks "why is this component slow?", "what's taking so long?", "profile this interaction"
8
+ - You want to measure the JS cost of a specific UI action
9
+ - You need a flamegraph or call-tree of the Hermes JS runtime
10
+
11
+ ## Prerequisites
12
+
13
+ ### 1. Build the app with Hermes
14
+
15
+ `valdi profile` requires the app to be built with the **Hermes JS engine**. The default engine is QuickJS — you must opt in:
16
+
17
+ ```
18
+ valdi install android --bazel_args="--@valdi//bzl/valdi:js_engine=hermes --@valdi//bzl/valdi:js_bytecode_format=hermes"
19
+ valdi install ios --bazel_args="--@valdi//bzl/valdi:js_engine=hermes --@valdi//bzl/valdi:js_bytecode_format=hermes"
20
+ ```
21
+
22
+ If you try to profile a QuickJS build you will get:
23
+ ```
24
+ Hermes debug socket not found on port 13595.
25
+ ```
26
+
27
+ ### 2. Run the app with the hot-reloader
28
+
29
+ The app must be **running on a connected device or emulator**, and the **hot-reloader must be running from the project directory**:
30
+
31
+ ```
32
+ valdi hotreload android
33
+ valdi hotreload ios
34
+ ```
35
+
36
+ The hot-reloader creates the `port 13595` tunnel to the Hermes debug server (which starts on a random port inside the app). Without it, port 13595 is not reachable.
37
+
38
+ > **Note**: The hot-reloader does not need to compile successfully. Even if it prints TypeScript errors, it still sets up the port-13595 tunnel and the profile command will work.
39
+
40
+ All commands output **JSON by default** (for AI parsing). Human-readable output goes to stderr.
41
+
42
+ ---
43
+
44
+ ## Commands
45
+
46
+ ### `valdi profile capture`
47
+
48
+ Capture a CPU profile. Stops on Ctrl+C (interactive) or after `--duration` seconds.
49
+
50
+ ```
51
+ valdi profile capture
52
+ valdi profile capture --duration 10
53
+ valdi profile capture --duration 5 --output /tmp/my-profile.cpuprofile
54
+ ```
55
+
56
+ Output: `{ "path": "/tmp/valdi-profile-<timestamp>.cpuprofile" }`
57
+
58
+ The `.cpuprofile` file is standard Chrome DevTools CPU profile format.
59
+
60
+ **Options:**
61
+
62
+ | Option | Description |
63
+ |--------|-------------|
64
+ | `--duration <s>` | Profile for N seconds then stop (omit to stop with Ctrl+C) |
65
+ | `--output <path>` | Custom output path (default: `/tmp/valdi-profile-<timestamp>.cpuprofile`) |
66
+ | `--port <n>` | Hermes debug port (default: 13595) |
67
+ | `--context <id>` | JS context ID (auto-selected if only one; prompts if multiple) |
68
+
69
+ ---
70
+
71
+ ## Common workflows
72
+
73
+ ### "Profile a slow render"
74
+
75
+ 1. Start the app and run `valdi hotreload android` (or `ios`)
76
+ 2. Navigate to the screen in the app
77
+ 3. Run: `valdi profile capture --duration 5`
78
+ 4. Trigger the slow interaction during the 5-second window
79
+ 5. Open the output file in Chrome DevTools or Speedscope
80
+
81
+ ### "Find what's running on the JS thread"
82
+
83
+ ```
84
+ valdi profile capture --duration 3
85
+ ```
86
+
87
+ Open the `.cpuprofile` in Chrome DevTools → Performance → Load file.
88
+
89
+ ### "Interactive profiling session"
90
+
91
+ ```
92
+ valdi profile capture
93
+ # ... trigger interactions ...
94
+ # press Ctrl+C to stop
95
+ ```
96
+
97
+ ---
98
+
99
+ ## Opening the output
100
+
101
+ The `.cpuprofile` file is compatible with several viewers:
102
+
103
+ **Chrome DevTools** (best flamegraph):
104
+ 1. Open Chrome → DevTools → Performance tab
105
+ 2. Click the upload icon → select the `.cpuprofile` file
106
+
107
+ **Speedscope** (fast, shareable):
108
+ - Open [speedscope.app](https://speedscope.app) → drag and drop the file
109
+
110
+ **VS Code** (integrated):
111
+ - Install "JS Profile Visualizer" extension
112
+ - Open the `.cpuprofile` file directly
113
+
114
+ ---
115
+
116
+ ## Troubleshooting
117
+
118
+ **"Hermes debug socket not found on port 13595"** — Either the app was built with QuickJS (the default), or the hot-reloader is not running. Check both prerequisites above.
119
+
120
+ **"No debuggable JS contexts found"** — The app is running but Hermes hasn't finished initialising. Wait a moment and retry.
121
+
122
+ **"Timeout waiting for response to Profiler.stop"** — The profile data is large (long capture on a busy app). The CLI waits up to 60 seconds; if this still times out, use a shorter `--duration`.
123
+
124
+ **Profile appears empty or shows only `[root]` in Speedscope/Chrome DevTools** — The app was idle during the capture (waiting for input, no JS activity). Trigger the interaction you want to profile *during* the capture window. The snake game, for example, only shows JS activity when the snake is actively moving.
125
+
126
+ **Physical iOS device** — Not supported in V1. Hermes debugging on a physical iOS device requires idb tunnelling. Use an iOS simulator instead.
@@ -38,13 +38,14 @@ valdi_module(
38
38
 
39
39
  ```json
40
40
  {
41
- "extends": "../../../../src/valdi_modules/src/valdi/_configs/base.tsconfig.json"
41
+ "extends": "../_configs/base.tsconfig.json"
42
42
  }
43
43
  ```
44
44
 
45
- Adjust the `../../../../` prefix to match how many directories deep your module is
46
- from the repo root. The base config sets up `paths` aliases so `'valdi_core/src/...'`
47
- imports resolve correctly.
45
+ The `extends` path must resolve to a `_configs/base.tsconfig.json` file. The relative
46
+ depth depends on where your module lives — check neighboring modules for the correct
47
+ prefix. The base config sets up `paths` aliases so `'valdi_core/src/...'` imports
48
+ resolve correctly.
48
49
 
49
50
  ## Dependency Table
50
51
 
@@ -54,7 +55,6 @@ imports resolve correctly.
54
55
  | JSX elements (`<view>`, `<label>`, etc.), `NativeTemplateElements` | `//src/valdi_modules/src/valdi/valdi_tsx` |
55
56
  | `HTTPClient`, `HTTPResponse` | `//src/valdi_modules/src/valdi/valdi_http` |
56
57
  | `PersistentStore` | `//src/valdi_modules/src/valdi/persistence` |
57
- | Pre-built UI components (buttons, cards, etc.) | `//src/valdi_modules/src/valdi/valdi_widgets_core` |
58
58
 
59
59
  ## ios_module_name Convention
60
60
 
@@ -105,6 +105,21 @@ export class MyComponent extends StatefulComponent<MyComponentViewModel, MyState
105
105
  }
106
106
  ```
107
107
 
108
+ ## Registering in an App Target
109
+
110
+ Your module must be added as a dependency of an application target to be compiled
111
+ and linked. The exact location depends on your project — look for the list of
112
+ Valdi module deps in the app's `BUILD.bazel` (often a `VALDI_MODULES` list or
113
+ similar) and add your module:
114
+
115
+ ```python
116
+ "//path/to/my_module:my_module",
117
+ ```
118
+
119
+ Without this, the module will not be compiled or bundled — the app will fail at
120
+ runtime with "No item named '...' in module '...'" even though the build itself
121
+ may succeed.
122
+
108
123
  ## Building
109
124
 
110
125
  ```bash
@@ -127,3 +142,38 @@ valdi hotreload --network # Discover device over Wi-Fi instead of USB
127
142
 
128
143
  If hot reload stops reflecting changes, stop with `Ctrl+C` and restart — the CLI
129
144
  will clean stale build artifacts automatically.
145
+
146
+ ## Agent Iteration Workflow
147
+
148
+ When an AI agent is editing Valdi TypeScript, use the hot reloader for compile
149
+ feedback and `agent-check` for lint + test validation.
150
+
151
+ ### During iteration
152
+
153
+ 1. Hot reloader is running (`valdi hotreload`). It recompiles on every file save.
154
+ 2. Watch the hot reloader output for compile results:
155
+ - `"Recompilation pass finished"` — change compiled successfully
156
+ - `[ERROR]` lines — compile error, fix before continuing
157
+ 3. Run a quick validation (lint + tests, skips the Bazel build):
158
+
159
+ ```bash
160
+ valdi agent-check --module my_module --quick
161
+ valdi agent-check --module my_module --quick --json # machine-readable
162
+ ```
163
+
164
+ ### Before committing
165
+
166
+ Run the full pipeline to catch build config issues, lint drift, and test regressions:
167
+
168
+ ```bash
169
+ valdi agent-check --module my_module
170
+ ```
171
+
172
+ ### agent-check flags
173
+
174
+ | Flag | Effect |
175
+ |---|---|
176
+ | `--module <name>` | Valdi module name to validate |
177
+ | `--target <label>` | Bazel target path (alternative to --module) |
178
+ | `--quick` | Skip build step (hot reloader already compiled) |
179
+ | `--json` | Structured JSON output for agent consumption |
@@ -42,20 +42,24 @@ my_module/
42
42
 
43
43
  ## BUILD.bazel for Tests
44
44
 
45
- Add a `ts_project` or `valdi_module` test target. The test target lists test spec files in `srcs` and shares `deps` with the main module:
45
+ Tests are included in the same `valdi_module` target as source files. The `valdi_module` rule auto-generates a test target from `test/` files:
46
46
 
47
47
  ```python
48
48
  load("//bzl/valdi:valdi_module.bzl", "valdi_module")
49
49
 
50
50
  valdi_module(
51
- name = "my_module_tests",
52
- srcs = glob(["test/**/*.spec.tsx", "test/**/*.spec.ts"]),
53
- testonly = True,
51
+ name = "my_module",
52
+ srcs = glob([
53
+ "src/**/*.ts",
54
+ "src/**/*.tsx",
55
+ "test/**/*.ts",
56
+ "test/**/*.tsx",
57
+ ]) + ["tsconfig.json"],
54
58
  deps = [
55
- ":my_module",
56
- "//src/valdi_modules/src/valdi/valdi_test",
57
- "//src/valdi_modules/src/foundation/test/util",
59
+ "//src/valdi_modules/src/valdi/valdi_core",
58
60
  "//src/valdi_modules/src/valdi/valdi_tsx",
61
+ "//src/valdi_modules/src/valdi/valdi_test",
62
+ "//src/valdi_modules/src/valdi/foundation/test/util",
59
63
  ],
60
64
  )
61
65
  ```
@@ -63,3 +67,15 @@ valdi_module(
63
67
  ## Platform Tests
64
68
 
65
69
  For C++, iOS, and Android platform layer tests, see the `valdi-cpp-runtime`, `valdi-ios`, and `valdi-android` skills respectively.
70
+
71
+ ## Combined Validation with agent-check
72
+
73
+ Instead of running build and test separately, use `agent-check`:
74
+
75
+ ```bash
76
+ valdi agent-check --module my_module # build + lint + test
77
+ valdi agent-check --module my_module --quick # lint + test only (hot reloader running)
78
+ valdi agent-check --module my_module --quick --json # machine-readable output
79
+ ```
80
+
81
+ See the **valdi-setup** skill for the full hot reloader + agent-check iteration workflow.
@@ -106,9 +106,17 @@ document.addEventListener('click', ...); // Doesn't work!
106
106
  onChange={this.handleTextChange}
107
107
  onEditEnd={this.handleSubmit}
108
108
  />
109
+
110
+ // ✅ CORRECT - For keyboard input on macOS desktop, use a polyglot <custom-view>
111
+ // (see valdi-polyglot-module and valdi-custom-view skills for full pattern)
112
+ {Device.isDesktop() && (
113
+ <custom-view macosClass='SCKeyboardView' onKeyDown={this.handleKeyDown} width={200} height={200}>
114
+ {/* wrap visible content so the view has non-zero size for first responder */}
115
+ </custom-view>
116
+ )}
109
117
  ```
110
118
 
111
- **Important**: Valdi doesn't support `addEventListener`, `keydown`, or other global DOM events. Use element-specific callbacks like `onTap`, `onPress`, `onChange`, etc.
119
+ **Important**: Valdi doesn't support `addEventListener`, `keydown`, or other global DOM events. Use element-specific callbacks like `onTap`, `onPress`, `onChange`, etc. For keyboard input on macOS desktop, use a polyglot `<custom-view>` with a native NSView that captures `keyDown:` events and forwards them via a bound callback attribute.
112
120
 
113
121
  ## Timers and Scheduling
114
122
 
@@ -178,6 +186,26 @@ onRender() {
178
186
  }
179
187
  ```
180
188
 
189
+ ### Font weights
190
+
191
+ Only two system font weights are available:
192
+ - `'system 16'` — regular weight
193
+ - `'system-bold 16'` — bold weight
194
+
195
+ **No other weights exist.** `system-semibold`, `system-light`, `system-medium` etc. will cause build errors. If you need semibold, use `system-bold` instead.
196
+
197
+ ### ScrollView restrictions
198
+
199
+ `<scroll>` (ScrollView) does **not** support `flexDirection`. It always scrolls vertically. Do not set `flexDirection: 'column'` on a ScrollView style — it will cause a build error.
200
+
201
+ ```typescript
202
+ // ❌ WRONG - flexDirection not valid on ScrollView
203
+ new Style<ScrollView>({ flexDirection: 'column' })
204
+
205
+ // ✅ CORRECT - ScrollView scrolls vertically by default, no flexDirection needed
206
+ new Style<ScrollView>({ width: '100%', height: '100%' })
207
+ ```
208
+
181
209
  ### Style Composition
182
210
 
183
211
  ```typescript
@@ -230,6 +258,11 @@ new Style<View>({
230
258
  paddingVertical: 10, // ❌ Use padding: '10 0'
231
259
  paddingInline: 15, // ❌ Doesn't exist
232
260
  })
261
+
262
+ // ❌ WRONG - gap property doesn't exist on View
263
+ new Style<View>({ flexDirection: 'row', gap: '8' })
264
+ // ✅ CORRECT - use margin on child elements instead
265
+ // In JSX: <view marginRight={8}> or margin="0 8 0 0"
233
266
  ```
234
267
 
235
268
  ### Layout: Flexbox (Yoga)
@@ -328,6 +361,28 @@ const layoutStyle = new Style<Layout>({ padding: 10 });
328
361
  >
329
362
  > **📖 Best practices**: See `/docs/docs/core-styling.md` for styling patterns and examples
330
363
 
364
+ ## @ExportModel ViewModel Restrictions
365
+
366
+ Interfaces annotated with `@ViewModel @ExportModel` are exported to native code. The Valdi compiler can only export **primitive types** (`string`, `number`, `boolean`) and other `@ExportModel`-annotated interfaces. Custom type aliases (e.g. `type Direction = 'UP' | 'DOWN'`) are **not supported** in exported ViewModels.
367
+
368
+ ```typescript
369
+ // ❌ WRONG — type alias in @ExportModel ViewModel
370
+ type Direction = 'UP' | 'DOWN' | 'LEFT' | 'RIGHT';
371
+
372
+ /** @ViewModel @ExportModel */
373
+ interface GameViewModel {
374
+ initialDirection?: Direction; // ❌ Compiler error: "Unrecognized type"
375
+ }
376
+
377
+ // ✅ CORRECT — keep custom types in State (internal), not ViewModel (exported)
378
+ /** @ViewModel @ExportModel */
379
+ interface GameViewModel {} // Only export what native code needs
380
+
381
+ interface GameState {
382
+ direction: Direction; // ✅ Fine — State is not exported
383
+ }
384
+ ```
385
+
331
386
  ## Common Mistakes to Avoid
332
387
 
333
388
  1. **Returning JSX from onRender()** - It returns void, JSX is a statement
@@ -337,10 +392,17 @@ const layoutStyle = new Style<Layout>({ padding: 10 });
337
392
  5. **Suggesting scheduleRender()** - Deprecated, use StatefulComponent + setState()
338
393
  6. **Using addEventListener** - Use element callbacks like onTap, onPress, onChange
339
394
  7. **Using setInterval/setTimeout directly** - Use this.setTimeoutDisposable()
340
- 8. **Using CSS properties that don't exist** - No gap, paddingHorizontal, paddingVertical
395
+ 8. **Using CSS properties that don't exist** - No gap, paddingHorizontal, paddingVertical; use margin on children for gap
341
396
  9. **Using `flex: 1`** - `flex` doesn't exist on `View`; use `flexGrow: 1` instead
342
397
  10. **Using `fontSize` on Label** - Labels use `font: 'system 20'` (string), not `fontSize`
343
- 11. **Using `overflow: 'hidden'`** - `View` only accepts `'visible' | 'scroll'`; remove overflow or use 'scroll'
398
+ 11. **Typing SIGIcon values as `string`** - `SIGIcon.cameraStroke` etc. return `Asset`, not `string`; use `import { Asset } from 'valdi_core/src/Asset'` for ViewModel fields that store icon references
399
+ 12. **Using `overflow: 'hidden'`** - `View` only accepts `'visible' | 'scroll'`; remove overflow or use 'scroll'
400
+ 13. **Using type aliases in `@ExportModel` ViewModels** - Only primitives and other `@ExportModel` types are allowed
401
+ 14. **Importing `Shape` instead of `ShapeView`** - `Shape` is not exported; use `import { ShapeView } from 'valdi_tsx/src/NativeTemplateElements'` and `new Style<ShapeView>({...})`
402
+ 15. **Using per-side border properties** - No `borderRight`, `borderRightWidth`, etc. Only `borderWidth`, `borderColor`, `borderRadius` exist. Use a thin `<view>` as a divider instead.
403
+ 16. **Using `font: 'system-semibold 16'`** - Only `system` (regular) and `system-bold` are reliably available. Use `system-bold` for semibold.
404
+ 17. **ViewModel/Context name collisions** - When a module has multiple components, each exported `ViewModel` and `ComponentContext` must have a unique name (e.g. `WeatherCardViewModel` not just `ViewModel`), or the compiler will emit conflicting platform types.
405
+ 18. **Using `flexDirection` on ScrollView** - ScrollView doesn't support flexDirection; it scrolls vertically by default
344
406
 
345
407
  ## Platform Detection
346
408
 
@@ -354,14 +416,16 @@ class MyComponent extends Component<MyViewModel> {
354
416
  <view>
355
417
  {Device.isIOS() && <IOSOnlyView />}
356
418
  {Device.isAndroid() && <AndroidOnlyView />}
357
- {Device.isMacOS() && <MacOSOnlyView />}
419
+ {Device.isDesktop() && <DesktopOnlyView />}
358
420
  {Device.isWeb() && <WebOnlyView />}
359
421
  </view>;
360
422
  }
361
423
  }
362
424
  ```
363
425
 
364
- Also use `Device.isIOS()` / `Device.isAndroid()` guards before using `<custom-view>` elements that don't have implementations on all platforms.
426
+ **Available guards:** `Device.isIOS()`, `Device.isAndroid()`, `Device.isDesktop()`, `Device.isWeb()`
427
+
428
+ Use platform guards before using `<custom-view>` elements that don't have implementations on all platforms. `Device.isDesktop()` is true for macOS desktop apps (the preview/standalone app). There is no `Device.isMacOS()` — use `Device.isDesktop()` instead.
365
429
 
366
430
  ## Imports
367
431