@snap/valdi 1.0.7 → 1.0.8

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 (160) hide show
  1. package/README.md +12 -3
  2. package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
  3. package/bundled-skills/registry.json +20 -0
  4. package/bundled-skills/skills/valdi-android/skill.md +89 -0
  5. package/bundled-skills/skills/valdi-async/skill.md +246 -0
  6. package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
  7. package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
  8. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
  9. package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
  10. package/bundled-skills/skills/valdi-bazel/skill.md +122 -0
  11. package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
  12. package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
  13. package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
  14. package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
  15. package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
  16. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
  17. package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
  18. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
  19. package/bundled-skills/skills/valdi-custom-view/skill.md +62 -0
  20. package/bundled-skills/skills/valdi-ios/skill.md +93 -0
  21. package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
  22. package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
  23. package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
  24. package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
  25. package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
  26. package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
  27. package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
  28. package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
  29. package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
  30. package/bundled-skills/skills/valdi-overview/skill.md +63 -0
  31. package/bundled-skills/skills/valdi-perf/skill.md +197 -0
  32. package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
  33. package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
  34. package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
  35. package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
  36. package/bundled-skills/skills/valdi-polyglot-module/skill.md +85 -0
  37. package/bundled-skills/skills/valdi-setup/skill.md +129 -0
  38. package/bundled-skills/skills/valdi-testing/skill.md +65 -0
  39. package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
  40. package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
  41. package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
  42. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
  43. package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
  44. package/dist/commands/bootstrap.js +0 -7
  45. package/dist/commands/newModule.js +10 -14
  46. package/dist/commands/skills.js +16 -0
  47. package/dist/commands/skills_commands/create.js +125 -0
  48. package/dist/commands/skills_commands/install.js +96 -0
  49. package/dist/commands/skills_commands/list.js +83 -0
  50. package/dist/commands/skills_commands/remove.js +41 -0
  51. package/dist/commands/skills_commands/update.js +59 -0
  52. package/dist/core/constants.js +0 -1
  53. package/dist/setup/versions.js +1 -1
  54. package/dist/utils/skillsAdapters.js +140 -0
  55. package/dist/utils/skillsRegistry.js +40 -0
  56. package/package.json +6 -1
  57. package/.bazelignore +0 -2
  58. package/.bootstrap/apps/cli_application/BUILD.bazel.template +0 -7
  59. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -11
  60. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +0 -1
  61. package/.bootstrap/apps/ui_application/.eslint.rc +0 -27
  62. package/.bootstrap/apps/ui_application/BUILD.bazel.template +0 -19
  63. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -21
  64. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  65. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +0 -133
  66. package/.bootstrap/apps/ui_application/package.json +0 -24
  67. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  68. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  69. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +0 -4
  70. package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +0 -39
  71. package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +0 -18
  72. package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +0 -31
  73. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  74. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  75. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  76. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  77. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  78. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  79. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  80. package/.bootstrap/modules/ui_component/BUILD.bazel.template +0 -34
  81. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +0 -45
  82. package/.config/copyconfig.json +0 -10
  83. package/.editorconfig +0 -21
  84. package/.eslintignore +0 -1
  85. package/.eslintrc.js +0 -72
  86. package/.github/README.md +0 -164
  87. package/.metadata/.bazelrc.template +0 -91
  88. package/.metadata/.bazelversion.template +0 -1
  89. package/.metadata/.cursorrules.template +0 -60
  90. package/.metadata/.editorconfig.template +0 -37
  91. package/.metadata/.eslintrc.js.template +0 -27
  92. package/.metadata/.gitignore.template +0 -4
  93. package/.metadata/.prettierrc.json.template +0 -7
  94. package/.metadata/.watchmanconfig.template +0 -8
  95. package/.metadata/AGENTS.md.template +0 -282
  96. package/.metadata/README.md.template +0 -31
  97. package/.metadata/WORKSPACE.template +0 -57
  98. package/.metadata/config.yaml.template +0 -1
  99. package/.metadata/package.json.template +0 -23
  100. package/.prettierignore +0 -2
  101. package/.prettierrc.json +0 -7
  102. package/LINUX_COMPATIBILITY.md +0 -248
  103. package/prettier.config.js +0 -4
  104. package/scripts/sync-agents-md.sh +0 -44
  105. package/scripts/update-agents-templates.ts +0 -170
  106. package/spec/support/jasmine.json +0 -6
  107. package/src/commands/bootstrap.ts +0 -410
  108. package/src/commands/build.ts +0 -89
  109. package/src/commands/devSetup.ts +0 -17
  110. package/src/commands/doctor.ts +0 -1832
  111. package/src/commands/export.ts +0 -131
  112. package/src/commands/hotreload.ts +0 -108
  113. package/src/commands/install.ts +0 -93
  114. package/src/commands/lint.ts +0 -15
  115. package/src/commands/lint_commands/lintCheck.ts +0 -53
  116. package/src/commands/lint_commands/lintFormat.ts +0 -49
  117. package/src/commands/log.ts +0 -108
  118. package/src/commands/newModule.ts +0 -286
  119. package/src/commands/package.ts +0 -102
  120. package/src/commands/projectsync.ts +0 -488
  121. package/src/commands/test.ts +0 -68
  122. package/src/core/constants.ts +0 -98
  123. package/src/core/errors.ts +0 -10
  124. package/src/index.ts +0 -27
  125. package/src/setup/DevSetupHelper.ts +0 -290
  126. package/src/setup/linuxSetup.ts +0 -261
  127. package/src/setup/macOSSetup.ts +0 -156
  128. package/src/setup/setupEntryPoint.ts +0 -64
  129. package/src/setup/versions.ts +0 -8
  130. package/src/utils/ArgumentsResolver.ts +0 -23
  131. package/src/utils/BazelClient.ts +0 -285
  132. package/src/utils/Digraph.ts +0 -81
  133. package/src/utils/LoadingIndicator.ts +0 -43
  134. package/src/utils/applicationUtils.ts +0 -276
  135. package/src/utils/buildInfo.ts +0 -99
  136. package/src/utils/byString.ts +0 -3
  137. package/src/utils/cliUtils.ts +0 -112
  138. package/src/utils/copyBootstrapFiles.ts +0 -30
  139. package/src/utils/deviceUtils.ts +0 -76
  140. package/src/utils/errorUtils.ts +0 -63
  141. package/src/utils/fileUtils.ts +0 -257
  142. package/src/utils/githubUtils.ts +0 -102
  143. package/src/utils/jsonUtils.ts +0 -30
  144. package/src/utils/lintUtils.ts +0 -190
  145. package/src/utils/linuxDistro.spec.ts +0 -219
  146. package/src/utils/linuxDistro.ts +0 -326
  147. package/src/utils/logUtils.ts +0 -9
  148. package/src/utils/pathUtils.ts +0 -12
  149. package/src/utils/stringUtils.spec.ts +0 -95
  150. package/src/utils/stringUtils.ts +0 -103
  151. package/src/utils/tempDir.ts +0 -24
  152. package/src/utils/zipUtils.ts +0 -14
  153. package/test/ValdiSmokeTest.ts +0 -279
  154. package/test/helpers/AsyncHelpers.ts +0 -113
  155. package/test/helpers/CommandHelpers.ts +0 -37
  156. package/test/helpers/ProjectHelpers.ts +0 -153
  157. package/test/helpers/StreamHelpers.ts +0 -37
  158. package/test/helpers/TypeScriptClient.ts +0 -217
  159. package/tsconfig.dist.json +0 -8
  160. package/tsconfig.json +0 -42
