@snap/valdi 1.0.11 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.metadata/.bazelrc.template +6 -5
  2. package/.metadata/MODULE.bazel.template +62 -0
  3. package/bundled-skills/registry.json +13 -2
  4. package/bundled-skills/skills/valdi-animations/skill.md +197 -0
  5. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
  6. package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
  7. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
  8. package/bundled-skills/skills/valdi-custom-view/skill.md +43 -1
  9. package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
  10. package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
  11. package/bundled-skills/skills/valdi-inspect/skill.md +19 -1
  12. package/bundled-skills/skills/valdi-localization/skill.md +142 -0
  13. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
  14. package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
  15. package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
  16. package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
  17. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
  18. package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
  19. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
  20. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
  21. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
  22. package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
  23. package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
  24. package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
  25. package/bundled-skills/skills/valdi-overview/skill.md +7 -4
  26. package/bundled-skills/skills/valdi-perf/skill.md +223 -0
  27. package/bundled-skills/skills/valdi-polyglot-module/skill.md +80 -0
  28. package/bundled-skills/skills/valdi-preview/skill.md +303 -0
  29. package/bundled-skills/skills/valdi-setup/skill.md +55 -5
  30. package/bundled-skills/skills/valdi-testing/skill.md +23 -7
  31. package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
  32. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
  33. package/dist/commands/agentCheck.js +184 -0
  34. package/dist/commands/analyze.js +16 -0
  35. package/dist/commands/analyze_commands/duplicates.js +134 -0
  36. package/dist/commands/bootstrap.js +57 -73
  37. package/dist/commands/doctor.js +40 -203
  38. package/dist/commands/hotreload.js +15 -0
  39. package/dist/commands/inspect_commands/snapshot.js +71 -6
  40. package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
  41. package/dist/commands/preview.js +81 -0
  42. package/dist/commands/projectsync.js +9 -7
  43. package/dist/commands/skills_commands/install.js +6 -1
  44. package/dist/commands/skills_commands/update.js +2 -1
  45. package/dist/core/analyze/clusterer.js +150 -0
  46. package/dist/core/analyze/fingerprint.js +2 -0
  47. package/dist/core/analyze/knownPatterns.js +76 -0
  48. package/dist/core/analyze/parser.js +177 -0
  49. package/dist/core/analyze/reporter.js +83 -0
  50. package/dist/core/analyze/scanner.js +172 -0
  51. package/dist/core/analyze/similarity.js +56 -0
  52. package/dist/core/constants.js +1 -1
  53. package/dist/core/packageFiles.spec.js +1 -1
  54. package/dist/preview/previewGenerator.js +240 -0
  55. package/dist/preview/previewGenerator.spec.js +203 -0
  56. package/dist/preview/viewModelParser.js +86 -0
  57. package/dist/preview/viewModelParser.spec.js +171 -0
  58. package/dist/setup/DevSetupHelper.js +0 -51
  59. package/dist/setup/linuxSetup.js +0 -2
  60. package/dist/setup/macOSSetup.js +1 -4
  61. package/dist/utils/BazelClient.js +15 -0
  62. package/dist/utils/daemonClient.js +3 -1
  63. package/dist/utils/skillsAdapters.js +86 -5
  64. package/dist/utils/skillsAdapters.spec.js +60 -0
  65. package/dist/utils/skillsRegistry.js +8 -0
  66. package/package.json +16 -8
  67. package/.metadata/WORKSPACE.template +0 -57
  68. package/dist/setup/versions.js +0 -8
