@snap/valdi 1.0.7 → 1.0.11

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 (170) hide show
  1. package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/BUILD.bazel.template +16 -1
  2. package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
  3. package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
  4. package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
  5. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
  6. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
  7. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
  8. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
  9. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
  10. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
  11. package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
  12. package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
  13. package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
  14. package/.metadata/AGENTS.md.template +8 -274
  15. package/.metadata/skill-reference.tsx.template +8 -0
  16. package/.metadata/skill-tests-BUILD.bazel.template +21 -0
  17. package/.metadata/skill-tests-README.md.template +17 -0
  18. package/.metadata/skill.md.template +27 -0
  19. package/README.md +12 -3
  20. package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
  21. package/bundled-skills/registry.json +21 -0
  22. package/bundled-skills/skills/valdi-android/skill.md +89 -0
  23. package/bundled-skills/skills/valdi-async/skill.md +246 -0
  24. package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
  25. package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
  26. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
  27. package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
  28. package/bundled-skills/skills/valdi-bazel/skill.md +141 -0
  29. package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
  30. package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
  31. package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
  32. package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
  33. package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
  34. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
  35. package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
  36. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
  37. package/bundled-skills/skills/valdi-custom-view/skill.md +64 -0
  38. package/bundled-skills/skills/valdi-inspect/skill.md +199 -0
  39. package/bundled-skills/skills/valdi-ios/skill.md +93 -0
  40. package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
  41. package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
  42. package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
  43. package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
  44. package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
  45. package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
  46. package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
  47. package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
  48. package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
  49. package/bundled-skills/skills/valdi-overview/skill.md +63 -0
  50. package/bundled-skills/skills/valdi-perf/skill.md +197 -0
  51. package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
  52. package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
  53. package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
  54. package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
  55. package/bundled-skills/skills/valdi-polyglot-module/skill.md +124 -0
  56. package/bundled-skills/skills/valdi-profile/skill.md +126 -0
  57. package/bundled-skills/skills/valdi-setup/skill.md +129 -0
  58. package/bundled-skills/skills/valdi-testing/skill.md +65 -0
  59. package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
  60. package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
  61. package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
  62. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
  63. package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
  64. package/dist/commands/bootstrap.js +0 -7
  65. package/dist/commands/inspect.js +16 -0
  66. package/dist/commands/inspect_commands/contexts.js +55 -0
  67. package/dist/commands/inspect_commands/devices.js +53 -0
  68. package/dist/commands/inspect_commands/heap.js +59 -0
  69. package/dist/commands/inspect_commands/select.js +43 -0
  70. package/dist/commands/inspect_commands/snapshot.js +64 -0
  71. package/dist/commands/inspect_commands/status.js +68 -0
  72. package/dist/commands/inspect_commands/tree.js +86 -0
  73. package/dist/commands/newModule.js +10 -14
  74. package/dist/commands/profile.js +16 -0
  75. package/dist/commands/profile_commands/capture.js +106 -0
  76. package/dist/commands/skills.js +16 -0
  77. package/dist/commands/skills_commands/create.js +125 -0
  78. package/dist/commands/skills_commands/install.js +96 -0
  79. package/dist/commands/skills_commands/list.js +83 -0
  80. package/dist/commands/skills_commands/remove.js +41 -0
  81. package/dist/commands/skills_commands/update.js +59 -0
  82. package/dist/core/constants.js +0 -1
  83. package/dist/core/packageFiles.spec.js +29 -0
  84. package/dist/setup/versions.js +1 -1
  85. package/dist/utils/daemonClient.js +342 -0
  86. package/dist/utils/hermesClient.js +252 -0
  87. package/dist/utils/skillsAdapters.js +140 -0
  88. package/dist/utils/skillsRegistry.js +40 -0
  89. package/dist/utils/stringUtils.spec.js +1 -1
  90. package/package.json +20 -5
  91. package/.bazelignore +0 -2
  92. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  93. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  94. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  95. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  96. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  97. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  98. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  99. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  100. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  101. package/.config/copyconfig.json +0 -10
  102. package/.editorconfig +0 -21
  103. package/.eslintignore +0 -1
  104. package/.eslintrc.js +0 -72
  105. package/.github/README.md +0 -164
  106. package/.metadata/.cursorrules.template +0 -60
  107. package/.prettierignore +0 -2
  108. package/.prettierrc.json +0 -7
  109. package/LINUX_COMPATIBILITY.md +0 -248
  110. package/prettier.config.js +0 -4
  111. package/scripts/sync-agents-md.sh +0 -44
  112. package/scripts/update-agents-templates.ts +0 -170
  113. package/spec/support/jasmine.json +0 -6
  114. package/src/commands/bootstrap.ts +0 -410
  115. package/src/commands/build.ts +0 -89
  116. package/src/commands/devSetup.ts +0 -17
  117. package/src/commands/doctor.ts +0 -1832
  118. package/src/commands/export.ts +0 -131
  119. package/src/commands/hotreload.ts +0 -108
  120. package/src/commands/install.ts +0 -93
  121. package/src/commands/lint.ts +0 -15
  122. package/src/commands/lint_commands/lintCheck.ts +0 -53
  123. package/src/commands/lint_commands/lintFormat.ts +0 -49
  124. package/src/commands/log.ts +0 -108
  125. package/src/commands/newModule.ts +0 -286
  126. package/src/commands/package.ts +0 -102
  127. package/src/commands/projectsync.ts +0 -488
  128. package/src/commands/test.ts +0 -68
  129. package/src/core/constants.ts +0 -98
  130. package/src/core/errors.ts +0 -10
  131. package/src/index.ts +0 -27
  132. package/src/setup/DevSetupHelper.ts +0 -290
  133. package/src/setup/linuxSetup.ts +0 -261
  134. package/src/setup/macOSSetup.ts +0 -156
  135. package/src/setup/setupEntryPoint.ts +0 -64
  136. package/src/setup/versions.ts +0 -8
  137. package/src/utils/ArgumentsResolver.ts +0 -23
  138. package/src/utils/BazelClient.ts +0 -285
  139. package/src/utils/Digraph.ts +0 -81
  140. package/src/utils/LoadingIndicator.ts +0 -43
  141. package/src/utils/applicationUtils.ts +0 -276
  142. package/src/utils/buildInfo.ts +0 -99
  143. package/src/utils/byString.ts +0 -3
  144. package/src/utils/cliUtils.ts +0 -112
  145. package/src/utils/copyBootstrapFiles.ts +0 -30
  146. package/src/utils/deviceUtils.ts +0 -76
  147. package/src/utils/errorUtils.ts +0 -63
  148. package/src/utils/fileUtils.ts +0 -257
  149. package/src/utils/githubUtils.ts +0 -102
  150. package/src/utils/jsonUtils.ts +0 -30
  151. package/src/utils/lintUtils.ts +0 -190
  152. package/src/utils/linuxDistro.spec.ts +0 -219
  153. package/src/utils/linuxDistro.ts +0 -326
  154. package/src/utils/logUtils.ts +0 -9
  155. package/src/utils/pathUtils.ts +0 -12
  156. package/src/utils/stringUtils.spec.ts +0 -95
  157. package/src/utils/stringUtils.ts +0 -103
  158. package/src/utils/tempDir.ts +0 -24
  159. package/src/utils/zipUtils.ts +0 -14
  160. package/test/ValdiSmokeTest.ts +0 -279
  161. package/test/helpers/AsyncHelpers.ts +0 -113
  162. package/test/helpers/CommandHelpers.ts +0 -37
  163. package/test/helpers/ProjectHelpers.ts +0 -153
  164. package/test/helpers/StreamHelpers.ts +0 -37
  165. package/test/helpers/TypeScriptClient.ts +0 -217
  166. package/tsconfig.dist.json +0 -8
  167. package/tsconfig.json +0 -42
  168. /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/android/CalculatorModuleFactory.kt.template +0 -0
  169. /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/ios/SCCCalculatorModuleFactory.m.template +0 -0
  170. /package/.bootstrap/modules/{cpp_bridge_module → polyglot_bridge_module}/src/Calculator.d.ts +0 -0
