@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,202 @@
1
+ // valdi-perf skill reference — compile check for performance patterns.
2
+ // This file must compile cleanly against the Valdi TypeScript compiler.
3
+ // Run: bzl build //ai-skills/skills/valdi-perf/tests:tests
4
+
5
+ import { Component, StatefulComponent } from 'valdi_core/src/Component';
6
+ import { Style } from 'valdi_core/src/Style';
7
+ import { createReusableCallback } from 'valdi_core/src/utils/Callback';
8
+ import { Layout, View } from 'valdi_tsx/src/NativeTemplateElements';
9
+
10
+ // ─── Module-level styles (defeats interning if created inside onRender) ───────
11
+
12
+ const styles = {
13
+ card: new Style<View>({ backgroundColor: '#fff', borderRadius: 8, padding: 12 }),
14
+ spacer: new Style<Layout>({ height: 16 }),
15
+ row: new Style<View>({ flexDirection: 'row', alignItems: 'center' }),
16
+ };
17
+
18
+ // ─── Stable class property for constant arrays ───────────────────────────────
19
+
20
+ interface TabBarViewModel {
21
+ tabs: string[];
22
+ }
23
+
24
+ class TabBar extends Component<TabBarViewModel> {
25
+ onRender(): void {
26
+ <view style={styles.row}>
27
+ {this.viewModel.tabs.forEach(tab => {
28
+ <label key={tab} value={tab} />;
29
+ })}
30
+ </view>;
31
+ }
32
+ }
33
+
34
+ // ─── Pre-computed viewModel in onViewModelUpdate ─────────────────────────────
35
+
36
+ interface UserRowViewModel {
37
+ name: string;
38
+ subtitle: string;
39
+ }
40
+
41
+ class UserRow extends Component<UserRowViewModel> {
42
+ onRender(): void {
43
+ <view style={styles.card}>
44
+ <label value={this.viewModel.name} />;
45
+ <label value={this.viewModel.subtitle} />;
46
+ </view>;
47
+ }
48
+ }
49
+
50
+ interface UserListViewModel {
51
+ user: { id: string; name: string; bio: string };
52
+ }
53
+
54
+ interface UserListState {
55
+ selectedIndex: number;
56
+ }
57
+
58
+ class UserList extends StatefulComponent<UserListViewModel, UserListState> {
59
+ state: UserListState = { selectedIndex: 0 };
60
+
61
+ // Pre-computed to avoid new object on every render
62
+ private userRowVM: UserRowViewModel = { name: '', subtitle: '' };
63
+
64
+ onViewModelUpdate(previous?: UserListViewModel): void {
65
+ if (this.viewModel.user.id !== previous?.user.id) {
66
+ this.userRowVM = {
67
+ name: this.viewModel.user.name,
68
+ subtitle: this.viewModel.user.bio,
69
+ };
70
+ }
71
+ }
72
+
73
+ onRender(): void {
74
+ // ✅ Stable reference — UserRow only re-renders when user.id changes
75
+ <UserRow {...this.userRowVM} />;
76
+ }
77
+ }
78
+
79
+ // ─── createReusableCallback: stable function for same arguments ───────────────
80
+
81
+ interface SectionViewModel {
82
+ id: string;
83
+ title: string;
84
+ }
85
+
86
+ interface SectionListViewModel {
87
+ sections: SectionViewModel[];
88
+ }
89
+
90
+ interface SectionListState {
91
+ selectedId: string | null;
92
+ }
93
+
94
+ class SectionList extends StatefulComponent<SectionListViewModel, SectionListState> {
95
+ state: SectionListState = { selectedId: null };
96
+
97
+ private handleSectionTap(id: string): void {
98
+ this.setState({ selectedId: id });
99
+ }
100
+
101
+ onRender(): void {
102
+ <view>
103
+ {this.viewModel.sections.forEach(section => {
104
+ // ✅ Inline Callback — Valdi merges identity, child doesn't re-render
105
+ <view key={section.id} onTap={createReusableCallback(() => this.handleSectionTap(section.id))}>
106
+ <label value={section.title} />;
107
+ </view>;
108
+ })}
109
+ </view>;
110
+ }
111
+ }
112
+
113
+ // ─── Stable render props as class arrow functions ────────────────────────────
114
+
115
+ interface Item {
116
+ id: string;
117
+ label: string;
118
+ }
119
+
120
+ interface FlatListViewModel {
121
+ items: Item[];
122
+ renderItem: (item: Item) => void;
123
+ }
124
+
125
+ class FlatList extends Component<FlatListViewModel> {
126
+ onRender(): void {
127
+ <scroll>
128
+ {this.viewModel.items.forEach(item => {
129
+ this.viewModel.renderItem(item);
130
+ })}
131
+ </scroll>;
132
+ }
133
+ }
134
+
135
+ interface FeedViewModel {
136
+ items: Item[];
137
+ }
138
+
139
+ class Feed extends Component<FeedViewModel> {
140
+ // ✅ Stable reference — defined as class property, not inline in onRender
141
+ private renderItem = (item: Item): void => {
142
+ <view key={item.id}>
143
+ <label value={item.label} />;
144
+ </view>;
145
+ };
146
+
147
+ onRender(): void {
148
+ <FlatList items={this.viewModel.items} renderItem={this.renderItem} />;
149
+ }
150
+ }
151
+
152
+ // ─── <layout> vs <view>: no native view for invisible containers ──────────────
153
+
154
+ interface CardViewModel {
155
+ title: string;
156
+ subtitle: string;
157
+ }
158
+
159
+ class Card extends Component<CardViewModel> {
160
+ onRender(): void {
161
+ <view style={styles.card}>
162
+ <label value={this.viewModel.title} />;
163
+ {/* ✅ layout: no native view allocated for spacer */}
164
+ <layout style={styles.spacer} />;
165
+ {/* ✅ layout: invisible structural wrapper */}
166
+ <layout flexDirection="row" alignItems="center">
167
+ <label value={this.viewModel.subtitle} />;
168
+ </layout>;
169
+ </view>;
170
+ }
171
+ }
172
+
173
+ // ─── Keys in lists: stable data ID, not index ────────────────────────────────
174
+
175
+ interface ListItem {
176
+ id: string;
177
+ text: string;
178
+ }
179
+
180
+ interface StableListViewModel {
181
+ items: ListItem[];
182
+ }
183
+
184
+ class StableList extends Component<StableListViewModel> {
185
+ onRender(): void {
186
+ <scroll>
187
+ {this.viewModel.items.forEach(item => {
188
+ // ✅ Stable key from data ID — reorder/insert/remove works correctly
189
+ <view key={item.id}>
190
+ <label value={item.text} />;
191
+ </view>;
192
+ })}
193
+ </scroll>;
194
+ }
195
+ }
196
+
197
+ void TabBar;
198
+ void UserList;
199
+ void SectionList;
200
+ void Feed;
201
+ void Card;
202
+ void StableList;
@@ -0,0 +1 @@
1
+ {"extends": "../../../../src/valdi_modules/src/valdi/_configs/base.tsconfig.json"}
@@ -0,0 +1,124 @@
1
+ # Polyglot Module Rules
2
+
3
+ **Applies to**: `**/BUILD.bazel` and source files in modules with platform-specific implementations (`android/`, `ios/`, `macos/`, `web/` directories).
4
+
5
+ ## Module Structure
6
+
7
+ A polyglot module contains platform-native implementations alongside Valdi TSX source:
8
+
9
+ ```
10
+ my_module/
11
+ src/ # Valdi TSX components (compiled by Valdi compiler)
12
+ android/ # Kotlin/Java native implementation
13
+ ios/ # Objective-C native implementation
14
+ macos/ # Objective-C native implementation (macOS desktop)
15
+ web/ # TypeScript web implementation (compiled by ts_project, NOT Valdi compiler)
16
+ strings/ # Localization
17
+ module.yaml
18
+ tsconfig.json
19
+ BUILD.bazel
20
+ ```
21
+
22
+ ## BUILD.bazel Pattern
23
+
24
+ ```python
25
+ load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
26
+
27
+ # web_deps MUST be a ts_project — never use filegroup for web code.
28
+ ts_project(
29
+ name = "my_module_web",
30
+ srcs = glob(
31
+ [
32
+ "web/**/*.ts",
33
+ "src/**/*.d.ts", # include if web code imports module type declarations
34
+ ],
35
+ exclude = ["web/**/*.d.ts"], # exclude to avoid TS5055 output collision with composite
36
+ ),
37
+ allow_js = True,
38
+ composite = True,
39
+ transpiler = "tsc", # required — aspect_rules_ts does not default it
40
+ tsconfig = "web/tsconfig.json",
41
+ visibility = ["//visibility:public"],
42
+ )
43
+
44
+ valdi_module(
45
+ name = "my_module",
46
+ srcs = glob(["src/**/*.ts", "src/**/*.tsx"]) + ["tsconfig.json"],
47
+ android_deps = [":android_impl"],
48
+ ios_deps = [":ios_impl"],
49
+ macos_deps = [":macos_impl"],
50
+ web_deps = [":my_module_web"],
51
+ deps = [...],
52
+ )
53
+ ```
54
+
55
+ - `web_deps`: makes `web/` outputs available to the web bundle. Any file in `web_deps` that exports `webPolyglotViews` is automatically registered with the `WebViewClassRegistry` at bundle time — no extra configuration needed.
56
+ - After changing `module.yaml` deps, run: `./scripts/regenerate_valdi_modules_build_bazel_files.sh`
57
+
58
+ ## Web Polyglot Entry Pattern
59
+
60
+ Web entry files export view factories that are auto-registered with the `WebViewClassRegistry` at bundle time. Use typed TypeScript with an `AttributeHandler` interface:
61
+
62
+ ```typescript
63
+ interface AttributeHandler {
64
+ changeAttribute(name: string, value: unknown): void;
65
+ }
66
+
67
+ type ViewFactory = (container: HTMLElement) => AttributeHandler;
68
+
69
+ function createMyViewFactory(): ViewFactory {
70
+ return (container: HTMLElement): AttributeHandler => {
71
+ const element = document.createElement('div');
72
+ container.appendChild(element);
73
+
74
+ return {
75
+ changeAttribute(name: string, value: unknown): void {
76
+ if (name === 'myAttribute' && typeof value === 'number') {
77
+ element.textContent = String(value);
78
+ }
79
+ },
80
+ };
81
+ };
82
+ }
83
+
84
+ // Keys must match the webClass attribute in <custom-view webClass="MyCustomViewClass">
85
+ export const webPolyglotViews: Record<string, ViewFactory> = {
86
+ MyCustomViewClass: createMyViewFactory(),
87
+ };
88
+ ```
89
+
90
+ ### Web `tsconfig.json`
91
+
92
+ The `web/tsconfig.json` must be standalone — do not extend the module-level tsconfig (it has Valdi path mappings that don't apply to web builds):
93
+
94
+ ```json
95
+ {
96
+ "compilerOptions": {
97
+ "target": "ES2016",
98
+ "module": "commonjs",
99
+ "strict": true,
100
+ "composite": true,
101
+ "allowJs": true,
102
+ "lib": ["dom", "ES2019"]
103
+ }
104
+ }
105
+ ```
106
+
107
+ ### Key constraints for `web/` files
108
+ - Compiled by `tsc` via `ts_project`, **not** the Valdi compiler
109
+ - Do **NOT** use Valdi imports (`valdi_core/`, `valdi_tsx/`) — web files run in the browser, not the Valdi runtime
110
+ - Do **NOT** manually call `globalThis.moduleLoader.resolveRequire()` — build system handles registration
111
+ - The `web/tsconfig.json` must be standalone with `lib: ["dom", "ES2019"]` and `module: "commonjs"`
112
+ - Always use `transpiler = "tsc"` in the `ts_project` rule — aspect_rules_ts requires explicit transpiler selection
113
+
114
+ ## Canonical Example
115
+
116
+ See `valdi_polyglot` module for a complete working example with all four platforms:
117
+ - `src/composer_modules/src/composer/valdi_polyglot/` (in the Snap monorepo)
118
+ - Or the equivalent path in your project
119
+
120
+ ## Common Mistakes
121
+
122
+ - Putting `web/` files in `srcs` — they must go through `ts_project` + `web_deps`, not the Valdi compiler
123
+ - Missing platform `_deps` — each platform impl must be wired via `android_deps`, `ios_deps`, `macos_deps`
124
+ - Using Valdi imports in `web/` — they don't exist in the browser bundle
@@ -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.
@@ -0,0 +1,129 @@
1
+ # Valdi Module Setup
2
+
3
+ ## BUILD.bazel — valdi_module()
4
+
5
+ ```python
6
+ load("//bzl/valdi:valdi_module.bzl", "valdi_module")
7
+
8
+ valdi_module(
9
+ name = "my_module", # Must match the directory name exactly
10
+ srcs = glob([
11
+ "src/**/*.ts",
12
+ "src/**/*.tsx",
13
+ ]) + [
14
+ "tsconfig.json", # tsconfig must be listed in srcs
15
+ ],
16
+ android_output_target = "release",
17
+ ios_module_name = "SCCMyModule", # SCC prefix + PascalCase module name
18
+ ios_output_target = "release",
19
+ visibility = ["//visibility:public"],
20
+ deps = [
21
+ "//src/valdi_modules/src/valdi/valdi_core",
22
+ "//src/valdi_modules/src/valdi/valdi_tsx",
23
+ # Add as needed — see dependency table below
24
+ ],
25
+ )
26
+ ```
27
+
28
+ **Common mistakes that cause build failures:**
29
+
30
+ - `name` must equal the Bazel package directory name. The Valdi compiler derives
31
+ module identity from this — mismatches cause a build error.
32
+ - `tsconfig.json` must be in `srcs`. It won't be picked up automatically even if
33
+ it's in the directory.
34
+ - Missing a dep (e.g. using `HTTPClient` without `valdi_http`) produces a TypeScript
35
+ path resolution error, not a missing import error — can be confusing.
36
+
37
+ ## tsconfig.json
38
+
39
+ ```json
40
+ {
41
+ "extends": "../../../../src/valdi_modules/src/valdi/_configs/base.tsconfig.json"
42
+ }
43
+ ```
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.
48
+
49
+ ## Dependency Table
50
+
51
+ | You're using | Add this dep |
52
+ |---|---|
53
+ | `Component`, `StatefulComponent`, `Style`, providers, `CancelablePromise` | `//src/valdi_modules/src/valdi/valdi_core` |
54
+ | JSX elements (`<view>`, `<label>`, etc.), `NativeTemplateElements` | `//src/valdi_modules/src/valdi/valdi_tsx` |
55
+ | `HTTPClient`, `HTTPResponse` | `//src/valdi_modules/src/valdi/valdi_http` |
56
+ | `PersistentStore` | `//src/valdi_modules/src/valdi/persistence` |
57
+ | Pre-built UI components (buttons, cards, etc.) | `//src/valdi_modules/src/valdi/valdi_widgets_core` |
58
+
59
+ ## ios_module_name Convention
60
+
61
+ Must start with `SCC` followed by the module name in PascalCase:
62
+
63
+ | Directory name | ios_module_name |
64
+ |---|---|
65
+ | `chat_thread` | `SCCChatThread` |
66
+ | `profile_editor` | `SCCProfileEditor` |
67
+ | `story_viewer` | `SCCStoryViewer` |
68
+
69
+ This becomes the Swift module name on iOS. Conflicts with other `SCCXxx` modules in
70
+ the same app target will cause a linker error.
71
+
72
+ ## New Component File Template
73
+
74
+ ```typescript
75
+ import { Component } from 'valdi_core/src/Component';
76
+
77
+ interface MyComponentViewModel {
78
+ // viewModel properties
79
+ }
80
+
81
+ export class MyComponent extends Component<MyComponentViewModel> {
82
+ onRender(): void {
83
+ <view>
84
+ <label value={this.viewModel.someText} />;
85
+ </view>;
86
+ }
87
+ }
88
+ ```
89
+
90
+ For stateful components:
91
+
92
+ ```typescript
93
+ import { StatefulComponent } from 'valdi_core/src/Component';
94
+
95
+ interface MyState {
96
+ // state properties
97
+ }
98
+
99
+ export class MyComponent extends StatefulComponent<MyComponentViewModel, MyState> {
100
+ state: MyState = { /* initial values */ };
101
+
102
+ onRender(): void {
103
+ // ...
104
+ }
105
+ }
106
+ ```
107
+
108
+ ## Building
109
+
110
+ ```bash
111
+ bazel build //path/to/my_module:my_module
112
+ ```
113
+
114
+ ## Hot Reload
115
+
116
+ ```bash
117
+ valdi hotreload
118
+ ```
119
+
120
+ Run from your module directory. The CLI watches for file changes, recompiles, and
121
+ pushes the updated module to a connected simulator or device over USB (or network
122
+ with `--network`).
123
+
124
+ ```bash
125
+ valdi hotreload --network # Discover device over Wi-Fi instead of USB
126
+ ```
127
+
128
+ If hot reload stops reflecting changes, stop with `Ctrl+C` and restart — the CLI
129
+ will clean stale build artifacts automatically.
@@ -0,0 +1,65 @@
1
+ # Valdi Testing
2
+
3
+ ## Component Tests (most common)
4
+
5
+ Use `valdiIt` from `valdi_test/test/JSXTestUtils` as the test wrapper. It provides a `driver` that renders components synchronously.
6
+
7
+ See **`valdi-component-tests`** skill for the full guide on:
8
+ - `elementKeyFind`, `elementTypeFind`, `componentTypeFind`, `componentGetElements`
9
+ - `tapNodeWithKey` for tap callbacks
10
+ - Discriminated union and array view model testing
11
+ - Lint rules (`jsx-no-lambda`, `explicit-function-return-type`, etc.)
12
+
13
+ ## Running Tests
14
+
15
+ ```bash
16
+ # Run a specific module's tests
17
+ bazel test //modules/my_module:tests
18
+
19
+ # Run with output on failure
20
+ bazel test //modules/my_module:tests --test_output=errors
21
+
22
+ # Run all tests in the repo
23
+ bazel test //...
24
+
25
+ # Filter to a specific test class
26
+ bazel test //modules/my_module:tests --test_filter=MyComponentTest
27
+ ```
28
+
29
+ ## Test File Location
30
+
31
+ Test files must mirror the source file hierarchy:
32
+
33
+ ```
34
+ my_module/
35
+ ├── src/
36
+ │ └── categories/
37
+ │ └── CollectionComponent.tsx
38
+ └── test/
39
+ └── categories/
40
+ └── CollectionComponentTest.spec.tsx
41
+ ```
42
+
43
+ ## BUILD.bazel for Tests
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:
46
+
47
+ ```python
48
+ load("//bzl/valdi:valdi_module.bzl", "valdi_module")
49
+
50
+ valdi_module(
51
+ name = "my_module_tests",
52
+ srcs = glob(["test/**/*.spec.tsx", "test/**/*.spec.ts"]),
53
+ testonly = True,
54
+ deps = [
55
+ ":my_module",
56
+ "//src/valdi_modules/src/valdi/valdi_test",
57
+ "//src/valdi_modules/src/foundation/test/util",
58
+ "//src/valdi_modules/src/valdi/valdi_tsx",
59
+ ],
60
+ )
61
+ ```
62
+
63
+ ## Platform Tests
64
+
65
+ For C++, iOS, and Android platform layer tests, see the `valdi-cpp-runtime`, `valdi-ios`, and `valdi-android` skills respectively.