@@ -0,0 +1,238 @@
1
+ # Valdi Error Handling
2
+
3
+ Error handling, promise rejection, and lifecycle safety patterns.
4
+
5
+ ## When to use
6
+
7
+ When dealing with async operations, network requests, component lifecycle boundaries, or any code that can fail at runtime.
8
+
9
+ ## Key concepts
10
+
11
+ Valdi runs on a JavaScript runtime (Hermes/V8) with native platform integration. Unhandled errors crash the app. The primary error sources are:
12
+
13
+ 1. **Async operations** completing after component destruction
14
+ 2. **Network failures** from HTTPClient
15
+ 3. **Uncaught promise rejections**
16
+ 4. **Type mismatches** from native/JS boundary
17
+
18
+ ## CancelablePromise — the first line of defense
19
+
20
+ Most Valdi errors stem from async work completing after a component is destroyed. `CancelablePromise` + `registerDisposable` prevents this entirely:
21
+
22
+ ```tsx
23
+ import { promiseToCancelablePromise } from 'valdi_core/src/CancelablePromise';
24
+
25
+ // ✅ Safe async — cancelled on component destruction
26
+ onCreate() {
27
+ const cancelable = promiseToCancelablePromise(this.fetchData(), () => {});
28
+ this.registerDisposable(() => cancelable.cancel?.());
29
+ cancelable.then(
30
+ data => { this.setState({ data, loading: false }); },
31
+ error => { this.setState({ error: error.message, loading: false }); },
32
+ );
33
+ }
34
+ ```
35
+
36
+ ```tsx
37
+ // ❌ WRONG — Raw promise with no lifecycle safety
38
+ onCreate() {
39
+ this.fetchData().then(data => {
40
+ this.setState({ data }); // Crashes if component is destroyed
41
+ });
42
+ }
43
+ ```
44
+
45
+ See the `valdi-async` skill for comprehensive CancelablePromise patterns.
46
+
47
+ ## HTTPClient error handling
48
+
49
+ `HTTPClient` is an instance, not static. Methods return `CancelablePromise<HTTPResponse>`.
50
+
51
+ ```tsx
52
+ import { HTTPClient } from 'valdi_http/src/HTTPClient';
53
+
54
+ private httpClient = new HTTPClient('https://api.example.com');
55
+
56
+ // ✅ Handle network errors with lifecycle safety
57
+ private fetchData = () => {
58
+ const cancelable = this.httpClient.get('/data');
59
+ this.registerDisposable(() => cancelable.cancel?.());
60
+ cancelable.then(
61
+ response => {
62
+ if (response.statusCode !== 200) {
63
+ this.setState({ error: `HTTP ${response.statusCode}`, loading: false });
64
+ return;
65
+ }
66
+ const decoder = new TextDecoder();
67
+ const data = JSON.parse(decoder.decode(response.body));
68
+ this.setState({ data, loading: false });
69
+ },
70
+ error => {
71
+ this.setState({ error: (error as Error).message, loading: false });
72
+ },
73
+ );
74
+ };
75
+ ```
76
+
77
+ `HTTPResponse` shape: `{ statusCode: number, headers: StringMap<string>, body?: Uint8Array }`. Decode `body` with `TextDecoder` before parsing.
78
+
79
+ ## isDestroyed() guard
80
+
81
+ For callbacks that can't use CancelablePromise (e.g., native callbacks, timers):
82
+
83
+ ```tsx
84
+ // ✅ Guard against use-after-destroy
85
+ private onNativeCallback = (result: string) => {
86
+ if (this.isDestroyed()) return;
87
+ this.setState({ result });
88
+ };
89
+ ```
90
+
91
+ `isDestroyed()` is a method — always call with parentheses.
92
+
93
+ ## try/catch in async methods
94
+
95
+ ```tsx
96
+ import { promiseToCancelablePromise } from 'valdi_core/src/CancelablePromise';
97
+
98
+ // ✅ Catch errors from async operations
99
+ private loadProfile = () => {
100
+ const cancelable = promiseToCancelablePromise(
101
+ (async () => {
102
+ try {
103
+ const profile = await this.api.getProfile();
104
+ return { profile, error: undefined };
105
+ } catch (e) {
106
+ return { profile: undefined, error: (e as Error).message };
107
+ }
108
+ })(),
109
+ () => {},
110
+ );
111
+ this.registerDisposable(() => cancelable.cancel?.());
112
+
113
+ cancelable.then(result => {
114
+ this.setState({
115
+ profile: result.profile,
116
+ error: result.error,
117
+ loading: false,
118
+ });
119
+ });
120
+ };
121
+ ```
122
+
123
+ ## Error states in UI
124
+
125
+ ```tsx
126
+ // ✅ Show error state to the user
127
+ onRender(): void {
128
+ if (this.state.loading) {
129
+ <AnimationShimmer width="100%" height={200} />;
130
+ return;
131
+ }
132
+
133
+ if (this.state.error) {
134
+ <view alignItems="center" justifyContent="center" padding={16}>
135
+ <label value="Something went wrong" font={systemBoldFont(16)} />
136
+ <label value={this.state.error} color="#999" />
137
+ <CoreButton text="Retry" onTap={this.handleRetry} />
138
+ </view>;
139
+ return;
140
+ }
141
+
142
+ <label value={this.state.data.name} />;
143
+ }
144
+ ```
145
+
146
+ ## Defensive ViewModel access
147
+
148
+ ViewModels come from parent components and may have optional fields:
149
+
150
+ ```tsx
151
+ // ✅ Defensive access with defaults
152
+ onRender(): void {
153
+ const title = this.viewModel.title ?? 'Untitled';
154
+ const items = this.viewModel.items ?? [];
155
+
156
+ <view>
157
+ <label value={title} />
158
+ {items.forEach(item => { <label value={item.name} />; })}
159
+ </view>;
160
+ }
161
+ ```
162
+
163
+ ## Timer cleanup
164
+
165
+ ```tsx
166
+ // ✅ Use setTimeoutDisposable for automatic cleanup
167
+ onCreate() {
168
+ this.setTimeoutDisposable(this.tick, 1000);
169
+ }
170
+ ```
171
+
172
+ ```tsx
173
+ // ✅ Manual cleanup for setInterval
174
+ private timerId?: number;
175
+
176
+ onCreate() {
177
+ this.timerId = setInterval(this.tick, 1000);
178
+ }
179
+
180
+ onDestroy() {
181
+ if (this.timerId !== undefined) {
182
+ clearInterval(this.timerId);
183
+ }
184
+ }
185
+ ```
186
+
187
+ Or use `registerDisposable` with a disposable wrapper — see `valdi-async` skill.
188
+
189
+ ## Common mistakes
190
+
191
+ ```tsx
192
+ // ❌ WRONG — HTTPClient is not static
193
+ const data = await HTTPClient.send(request); // No static send() method
194
+
195
+ // ✅ Correct — instantiate then call methods
196
+ const client = new HTTPClient('https://api.example.com');
197
+ const cancelable = client.get('/data');
198
+
199
+ // ❌ WRONG — .catch() is not available on CancelablePromise
200
+ cancelable.catch(error => { ... }); // CancelablePromise only has .then()
201
+
202
+ // ✅ Correct — use second argument of .then() for error handling
203
+ cancelable.then(
204
+ response => { /* success */ },
205
+ error => { /* failure */ },
206
+ );
207
+
208
+ // ❌ WRONG — React error boundaries don't exist
209
+ <ErrorBoundary fallback={<Error />}> // Not a Valdi concept
210
+ <MyComponent />
211
+ </ErrorBoundary>
212
+
213
+ // ❌ WRONG — window.onerror / global error handlers
214
+ window.addEventListener('error', handler); // No window object
215
+
216
+ // ❌ WRONG — isDestroyed without parentheses
217
+ if (this.isDestroyed) return; // It's a method, not a property
218
+
219
+ // ✅ Correct
220
+ if (this.isDestroyed()) return;
221
+
222
+ // ❌ WRONG — Passing CancelablePromise directly to registerDisposable
223
+ this.registerDisposable(cancelable); // Wrong type
224
+
225
+ // ✅ Correct — wrap cancel in a callback
226
+ this.registerDisposable(() => cancelable.cancel?.());
227
+ ```
228
+
229
+ ## Summary
230
+
231
+ | Pattern | When to use |
232
+ |---------|------------|
233
+ | `promiseToCancelablePromise` + `registerDisposable` | Any async work in a component |
234
+ | `isDestroyed()` guard | Native callbacks, external event handlers |
235
+ | `try/catch` | Operations that can throw |
236
+ | Error state in UI | User-facing failure recovery |
237
+ | `onDestroy` cleanup | Timers, subscriptions, manual resources |
238
+ | `setTimeoutDisposable` | One-shot timers (auto-cleaned) |
@@ -0,0 +1,198 @@
1
+ # Valdi Gestures
2
+
3
+ Touch and gesture handling: tap, long press, drag, pinch, and rotate.
4
+
5
+ ## When to use
6
+
7
+ When handling user touch interactions beyond basic `onTap` — drag-to-reorder, pinch-to-zoom, long press menus, custom gesture recognition.
8
+
9
+ ## Key concepts
10
+
11
+ Valdi gesture handling is **attribute-based on `<view>` elements**. Each gesture type has three attributes:
12
+ - `on<Gesture>` — the callback
13
+ - `<gesture>Enabled` — boolean to enable/disable (default: true when callback is set)
14
+ - `on<Gesture>Predicate` — function returning boolean, controls whether the gesture should fire
15
+
16
+ The topmost visible element with a matching gesture wins. Conflicting gestures on parent elements are suppressed.
17
+
18
+ ## TouchEvent interface
19
+
20
+ All gesture callbacks receive a `TouchEvent` (or extension of it):
21
+
22
+ ```tsx
23
+ interface TouchEvent {
24
+ x: number; // X relative to the element
25
+ y: number; // Y relative to the element
26
+ absoluteX: number; // X relative to root Valdi view
27
+ absoluteY: number; // Y relative to root Valdi view
28
+ pointerCount: number;
29
+ pointerLocations: Pointer[];
30
+ }
31
+ ```
32
+
33
+ ## Basic gestures
34
+
35
+ ### onTap
36
+
37
+ ```tsx
38
+ // ✅ Simple tap handler
39
+ <view onTap={this.handleTap}>
40
+ <label value="Tap me" />
41
+ </view>
42
+
43
+ private handleTap = (event: TouchEvent) => {
44
+ console.log(`Tapped at ${event.x}, ${event.y}`);
45
+ };
46
+ ```
47
+
48
+ ### onDoubleTap
49
+
50
+ ```tsx
51
+ // ✅ Double tap to zoom
52
+ <view onDoubleTap={this.handleDoubleTap}>
53
+ <image src={this.viewModel.photo} />
54
+ </view>
55
+ ```
56
+
57
+ ### onLongPress
58
+
59
+ ```tsx
60
+ // ✅ Long press with custom duration
61
+ <view
62
+ onLongPress={this.handleLongPress}
63
+ longPressDuration={500} // milliseconds before trigger
64
+ >
65
+ <label value="Hold me" />
66
+ </view>
67
+ ```
68
+
69
+ ## Continuous gestures
70
+
71
+ ### onDrag
72
+
73
+ ```tsx
74
+ // ✅ Drag to move — fires continuously during the drag
75
+ <view onDrag={this.handleDrag}>
76
+ <label value="Drag me" />
77
+ </view>
78
+
79
+ private handleDrag = (event: DragEvent) => {
80
+ // event extends TouchEvent with drag-specific data
81
+ this.cardRef.setAttribute('translateX', event.x);
82
+ this.cardRef.setAttribute('translateY', event.y);
83
+ };
84
+ ```
85
+
86
+ ### onPinch
87
+
88
+ ```tsx
89
+ // ✅ Pinch to zoom — requires 2+ pointers
90
+ <view onPinch={this.handlePinch}>
91
+ <image src={this.viewModel.photo} ref={this.imageRef} />
92
+ </view>
93
+
94
+ private handlePinch = (event: PinchEvent) => {
95
+ this.imageRef.setAttribute('scale', event.scale);
96
+ };
97
+ ```
98
+
99
+ ### onRotate
100
+
101
+ ```tsx
102
+ // ✅ Rotate with two fingers — requires 2+ pointers
103
+ <view onRotate={this.handleRotate}>
104
+ <image src={this.viewModel.sticker} ref={this.stickerRef} />
105
+ </view>
106
+ ```
107
+
108
+ ## Simultaneous gestures
109
+
110
+ `onDrag`, `onPinch`, and `onRotate` can run simultaneously. This enables multitouch interactions like pinch-zoom-rotate on a photo:
111
+
112
+ ```tsx
113
+ // ✅ Combined pinch + drag + rotate on same element
114
+ <view
115
+ onDrag={this.handleDrag}
116
+ onPinch={this.handlePinch}
117
+ onRotate={this.handleRotate}
118
+ >
119
+ <image src={this.viewModel.photo} ref={this.photoRef} />
120
+ </view>
121
+ ```
122
+
123
+ ## Touch area extension
124
+
125
+ Expand the tappable area beyond the visible bounds:
126
+
127
+ ```tsx
128
+ // ✅ Small button with larger touch target
129
+ <view
130
+ onTap={this.handleTap}
131
+ touchAreaExtension={10} // extends hit area by 10pt in each direction
132
+ width={24} height={24}
133
+ >
134
+ <image src={SIGIcon.checkmarkFill} />
135
+ </view>
136
+ ```
137
+
138
+ ## Touch delay in scroll views
139
+
140
+ Inside a `<scroll>`, touches are delayed to avoid conflicts with scrolling:
141
+
142
+ ```tsx
143
+ // ✅ Delay touch recognition inside scrollable content
144
+ <view
145
+ onTouch={this.handleTouch}
146
+ onTouchDelayDuration={150} // ms before onTouch fires during scroll
147
+ />
148
+ ```
149
+
150
+ ## Gesture predicates
151
+
152
+ Control whether a gesture should activate:
153
+
154
+ ```tsx
155
+ // ✅ Only allow drag when in edit mode
156
+ <view
157
+ onDrag={this.handleDrag}
158
+ onDragPredicate={() => this.state.editMode}
159
+ />
160
+ ```
161
+
162
+ ## onTouch (raw)
163
+
164
+ Low-level touch events that fire on all elements in the hierarchy:
165
+
166
+ ```tsx
167
+ // ✅ Raw touch tracking — fires for all touch phases
168
+ <view onTouch={this.handleTouch}>
169
+ <label value="Touch me" />
170
+ </view>
171
+
172
+ private handleTouch = (event: TouchEvent) => {
173
+ // Fires on begin, move, end, cancel
174
+ };
175
+ ```
176
+
177
+ Unlike other gestures, `onTouch` propagates to parents/siblings — it doesn't suppress other handlers.
178
+
179
+ ## Common mistakes
180
+
181
+ ```tsx
182
+ // ❌ WRONG — React-style event handlers
183
+ <div onClick={handler} /> // ❌ No <div>, no onClick
184
+ <button onMouseDown={handler} /> // ❌ No mouse events
185
+
186
+ // ❌ WRONG — addEventListener
187
+ element.addEventListener('touchstart', handler); // ❌
188
+
189
+ // ❌ WRONG — Gesture on <layout> (use <view>)
190
+ <layout onTap={handler} /> // ❌ Gestures go on <view> elements
191
+
192
+ // ✅ Correct — gestures on <view>
193
+ <view onTap={handler}>
194
+ <layout>
195
+ <label value="Content" />
196
+ </layout>
197
+ </view>
198
+ ```
@@ -118,12 +118,30 @@ valdi inspect snapshot <elementId> <contextId>
118
118
  valdi inspect snapshot <elementId> <contextId> --output /tmp/my-snap.png