@@ -0,0 +1,103 @@
1
+ # C++ Runtime Rules
2
+
3
+ **Applies to**: C++ files in `/valdi/`, `/valdi_core/`, `/snap_drawing/`
4
+
5
+ ## Overview
6
+
7
+ Valdi's runtime and layout engine are implemented in C++ for cross-platform performance. This code runs on iOS, Android, macOS, but not web.
8
+
9
+ **Note**: `/libs/` contains shared utility libraries (crypto, logging, image processing) used across the codebase, but not the core runtime itself.
10
+
11
+ ## Code Style
12
+
13
+ - **4-space indentation**
14
+ - Follow existing C++ style in the codebase
15
+ - Use smart pointers appropriately
16
+ - Prefer const correctness
17
+
18
+ ## Key Concepts
19
+
20
+ ### Layout Engine
21
+
22
+ - Uses **Yoga** (Facebook's Flexbox implementation) for layout
23
+ - Cross-platform layout calculations
24
+ - Performance-critical code
25
+ - RTL (right-to-left) support built-in
26
+ - Yoga source: `/third-party/yoga/`
27
+
28
+ ### Memory Management
29
+
30
+ - Be careful with memory ownership
31
+ - Use RAII patterns
32
+ - Consider platform-specific memory constraints (mobile)
33
+
34
+ ### Platform Abstractions
35
+
36
+ - Code must work on iOS, Android, macOS
37
+ - Use platform-agnostic APIs where possible
38
+ - Platform-specific code goes in appropriate subdirectories
39
+
40
+ ## Common Patterns
41
+
42
+ ### Djinni Generated Code
43
+
44
+ - Some C++ code is generated from `.djinni` interface files
45
+ - **Don't modify generated code** - change the .djinni file instead
46
+ - Generated files typically in `generated-src/` directories
47
+
48
+ ### Performance
49
+
50
+ - This is performance-critical code
51
+ - Profile before optimizing
52
+ - Consider cache locality
53
+ - Be mindful of allocations in hot paths
54
+
55
+ ## Testing
56
+
57
+ ```bash
58
+ # Run all C++ runtime tests
59
+ bazel test //valdi:test
60
+
61
+ # Run specific test suites
62
+ bazel test //valdi:test_runtime # Runtime tests
63
+ bazel test //valdi:test_integration # Integration tests
64
+ bazel test //valdi:test_snap_drawing # Snap drawing tests
65
+ ```
66
+
67
+ ## Platform-Specific Notes
68
+
69
+ ### iOS
70
+ - Objective-C++ bridge in `/valdi/src/valdi/ios/`
71
+ - Metal for GPU rendering
72
+ - UIKit view integration
73
+
74
+ ### Android
75
+ - JNI bridge in `/valdi/src/valdi/android/`
76
+ - NDK integration
77
+ - Native view rendering
78
+
79
+ ### macOS
80
+ - Platform-specific code in `/valdi/src/valdi/macos/`
81
+ - Desktop runtime support
82
+
83
+ ### Build
84
+
85
+ ```bash
86
+ # Build runtime for specific platform
87
+ bazel build //valdi:valdi_ios
88
+ bazel build //valdi:valdi_android
89
+ bazel build //valdi:valdi_macos
90
+ ```
91
+
92
+ ## Important
93
+
94
+ 1. **Cross-platform first** - Code must work on all platforms
95
+ 2. **Performance critical** - UI rendering and layout
96
+ 3. **Memory efficiency** - Mobile devices have constraints
97
+ 4. **Thread safety** - Consider concurrency
98
+
99
+ ## More Information
100
+
101
+ - Runtime overview: `/valdi/README.md`
102
+ - Core bindings: `/valdi_core/README.md`
103
+ - Framework docs: `/AGENTS.md`
@@ -0,0 +1,64 @@
1
+ # Custom View Rules
2
+
3
+ **Applies to**: `**/*.tsx` files using `<custom-view>` elements.
4
+
5
+ ## `<custom-view>` Element
6
+
7
+ `<custom-view>` renders a platform-native view inside a Valdi component. Each platform resolves the view by class name.
8
+
9
+ ```typescript
10
+ <custom-view
11
+ androidClass="com.snap.modules.my_module.MyNativeView"
12
+ iosClass="SCMyNativeView"
13
+ macosClass="SCMyNativeView"
14
+ webClass="MyWebViewClassName"
15
+ width="100%"
16
+ height={120}
17
+ />
18
+ ```
19
+
20
+ ## Class Attributes
21
+
22
+ | Attribute | Platform | Resolution |
23
+ |-----------|----------|------------|
24
+ | `androidClass` | Android | Reflection via `ReflectionViewFactory`; needs `@RegisterAttributesBinder` |
25
+ | `iosClass` | iOS | ObjC class name; must be linked via `ios_deps` |
26
+ | `macosClass` | macOS | `NSClassFromString()`; must be linked via `macos_deps` |
27
+ | `webClass` | Web | Looked up in `WebViewClassRegistry`; registered via `webPolyglotViews` export |
28
+
29
+ ## Platform Resolution
30
+
31
+ - **Android**: The view class needs a single-arg `(Context)` constructor. An `@RegisterAttributesBinder`-annotated binder is discovered from assets at runtime.
32
+ - **iOS**: The ObjC class must be a `UIView` subclass linked into the binary via `ios_deps`.
33
+ - **macOS**: Falls through to `iosClass` when `macosClass` is not specified — both in TypeScript (`JSXBootstrap.ts`) and C++ (`ViewNode.cpp`). Only specify `macosClass` when the macOS view is different from iOS.
34
+ - **Web**: The `webClass` name is matched against the `WebViewClassRegistry`. Register by exporting `webPolyglotViews` from a typed TypeScript web polyglot entry file compiled via `ts_project` (see `valdi-polyglot-module` skill). Factories return an `AttributeHandler` with `changeAttribute(name, value)` to receive attribute updates.
35
+
36
+ ## viewFactory Pattern
37
+
38
+ Instead of resolving by class name, you can pass a `ViewFactory` object directly. This is useful when the factory is provided by a parent component or constructed dynamically:
39
+
40
+ ```typescript
41
+ import { ViewFactory } from 'valdi_tsx/src/ViewFactory';
42
+
43
+ interface MyViewModel {
44
+ viewFactory?: ViewFactory;
45
+ }
46
+
47
+ class MyComponent extends Component<MyViewModel> {
48
+ onRender(): void {
49
+ if (this.viewModel.viewFactory) {
50
+ <custom-view style={styles.container} viewFactory={this.viewModel.viewFactory} />;
51
+ }
52
+ }
53
+ }
54
+ ```
55
+
56
+ `viewFactory` and `*Class` attributes are mutually exclusive — use one or the other. `viewFactory` takes precedence when both are provided.
57
+
58
+ ## Common Mistakes
59
+
60
+ - Using `<custom-view>` without checking the platform — wrap in `Device.isAndroid()` / `Device.isIOS()` etc. if not all platforms are supported
61
+ - Forgetting to link native implementations — the class name string alone isn't enough; the native code must be compiled and linked via platform `_deps` in BUILD.bazel
62
+ - Wrong package name in `androidClass` — must match the Kotlin/Java package exactly
63
+ - Specifying `macosClass` when it's the same as `iosClass` — omit it and let the fallthrough handle it
64
+ - Using a `filegroup` for `web_deps` — always use `ts_project` with `transpiler = "tsc"`
@@ -0,0 +1,199 @@
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: "/tmp/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
+ ---
128
+
129
+ ### `valdi inspect heap`
130
+
131
+ Dump JS heap statistics for the connected device.
132
+
133
+ ```
134
+ valdi inspect heap
135
+ valdi inspect heap --pretty
136
+ valdi inspect heap --gc
137
+ ```
138
+
139
+ Options:
140
+ - `--gc`: run garbage collection before dumping (more accurate free memory reading)
141
+
142
+ Output: `{ memoryUsageBytes: number, heapDumpJSON: string }`
143
+
144
+ `heapDumpJSON` is a serialized heap snapshot in V8 format. Note: heap dumps can crash small/toy apps — this works best on full production apps.
145
+
146
+ ---
147
+
148
+ ## Common workflows
149
+
150
+ ### "What is rendering on screen right now?"
151
+
152
+ ```
153
+ valdi inspect tree --pretty
154
+ ```
155
+
156
+ (contextId is auto-selected if there's only one)
157
+
158
+ ### "Show me what a specific component looks like"
159
+
160
+ 1. Run `valdi inspect tree --pretty` to find the node — note its `element.id`
161
+ 2. Run `valdi inspect snapshot <element.id>` to capture it
162
+ 3. Read the PNG with the `Read` tool
163
+
164
+ ### "Diagnose a layout issue at position X,Y"
165
+
166
+ Run `valdi inspect tree --pretty` and look for `element.frame` values overlapping with the target position.
167
+
168
+ ### "Check memory usage"
169
+
170
+ ```
171
+ valdi inspect heap --pretty
172
+ ```
173
+
174
+ ### "Verify a hot-reload applied correctly"
175
+
176
+ Run `valdi inspect tree` before and after the edit, compare the JSON output.
177
+
178
+ ---
179
+
180
+ ## Options reference
181
+
182
+ | Option | Commands | Description |
183
+ |--------|----------|-------------|
184
+ | `--port <n>` | all | Daemon TCP port (default: 13592 mobile, 13591 standalone) |
185
+ | `--client <id>` | contexts, tree, snapshot, heap | Target a specific connected device |
186
+ | `--pretty` | devices, status, contexts, tree, heap | Human-readable output |
187
+ | `--max-depth <n>` | tree | Trim tree to N levels deep |
188
+ | `--output <path>` | snapshot | Custom PNG output path |
189
+ | `--gc` | heap | GC before heap dump |
190
+
191
+ ---
192
+
193
+ ## Troubleshooting
194
+
195
+ **"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`.
196
+
197
+ **"No devices connected"** — Make sure the Valdi app is running. For Android, ensure a device or emulator is connected via `adb`.
198
+
199
+ **"Timeout waiting for device response"** — The app may be frozen or the JS runtime may be busy. Try again after a moment.
@@ -0,0 +1,93 @@
1
+ # iOS Runtime Rules
2
+
3
+ **Applies to**: Objective-C/C++ files in `/valdi/src/valdi/ios/` and related iOS runtime code
4
+
5
+ ## Overview
6
+
7
+ The Valdi iOS runtime bridges TypeScript/Valdi components to native UIKit views. It's implemented in Objective-C, Objective-C++, and Swift.
8
+
9
+ ## Code Style
10
+
11
+ - **4-space indentation** for Objective-C
12
+ - Follow Apple's Objective-C conventions
13
+ - Use modern Objective-C features (properties, blocks, etc.)
14
+
15
+ ## Key Concepts
16
+
17
+ ### View Rendering
18
+
19
+ - Valdi components map to UIViews
20
+ - View recycling for performance
21
+ - UIKit integration
22
+
23
+ ### Platform Bridge
24
+
25
+ - Objective-C++ bridge to C++ runtime
26
+ - Memory management (ARC)
27
+ - iOS-specific APIs
28
+
29
+ ## Common Patterns
30
+
31
+ ### Bazel iOS Targets
32
+
33
+ ```python
34
+ objc_library(
35
+ name = "valdi_ios",
36
+ srcs = glob(["**/*.m", "**/*.mm"]),
37
+ hdrs = glob(["**/*.h"]),
38
+ )
39
+ ```
40
+
41
+ ### View Implementation
42
+
43
+ - Custom UIView subclasses
44
+ - CALayer for advanced rendering
45
+ - Metal for GPU acceleration
46
+
47
+ ## Testing
48
+
49
+ ```bash
50
+ # Run iOS runtime tests (Objective-C)
51
+ bazel test //valdi:valdi_ios_objc_test
52
+
53
+ # Run iOS runtime tests (Swift)
54
+ bazel test //valdi:valdi_ios_swift_test
55
+
56
+ # Run all iOS tests
57
+ bazel test //valdi:valdi_ios_objc_test //valdi:valdi_ios_swift_test
58
+ ```
59
+
60
+ Test files are in `/valdi/test/ios/` and `/valdi/test/ios_swift/`
61
+
62
+ ## Building
63
+
64
+ ```bash
65
+ # Build iOS runtime library
66
+ bazel build //valdi:valdi_ios
67
+
68
+ # Test with hello world app
69
+ cd apps/helloworld
70
+ valdi install ios
71
+ ```
72
+
73
+ ## Platform-Specific Notes
74
+
75
+ 1. **iOS Version** - Be mindful of minimum iOS version
76
+ 2. **ARC** - Automatic Reference Counting (memory management)
77
+ 3. **Auto Layout** - Valdi uses flexbox, not Auto Layout
78
+ 4. **Metal** - GPU rendering for advanced graphics
79
+
80
+ ## Important
81
+
82
+ - **Performance** - UIView creation and layout are critical
83
+ - **Memory** - Understand retain cycles and weak references
84
+ - **Threading** - Main thread for UI, background for heavy work
85
+ - **Lifecycle** - UIViewController lifecycle
86
+
87
+ ## More Information
88
+
89
+ - Runtime source: `/valdi/src/valdi/ios/`
90
+ - Runtime tests: `/valdi/test/ios/` and `/valdi/test/ios_swift/`
91
+ - Core iOS code: `/valdi_core/src/valdi_core/ios/`
92
+ - Build config: `/valdi/BUILD.bazel`
93
+ - Framework docs: `/AGENTS.md`
@@ -0,0 +1,175 @@
1
+ # Valdi Migration Assistant
2
+
3
+ Guidance for migrating code from Flutter, React, or Jetpack Compose to Valdi.
4
+
5
+ ## When to use
6
+
7
+ Use this skill when converting Flutter widgets, React components, or Compose `@Composable` functions to Valdi components, or when translating framework-specific patterns (hooks, widgets, Navigator, setState, remember, LaunchedEffect, Modifier, Provider, styled-components, FlatList, LazyColumn, etc.) to Valdi equivalents.
8
+
9
+ ## Critical: Never suggest these patterns
10
+
11
+ ```typescript
12
+ // ❌ React hooks — DO NOT EXIST in Valdi
13
+ useState / useEffect / useContext / useMemo / useCallback / useRef
14
+
15
+ // ❌ Compose APIs — DO NOT EXIST in Valdi
16
+ @Composable annotation
17
+ remember { mutableStateOf() } / remember { }
18
+ derivedStateOf / collectAsState / LaunchedEffect / DisposableEffect
19
+ Modifier chain (Modifier.padding().background().clickable())
20
+ CompositionLocalProvider / LocalXxx.current
21
+
22
+ // ❌ Functional components — DO NOT EXIST
23
+ const MyComp = () => <view />;
24
+ function MyComp(props) { return <view />; }
25
+
26
+ // ❌ Wrong naming
27
+ this.props // → this.viewModel
28
+ onMount/onUnmount // → onCreate/onDestroy
29
+ markNeedsRender() // → this.setState({})
30
+ scheduleRender() // → deprecated, use setState
31
+
32
+ // ❌ Returning JSX — onRender() returns void
33
+ onRender() { return <view />; } // no return statement
34
+
35
+ // ❌ Inline lambdas in JSX props — causes re-renders
36
+ <view onTap={() => this.doThing()} /> // use class arrow fn
37
+
38
+ // ❌ map() in render — does not work (JSX is side-effect, not return value)
39
+ {items.map(i => <Item key={i.id} />)} // use forEach
40
+
41
+ // ❌ JSX as a prop value
42
+ <MyComp label={<label value="hi" />} /> // use render prop () => void
43
+
44
+ // ❌ new Style() inside onRender() — style interning requires module-level init
45
+ onRender() { const s = new Style<View>({...}); ... } // wrong
46
+ ```
47
+
48
+ ## Correct patterns
49
+
50
+ ```typescript
51
+ import { Component, StatefulComponent } from 'valdi_core/src/Component';
52
+
53
+ // ✅ Stateless component
54
+ class MyComp extends Component<MyViewModel> {
55
+ onRender() {
56
+ <view>
57
+ <label value={this.viewModel.title} />;
58
+ </view>;
59
+ }
60
+ }
61
+
62
+ // ✅ Stateful component
63
+ class Counter extends StatefulComponent<MyViewModel, { count: number }> {
64
+ state = { count: 0 };
65
+
66
+ // Class arrow function — never inline lambda in JSX
67
+ private handleTap = () => {
68
+ this.setState({ count: this.state.count + 1 });
69
+ };
70
+
71
+ onRender() {
72
+ <view onTap={this.handleTap}>
73
+ <label value={`Count: ${this.state.count}`} />;
74
+ </view>;
75
+ }
76
+ }
77
+
78
+ // ✅ Lists — forEach, not map()
79
+ onRender() {
80
+ <scroll>
81
+ {this.viewModel.items.forEach(item => {
82
+ <Row key={item.id} data={item} />;
83
+ })}
84
+ </scroll>;
85
+ }
86
+
87
+ // ✅ Style — created at module level, not inside onRender()
88
+ const cardStyle = new Style<View>({ backgroundColor: '#fff', borderRadius: 8 });
89
+ ```
90
+
91
+ ## Lifecycle mapping
92
+
93
+ | Flutter | Jetpack Compose | React | Valdi |
94
+ |---------|-----------------|-------|-------|
95
+ | `initState()` | `LaunchedEffect(Unit) { }` | `componentDidMount` / `useEffect(fn, [])` | `onCreate()` |
96
+ | `dispose()` | `DisposableEffect { onDispose { } }` | `componentWillUnmount` / `useEffect(() => fn, [])` | `onDestroy()` |
97
+ | `didUpdateWidget(old)` | `LaunchedEffect(key) { }` | `componentDidUpdate(prev)` / `useEffect(fn, [dep])` | `onViewModelUpdate(previous?)` |
98
+ | `build(context)` | `@Composable fun` recomposition | `render(): JSX.Element` | `onRender(): void` |
99
+ | `setState(() {...})` | `mutableStateOf` + state write | `this.setState({...})` | `this.setState({...})` |
100
+
101
+ ## Component and element mapping
102
+
103
+ | Flutter | Jetpack Compose | React | Valdi |
104
+ |---------|-----------------|-------|-------|
105
+ | `StatelessWidget` | `@Composable fun` (stateless) | Function component | `class X extends Component<VM>` |
106
+ | `StatefulWidget` + `State` | `@Composable fun` + `remember { mutableStateOf() }` | Class component + state | `class X extends StatefulComponent<VM, State>` |
107
+ | `Container` / `SizedBox` (visual) | `Box` / `Surface` | `<div>` with styles | `<view>` |
108
+ | `SizedBox` (invisible spacer) | `Spacer` | Layout-only `<div>` | `<layout>` (no native view, faster) |
109
+ | `Text` | `Text(text)` | `<span>` / `<p>` | `<label value="...">` |
110
+ | `TextField` | `TextField` / `OutlinedTextField` | `<input>` | `<textfield>` (single-line) |
111
+ | `TextFormField` | `BasicTextField` (multi) | `<textarea>` | `<textview>` (multi-line) |
112
+ | `Image.network` | `AsyncImage` (Coil) | `<img>` | `<image src={url}>` |
113
+ | `ListView` / `FlatList` | `LazyColumn` / `LazyRow` | `<FlatList>` | `<scroll>` + `forEach` |
114
+ | `SingleChildScrollView` | `Column` + `verticalScroll` | `<ScrollView>` | `<scroll>` |
115
+ | `PageView` | `HorizontalPager` | `<ViewPager>` | `<scroll pagingEnabled={true}>` |
116
+ | `CircularProgressIndicator` | `CircularProgressIndicator` | `<ActivityIndicator>` | `<spinner>` |
117
+ | `GestureDetector` | `Modifier.clickable { }` | `onClick` / `onPress` | `onTap` on `<view>` |
118
+ | `Column` | `Column` | `flexDirection: 'column'` | `<view flexDirection="column">` (default) |
119
+ | `Row` | `Row` | `flexDirection: 'row'` | `<view flexDirection="row">` |
120
+ | `Stack` | `Box` with `align` | `position: absolute` | `<view>` + children with `position="absolute"` |
121
+ | `Modifier.padding(16.dp)` | `Modifier.padding(16.dp)` | `style={{padding:16}}` | `padding={16}` on any element |
122
+ | `Navigator.push` | `navController.navigate("route")` | `navigate()` / `router.push` | `navigationController.push(Page, vm, ctx)` |
123
+ | `Navigator.pop` | `navController.popBackStack()` | `goBack()` / `router.back` | `navigationController.pop()` |
124
+ | `showModalBottomSheet` | `ModalBottomSheet` / `Dialog` | `<Modal>` | `navigationController.present(Page, vm, ctx)` |
125
+ | `InheritedWidget` / `Provider` | `CompositionLocalProvider` | `React.Context` + `useContext` | `createProviderComponentWithKeyName<T>()` + `withProviders()` |
126
+ | `SharedPreferences` | `SharedPreferences` / `DataStore` | `AsyncStorage` / `localStorage` | `PersistentStore` (valdi persistence) |
127
+ | `http.get()` / `dio` | `viewModelScope.launch { api.get() }` | `fetch()` / `axios` | `HTTPClient.get()` (valdi_http) |
128
+ | `Lottie` | `LottieAnimation` | `<Lottie>` | `<animatedimage>` |
129
+ | `BackdropFilter` | `BlurMaskFilter` | CSS `backdrop-filter` | `<blur>` (iOS only) |
130
+
131
+ ## Key import paths
132
+
133
+ ```typescript
134
+ import { Component, StatefulComponent } from 'valdi_core/src/Component';
135
+ import { Style } from 'valdi_core/src/Style';
136
+ import { createProviderComponentWithKeyName } from 'valdi_core/src/provider/createProvider';
137
+ import { withProviders, ProvidersValuesViewModel } from 'valdi_core/src/provider/withProviders';
138
+ import { createReusableCallback } from 'valdi_core/src/utils/Callback';
139
+ import { HTTPClient } from 'valdi_http/src/HTTPClient';
140
+ import { PersistentStore } from 'persistence/src/PersistentStore';
141
+ import { Layout, View } from 'valdi_tsx/src/NativeTemplateElements';
142
+ ```
143
+
144
+ ## Provider pattern (replaces React Context / Flutter InheritedWidget)
145
+
146
+ ```typescript
147
+ import { createProviderComponentWithKeyName } from 'valdi_core/src/provider/createProvider';
148
+ import { ProvidersValuesViewModel, withProviders } from 'valdi_core/src/provider/withProviders';
149
+
150
+ const ThemeProvider = createProviderComponentWithKeyName<ThemeService>('ThemeProvider');
151
+
152
+ // ✅ Root provides value
153
+ class AppRoot extends Component {
154
+ private theme = new ThemeService();
155
+ onRender() {
156
+ <ThemeProvider value={this.theme}><App /></ThemeProvider>;
157
+ }
158
+ }
159
+
160
+ // ✅ Consumer wraps with HOC
161
+ interface MyViewModel extends ProvidersValuesViewModel<[ThemeService]> {}
162
+ class MyComp extends Component<MyViewModel> {
163
+ onRender() {
164
+ const [theme] = this.viewModel.providersValues;
165
+ <view backgroundColor={theme.primary} />;
166
+ }
167
+ }
168
+ const MyCompWithProvider = withProviders(ThemeProvider)(MyComp);
169
+ ```
170
+
171
+ ## Further reading
172
+
173
+ - [Migrating from React](../../../docs/docs/start-from-react.md)
174
+ - [Migrating from Flutter](../../../docs/docs/migrate-from-flutter.md)
175
+ - [Migrating from Jetpack Compose](../../../docs/docs/migrate-from-compose.md)
@@ -0,0 +1,23 @@
1
+ load("//bzl/valdi:valdi_module.bzl", "valdi_module")
2
+
3
+ valdi_module(
4
+ name = "tests",
5
+ srcs = glob([
6
+ "src/**/*.ts",
7
+ "src/**/*.tsx",
8
+ "output/**/*.ts",
9
+ "output/**/*.tsx",
10
+ ]) + [
11
+ "tsconfig.json",
12
+ ],
13
+ android_output_target = "release",
14
+ ios_module_name = "SCCValdiMigrateTest",
15
+ ios_output_target = "release",
16
+ visibility = ["//visibility:public"],
17
+ deps = [
18
+ "//src/valdi_modules/src/valdi/persistence",
19
+ "//src/valdi_modules/src/valdi/valdi_core",
20
+ "//src/valdi_modules/src/valdi/valdi_http",
21
+ "//src/valdi_modules/src/valdi/valdi_tsx",
22
+ ],
23
+ )