@@ -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,62 @@
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 Discovery
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 an `NSView`/`UIView` subclass linked into the binary.
33
+ - **macOS**: Same as iOS but with `NSView` subclass.
34
+ - **Web**: The `webClass` name is matched against the `WebViewClassRegistry`. Register by exporting `webPolyglotViews` from a web polyglot entry file (see `web-polyglot.md` rule).
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
@@ -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
+ )
@@ -0,0 +1,70 @@
1
+ # valdi-migrate skill tests
2
+
3
+ Validates that code migrated to Valdi using the `valdi-migrate` skill is free of
4
+ anti-patterns (React hooks, Compose APIs, inline lambdas, `map()` in render loops, etc.)
5
+ and that the output actually compiles.
6
+
7
+ ## Files
8
+
9
+ | File | Description |
10
+ |------|-------------|
11
+ | `BUILD.bazel` | Bazel build target — compiles `src/` and `output/` together |
12
+ | `tsconfig.json` | TypeScript config |
13
+ | `check_antipatterns.py` | Linter — exits 0 if clean, 1 if violations found |
14
+ | `flutter_example.dart` | Source Flutter code to migrate |
15
+ | `compose_example.kt` | Source Jetpack Compose code to migrate |
16
+ | `react_example.tsx` | Source React code to migrate |
17
+ | `src/expected_valdi.tsx` | Reference correct Valdi output (canonical ground truth) |
18
+ | `output/` | Skill-generated migrations — checked in after running integration tests |
19
+
20
+ ## Integration tests
21
+
22
+ These tests verify the skill produces correct, compilable Valdi from each source framework.
23
+
24
+ ### 1. Generate migrations
25
+
26
+ Ask Claude (with the `valdi-migrate` skill active) to migrate each source file:
27
+
28
+ ```
29
+ Migrate flutter_example.dart to Valdi
30
+ Migrate compose_example.kt to Valdi
31
+ Migrate react_example.tsx to Valdi
32
+ ```
33
+
34
+ Save each output to the `output/` directory:
35
+ - `output/flutter_migrated.tsx`
36
+ - `output/compose_migrated.tsx`
37
+ - `output/react_migrated.tsx`
38
+
39
+ ### 2. Anti-pattern check
40
+
41
+ Verify none of the outputs contain framework-specific patterns:
42
+
43
+ ```bash
44
+ cd client/src/open_source/ai-skills/skills/valdi-migrate/tests
45
+
46
+ python3 check_antipatterns.py output/flutter_migrated.tsx # must pass
47
+ python3 check_antipatterns.py output/compose_migrated.tsx # must pass
48
+ python3 check_antipatterns.py output/react_migrated.tsx # must pass
49
+
50
+ # Sanity check — source files should still fail
51
+ python3 check_antipatterns.py react_example.tsx # expected: fail
52
+ python3 check_antipatterns.py compose_example.kt # expected: fail
53
+ ```
54
+
55
+ ### 3. Compile check
56
+
57
+ Verify all outputs (reference + migrations) build with the Valdi compiler:
58
+
59
+ ```bash
60
+ cd client/src/open_source
61
+ bazel build //ai-skills/skills/valdi-migrate/tests:tests
62
+ ```
63
+
64
+ Expected: `Build completed successfully`
65
+
66
+ ## Updating the tests
67
+
68
+ - **Source examples** (`flutter_example.dart`, `compose_example.kt`, `react_example.tsx`): add new patterns you want the skill to handle correctly.
69
+ - **Reference output** (`src/expected_valdi.tsx`): update when Valdi APIs change (import paths, type signatures, etc.). Must always compile and pass the linter.
70
+ - **Skill** (`../skill.md`): update when adding new source frameworks or fixing incorrect migration guidance.
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Validates a Valdi TSX file for known anti-patterns.
4
+ Usage: python3 check_antipatterns.py <file.tsx>
5
+ Returns exit code 0 if clean, 1 if violations found.
6
+ """
7
+
8
+ import sys
9
+ import re
10
+
11
+ ANTI_PATTERNS = [
12
+ # React hooks
13
+ (r'\buseState\b', 'React hook: useState'),
14
+ (r'\buseEffect\b', 'React hook: useEffect'),
15
+ (r'\buseContext\b', 'React hook: useContext'),
16
+ (r'\buseMemo\b', 'React hook: useMemo'),
17
+ (r'\buseCallback\b', 'React hook: useCallback'),
18
+ (r'\buseRef\b', 'React hook: useRef'),
19
+
20
+ # Compose APIs
21
+ (r'@Composable', 'Compose: @Composable annotation'),
22
+ (r'\bremember\s*\{', 'Compose: remember { }'),
23
+ (r'\bmutableStateOf\b', 'Compose: mutableStateOf'),
24
+ (r'\bLaunchedEffect\b', 'Compose: LaunchedEffect'),
25
+ (r'\bDisposableEffect\b', 'Compose: DisposableEffect'),
26
+
27
+ # Functional components
28
+ (r'const\s+\w+\s*=\s*\([^)]*\)\s*=>\s*[<(]', 'Functional component arrow fn'),
29
+ (r'function\s+\w+\s*\([^)]*\)\s*\{[^}]*return\s*<', 'Functional component with return JSX'),
30
+
31
+ # Wrong naming
32
+ (r'\bthis\.props\b', 'Wrong: this.props (should be this.viewModel)'),
33
+ (r'\bonMount\b', 'Wrong: onMount (should be onCreate)'),
34
+ (r'\bonUnmount\b', 'Wrong: onUnmount (should be onDestroy)'),
35
+ (r'\bmarkNeedsRender\b', 'Wrong: markNeedsRender (use this.setState)'),
36
+ (r'\bscheduleRender\b', 'Wrong: scheduleRender (deprecated)'),
37
+
38
+ # return JSX in onRender
39
+ (r'onRender\s*\(\s*\)\s*\{[^}]*return\s*<', 'onRender() should not return JSX'),
40
+
41
+ # Inline lambdas in JSX props (e.g. onTap={() => ...})
42
+ (r'on\w+\s*=\s*\{\s*\(\s*\)\s*=>', 'Inline lambda in JSX prop (use class arrow fn)'),
43
+
44
+ # map() in JSX context
45
+ (r'\.map\s*\([^)]*=>\s*[^)]*<\w', 'map() returns array (use forEach in onRender)'),
46
+
47
+ # new Style inside onRender
48
+ (r'onRender\s*\(\s*\)\s*\{(?:[^}]|\{[^}]*\})*new\s+Style\s*<', 'new Style() inside onRender()'),
49
+
50
+ # Wrong import paths (discovered by build failures)
51
+ # Provider is two separate files, not a directory import
52
+ (r"from 'valdi_core/src/provider'",
53
+ "Wrong import: use 'valdi_core/src/provider/createProvider' and/or 'valdi_core/src/provider/withProviders'"),
54
+ ]
55
+
56
+ def check_file(path: str) -> list[tuple[int, str, str]]:
57
+ violations = []
58
+ with open(path) as f:
59
+ lines = f.readlines()
60
+ for lineno, line in enumerate(lines, 1):
61
+ stripped = line.lstrip()
62
+ # Skip comment lines
63
+ if stripped.startswith('//') or stripped.startswith('*') or stripped.startswith('#'):
64
+ continue
65
+ for pattern, description in ANTI_PATTERNS:
66
+ if re.search(pattern, line):
67
+ violations.append((lineno, description, line.rstrip()))
68
+ return violations
69
+
70
+ def main():
71
+ if len(sys.argv) < 2:
72
+ print(f'Usage: {sys.argv[0]} <file.tsx>', file=sys.stderr)
73
+ sys.exit(2)
74
+
75
+ path = sys.argv[1]
76
+ violations = check_file(path)
77
+
78
+ if not violations:
79
+ print(f'✅ {path}: no anti-patterns found')
80
+ sys.exit(0)
81
+ else:
82
+ print(f'❌ {path}: {len(violations)} violation(s) found')
83
+ for lineno, desc, text in violations:
84
+ print(f' Line {lineno}: [{desc}]')
85
+ print(f' {text}')
86
+ sys.exit(1)
87
+
88
+ if __name__ == '__main__':
89
+ main()