119
119
  ```
120
120
 
121
- Output: `{ path: "/tmp/valdi-snapshot-<elementId>.png" }`
121
+ Output: `{ path: "/var/folders/.../valdi-snapshot-<elementId>.png" }`
122
122
 
123
123
  The PNG is written to disk. Read it with the `Read` tool to view it visually.
124
124
 
125
125
  **Getting elementId**: Use `element.id` from the `tree` output (a number, e.g. `1`, `5`, `42`).
126
126
 
127
+ #### Using `--key` instead of numeric IDs (recommended)
128
+
129
+ Instead of looking up numeric element IDs from the tree, use the `--key` flag to resolve by component tag name or element `key` prop:
130
+
131
+ ```
132
+ valdi inspect snapshot --key PreviewRoot
133
+ valdi inspect snapshot --key weather-card --port 13591
134
+ ```
135
+
136
+ The `--key` flag searches the component tree for a matching tag name or `key` prop and resolves it to the element ID automatically.
137
+
138
+ **This is stable across hot-reloads** — element IDs change on every reload, but component names and `key` props stay the same. Use `--key` instead of numeric IDs to avoid re-querying the tree after each hot-reload cycle.
139
+
140
+ Custom keys can be set on any element in TSX:
141
+ ```tsx
142
+ <view key="weather-card" style={styles.card}>
143
+ ```
144
+
127
145
  ---
128
146
 
129
147
  ### `valdi inspect heap`
@@ -0,0 +1,142 @@
1
+ # Valdi Localization
2
+
3
+ Internationalization (i18n) and localized strings in Valdi modules.
4
+
5
+ ## When to use
6
+
7
+ When adding user-visible text that should be translatable across languages.
8
+
9
+ ## Key concepts
10
+
11
+ Valdi localization uses **JSON string files** (`strings-en.json`) compiled into type-safe TypeScript accessors. The compiler generates a `Strings.d.ts` file with typed functions for each key. On iOS, strings compile to `.strings` files; on Android, to XML string resources.
12
+
13
+ ## Setup
14
+
15
+ ### 1. Create the strings file
16
+
17
+ Create `strings/strings-en.json` in your module directory:
18
+
19
+ ```json
20
+ {
21
+ "hello_world": {
22
+ "defaultMessage": "Hello, world!"
23
+ },
24
+ "welcome_user": {
25
+ "defaultMessage": "Welcome, {name}!",
26
+ "example": "Welcome, Alex!"
27
+ },
28
+ "items_count": {
29
+ "defaultMessage": "{count%d} items remaining",
30
+ "example": "5 items remaining"
31
+ }
32
+ }
33
+ ```
34
+
35
+ ### 2. Add strings directory to module config
36
+
37
+ In your `module.yaml`:
38
+
39
+ ```yaml
40
+ strings_dir: strings
41
+ ```
42
+
43
+ ### 3. Generate typed accessors
44
+
45
+ ```bash
46
+ valdi projectsync
47
+ ```
48
+
49
+ This generates `Strings.d.ts` in your module with typed functions for each key.
50
+
51
+ ### 4. Use in TypeScript
52
+
53
+ ```tsx
54
+ import Strings from 'mymodule/src/Strings';
55
+
56
+ onRender(): void {
57
+ <view>
58
+ <label value={Strings.helloWorld()} />
59
+ <label value={Strings.welcomeUser('Alex')} />
60
+ <label value={Strings.itemsCount(5)} />
61
+ </view>;
62
+ }
63
+ ```
64
+
65
+ ## String keys and naming
66
+
67
+ Keys in `strings-en.json` are `snake_case`. The generated TypeScript accessors are `camelCase`:
68
+
69
+ | JSON key | TypeScript accessor |
70
+ |----------|-------------------|
71
+ | `hello_world` | `Strings.helloWorld()` |
72
+ | `items_count` | `Strings.itemsCount(n)` |
73
+ | `welcome_user` | `Strings.welcomeUser(name)` |
74
+
75
+ ## Template strings with variables
76
+
77
+ Variables use the format `{NAME%FORMAT}`:
78
+
79
+ ```json
80
+ {
81
+ "greeting": {
82
+ "defaultMessage": "Hi {name}, you have {count%d} new messages",
83
+ "example": "Hi Alex, you have 3 new messages"
84
+ }
85
+ }
86
+ ```
87
+
88
+ Supported formats:
89
+ - `{name}` or `{name%s}` — string (default)
90
+ - `{count%d}` — integer
91
+
92
+ Multiple variables must have unique names. Argument order in the TypeScript function matches the order they appear in the English string.
93
+
94
+ ```tsx
95
+ // ✅ Variables passed in order of appearance in defaultMessage
96
+ Strings.greeting('Alex', 3) // "Hi Alex, you have 3 new messages"
97
+ ```
98
+
99
+ ## Using strings in Kotlin (Android)
100
+
101
+ Generated strings are accessible as standard Android resources:
102
+
103
+ ```kotlin
104
+ val text = getResources().getString(
105
+ com.snap.valdi.modules.my_module.R.string.my_module_hello_world
106
+ )
107
+ ```
108
+
109
+ ## Common mistakes
110
+
111
+ ```tsx
112
+ // ❌ WRONG — Hardcoding user-visible strings
113
+ <label value="Hello, world!" />
114
+
115
+ // ✅ Correct — use localized strings
116
+ <label value={Strings.helloWorld()} />
117
+
118
+ // ❌ WRONG — Concatenating localized strings
119
+ const msg = Strings.hello() + " " + name; // ❌ Word order varies by language
120
+
121
+ // ✅ Correct — use template strings with variables
122
+ const msg = Strings.helloUser(name);
123
+
124
+ // ❌ WRONG — Constructing plurals in code
125
+ const msg = count === 1 ? "1 item" : `${count} items`; // ❌
126
+
127
+ // ✅ Correct — handle plurals in the string definition
128
+ // (Use a single template string; translation handles pluralization)
129
+
130
+ // ❌ WRONG — Importing from the wrong path
131
+ import Strings from 'Strings'; // ❌
132
+
133
+ // ✅ Correct — import from your module's generated path
134
+ import Strings from 'mymodule/src/Strings';
135
+ ```
136
+
137
+ ## Workflow
138
+
139
+ 1. Add keys to `strings/strings-en.json`
140
+ 2. Run `valdi projectsync` to regenerate `Strings.d.ts`
141
+ 3. Import `Strings` from your module and use the generated functions
142
+ 4. Valdi tooling handles iOS `.strings` and Android `.xml` generation during build