@snap/valdi 1.0.11 → 1.1.7

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 (74) hide show
  1. package/.metadata/.bazelrc.template +7 -6
  2. package/.metadata/MODULE.bazel.template +154 -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-compiler/skill.md +4 -4
  7. package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
  8. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
  9. package/bundled-skills/skills/valdi-custom-view/skill.md +43 -1
  10. package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
  11. package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
  12. package/bundled-skills/skills/valdi-inspect/skill.md +19 -1
  13. package/bundled-skills/skills/valdi-localization/skill.md +142 -0
  14. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
  15. package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
  16. package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
  17. package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
  18. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
  19. package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
  20. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
  21. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
  22. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
  23. package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
  24. package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
  25. package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
  26. package/bundled-skills/skills/valdi-overview/skill.md +7 -4
  27. package/bundled-skills/skills/valdi-perf/skill.md +223 -0
  28. package/bundled-skills/skills/valdi-polyglot-module/skill.md +80 -0
  29. package/bundled-skills/skills/valdi-preview/skill.md +303 -0
  30. package/bundled-skills/skills/valdi-setup/skill.md +55 -5
  31. package/bundled-skills/skills/valdi-testing/skill.md +23 -7
  32. package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
  33. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
  34. package/dist/commands/agentCheck.js +184 -0
  35. package/dist/commands/analyze.js +16 -0
  36. package/dist/commands/analyze_commands/duplicates.js +134 -0
  37. package/dist/commands/bootstrap.js +57 -73
  38. package/dist/commands/build.js +6 -0
  39. package/dist/commands/doctor.js +42 -266
  40. package/dist/commands/hotreload.js +15 -0
  41. package/dist/commands/inspect_commands/snapshot.js +71 -6
  42. package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
  43. package/dist/commands/install.js +6 -0
  44. package/dist/commands/preview.js +81 -0
  45. package/dist/commands/projectsync.js +9 -7
  46. package/dist/commands/skills_commands/install.js +6 -1
  47. package/dist/commands/skills_commands/update.js +2 -1
  48. package/dist/core/analyze/clusterer.js +150 -0
  49. package/dist/core/analyze/fingerprint.js +2 -0
  50. package/dist/core/analyze/knownPatterns.js +76 -0
  51. package/dist/core/analyze/parser.js +177 -0
  52. package/dist/core/analyze/reporter.js +83 -0
  53. package/dist/core/analyze/scanner.js +172 -0
  54. package/dist/core/analyze/similarity.js +56 -0
  55. package/dist/core/constants.js +6 -3
  56. package/dist/core/packageFiles.spec.js +1 -1
  57. package/dist/preview/previewGenerator.js +240 -0
  58. package/dist/preview/previewGenerator.spec.js +203 -0
  59. package/dist/preview/viewModelParser.js +86 -0
  60. package/dist/preview/viewModelParser.spec.js +171 -0
  61. package/dist/setup/DevSetupHelper.js +0 -54
  62. package/dist/setup/linuxSetup.js +0 -16
  63. package/dist/setup/macOSSetup.js +1 -5
  64. package/dist/utils/BazelClient.js +15 -0
  65. package/dist/utils/applicationUtils.js +15 -0
  66. package/dist/utils/daemonClient.js +3 -1
  67. package/dist/utils/linuxDistro.js +0 -21
  68. package/dist/utils/linuxDistro.spec.js +0 -48
  69. package/dist/utils/skillsAdapters.js +126 -19
  70. package/dist/utils/skillsAdapters.spec.js +141 -0
  71. package/dist/utils/skillsRegistry.js +8 -0
  72. package/package.json +16 -8
  73. package/.metadata/WORKSPACE.template +0 -57
  74. package/dist/setup/versions.js +0 -8
@@ -6,7 +6,6 @@ const fs = tslib_1.__importStar(require("fs"));
6
6
  const os = tslib_1.__importStar(require("os"));
7
7
  const path_1 = tslib_1.__importDefault(require("path"));
8
8
  const constants_1 = require("../core/constants");
9
- const versions_1 = require("../setup/versions");
10
9
  const BazelClient_1 = require("../utils/BazelClient");
11
10
  const cliUtils_1 = require("../utils/cliUtils");
12
11
  const errorUtils_1 = require("../utils/errorUtils");
@@ -48,9 +47,7 @@ class ValdiDoctor {
48
47
  }
49
48
  await this.checkEssentialPlatformTools();
50
49
  await this.checkJavaInstallation();
51
- this.checkAndroidSDKBasics();
52
50
  await this.checkCoreDependencies();
53
- await this.checkGitLfsInitialization();
54
51
  this.checkShellAutoComplete();
55
52
  await this.checkEditorExtensions();
56
53
  if (this.frameworkMode) {
@@ -281,23 +278,41 @@ class ValdiDoctor {
281
278
  }
282
279
  }
283
280
  async checkEssentialPlatformTools() {
284
- const androidHome = process.env['ANDROID_HOME'] || process.env['ANDROID_SDK_ROOT'];
285
- if (androidHome && fs.existsSync(androidHome)) {
286
- this.addResult({
287
- name: 'Android SDK',
288
- status: 'pass',
289
- message: `Android SDK found at ${androidHome}`,
290
- category: 'Android installation',
291
- });
281
+ this.addResult({
282
+ name: 'Android SDK',
283
+ status: 'pass',
284
+ message: 'Android SDK, NDK, and build tools are managed hermetically by Bazel',
285
+ details: 'See bzl/hermetic_android_sdk.bzl and bzl/hermetic_ndk.bzl',
286
+ category: 'Android installation',
287
+ });
288
+ if ((0, cliUtils_1.checkCommandExists)('adb')) {
289
+ try {
290
+ const { stdout } = await (0, cliUtils_1.runCliCommand)('adb --version');
291
+ const versionLine = stdout.split('\n')[0] || 'Unknown version';
292
+ this.addResult({
293
+ name: 'adb (Android Debug Bridge)',
294
+ status: 'pass',
295
+ message: `adb is installed: ${versionLine}`,
296
+ category: 'Android installation',
297
+ });
298
+ }
299
+ catch {
300
+ this.addResult({
301
+ name: 'adb (Android Debug Bridge)',
302
+ status: 'pass',
303
+ message: 'adb is installed',
304
+ category: 'Android installation',
305
+ });
306
+ }
292
307
  }
293
308
  else {
309
+ const fixCommand = this.getFixCommandForDependency('adb');
294
310
  this.addResult({
295
- name: 'Android SDK',
311
+ name: 'adb (Android Debug Bridge)',
296
312
  status: 'warn',
297
- message: 'Android SDK not found',
298
- details: 'Required for Android app development. Set ANDROID_HOME environment variable.',
313
+ message: 'adb is not installed — needed for device interaction (push, logcat, etc.)',
299
314
  fixable: true,
300
- fixCommand: 'Install Android Studio and set ANDROID_HOME',
315
+ fixCommand,
301
316
  category: 'Android installation',
302
317
  });
303
318
  }
@@ -516,86 +531,6 @@ class ValdiDoctor {
516
531
  }
517
532
  }
518
533
  }
519
- checkAndroidSDKBasics() {
520
- const androidHome = process.env['ANDROID_HOME'] || process.env['ANDROID_SDK_ROOT'];
521
- if (!androidHome || !fs.existsSync(androidHome)) {
522
- this.addResult({
523
- name: 'Android SDK Components',
524
- status: 'warn',
525
- message: 'Cannot check Android SDK components - ANDROID_HOME not set',
526
- details: 'Set ANDROID_HOME environment variable for Android development',
527
- fixable: true,
528
- fixCommand: 'Install Android Studio and set ANDROID_HOME',
529
- category: 'Android installation',
530
- });
531
- return;
532
- }
533
- const platformsDir = path_1.default.join(androidHome, 'platforms');
534
- if (fs.existsSync(platformsDir)) {
535
- const platforms = fs.readdirSync(platformsDir).filter(dir => dir.startsWith('android-'));
536
- if (platforms.length > 0) {
537
- this.addResult({
538
- name: 'Android Platform',
539
- status: 'pass',
540
- message: `Android Platform installed (${platforms.length} version${platforms.length > 1 ? 's' : ''})`,
541
- category: 'Android installation',
542
- });
543
- }
544
- else {
545
- this.addResult({
546
- name: 'Android Platform',
547
- status: 'warn',
548
- message: 'No Android Platform found',
549
- details: 'Install an Android Platform via Android Studio SDK Manager',
550
- fixable: true,
551
- fixCommand: 'Open Android Studio > SDK Manager > Install an Android Platform',
552
- category: 'Android installation',
553
- });
554
- }
555
- }
556
- else {
557
- this.addResult({
558
- name: 'Android Platform',
559
- status: 'warn',
560
- message: 'Android platforms directory not found',
561
- fixable: true,
562
- fixCommand: 'Install Android Studio and configure SDK',
563
- category: 'Android installation',
564
- });
565
- }
566
- const buildToolsDir = path_1.default.join(androidHome, 'build-tools');
567
- if (fs.existsSync(buildToolsDir)) {
568
- const buildTools = fs.readdirSync(buildToolsDir);
569
- if (buildTools.length > 0) {
570
- this.addResult({
571
- name: 'Android Build Tools',
572
- status: 'pass',
573
- message: `Android Build Tools installed (${buildTools.length} version${buildTools.length > 1 ? 's' : ''})`,
574
- category: 'Android installation',
575
- });
576
- }
577
- else {
578
- this.addResult({
579
- name: 'Android Build Tools',
580
- status: 'warn',
581
- message: 'No Android Build Tools found',
582
- fixable: true,
583
- fixCommand: 'Install Build Tools via Android Studio SDK Manager',
584
- category: 'Android installation',
585
- });
586
- }
587
- }
588
- else {
589
- this.addResult({
590
- name: 'Android Build Tools',
591
- status: 'warn',
592
- message: 'Build tools directory not found',
593
- fixable: true,
594
- fixCommand: 'Install Android Studio and configure SDK',
595
- category: 'Android installation',
596
- });
597
- }
598
- }
599
534
  async checkCoreDependencies() {
600
535
  const coreDeps = ['git', 'npm', 'watchman'];
601
536
  for (const dep of coreDeps) {
@@ -605,60 +540,6 @@ class ValdiDoctor {
605
540
  await this.checkSingleDependency('ios_webkit_debug_proxy', 'fail');
606
541
  }
607
542
  }
608
- async checkGitLfsInitialization() {
609
- if (!(0, cliUtils_1.checkCommandExists)('git-lfs')) {
610
- const fixCommand = this.getFixCommandForDependency('git-lfs');
611
- this.addResult({
612
- name: 'Git LFS',
613
- status: 'warn',
614
- message: 'git-lfs not installed',
615
- details: 'Required for working with large files in the repository',
616
- fixable: true,
617
- fixCommand,
618
- category: 'Development tools',
619
- });
620
- return;
621
- }
622
- try {
623
- const { stdout, returnCode } = await (0, cliUtils_1.runCliCommand)('git config --global --get filter.lfs.process');
624
- if (returnCode === 0 && stdout.trim()) {
625
- this.addResult({
626
- name: 'Git LFS initialization',
627
- status: 'pass',
628
- message: 'git-lfs is initialized',
629
- category: 'Development tools',
630
- });
631
- }
632
- else {
633
- this.addResult({
634
- name: 'Git LFS initialization',
635
- status: 'warn',
636
- message: 'git-lfs is installed but not initialized',
637
- details: 'Run git lfs install to configure Git LFS hooks',
638
- fixable: true,
639
- fixCommand: 'git lfs install',
640
- category: 'Development tools',
641
- });
642
- if (this.autoFix) {
643
- await this.attemptAutoFix('git-lfs', 'git lfs install');
644
- }
645
- }
646
- }
647
- catch {
648
- this.addResult({
649
- name: 'Git LFS initialization',
650
- status: 'warn',
651
- message: 'git-lfs is installed but not initialized',
652
- details: 'Run git lfs install to configure Git LFS hooks',
653
- fixable: true,
654
- fixCommand: 'git lfs install',
655
- category: 'Development tools',
656
- });
657
- if (this.autoFix) {
658
- await this.attemptAutoFix('git-lfs', 'git lfs install');
659
- }
660
- }
661
- }
662
543
  checkShellAutoComplete() {
663
544
  const homeDir = process.env['HOME'] ?? '';
664
545
  const shell = process.env['SHELL'] ?? '';
@@ -815,57 +696,20 @@ class ValdiDoctor {
815
696
  }
816
697
  }
817
698
  checkAdvancedAndroidSDK() {
818
- const androidHome = process.env['ANDROID_HOME'] || process.env['ANDROID_SDK_ROOT'];
819
- if (!androidHome || !fs.existsSync(androidHome)) {
820
- return;
821
- }
822
- const platformPath = path_1.default.join(androidHome, 'platforms', versions_1.ANDROID_PLATFORM_VERSION);
823
- if (fs.existsSync(platformPath)) {
824
- this.addResult({
825
- name: `Android Platform ${versions_1.ANDROID_PLATFORM_VERSION}`,
826
- status: 'pass',
827
- message: `Android Platform ${versions_1.ANDROID_PLATFORM_VERSION} installed`,
828
- category: 'Android installation',
829
- });
830
- }
831
- else {
832
- this.addResult({
833
- name: `Android Platform ${versions_1.ANDROID_PLATFORM_VERSION}`,
834
- status: 'warn',
835
- message: `Android Platform ${versions_1.ANDROID_PLATFORM_VERSION} not found`,
836
- details: 'Specific platform version for framework development',
837
- fixable: true,
838
- fixCommand: `sdkmanager --install 'platforms;${versions_1.ANDROID_PLATFORM_VERSION}'`,
839
- category: 'Android installation',
840
- });
841
- }
842
- const ndkPath = path_1.default.join(androidHome, 'ndk', versions_1.ANDROID_NDK_VERSION);
843
- if (fs.existsSync(ndkPath)) {
844
- this.addResult({
845
- name: 'Android NDK',
846
- status: 'pass',
847
- message: `Android NDK ${versions_1.ANDROID_NDK_VERSION} installed`,
848
- category: 'Android installation',
849
- });
850
- }
851
- else {
852
- this.addResult({
853
- name: 'Android NDK',
854
- status: 'warn',
855
- message: `Android NDK ${versions_1.ANDROID_NDK_VERSION} not found`,
856
- details: 'Required for native development in framework',
857
- fixable: true,
858
- fixCommand: `sdkmanager --install 'ndk;${versions_1.ANDROID_NDK_VERSION}'`,
859
- category: 'Android installation',
860
- });
861
- }
699
+ this.addResult({
700
+ name: 'Android SDK',
701
+ status: 'pass',
702
+ message: 'Android SDK, NDK, and build tools are managed hermetically by Bazel',
703
+ details: 'See bzl/hermetic_android_sdk.bzl and bzl/hermetic_ndk.bzl',
704
+ category: 'Android installation',
705
+ });
862
706
  }
863
707
  async checkSingleDependency(dep, failureLevel) {
864
708
  let category;
865
709
  if (['git', 'npm', 'watchman', 'ios_webkit_debug_proxy'].includes(dep)) {
866
710
  category = 'Development tools';
867
711
  }
868
- else if (['git-lfs', 'temurin'].includes(dep)) {
712
+ else if (['temurin'].includes(dep)) {
869
713
  category = 'Framework tools';
870
714
  }
871
715
  else {
@@ -907,71 +751,6 @@ class ValdiDoctor {
907
751
  }
908
752
  }
909
753
  checkEnvironmentVariables() {
910
- const androidHome = process.env['ANDROID_HOME'];
911
- if (androidHome && fs.existsSync(androidHome)) {
912
- this.addResult({
913
- name: 'ANDROID_HOME',
914
- status: 'pass',
915
- message: `ANDROID_HOME set to ${androidHome}`,
916
- category: 'Android installation',
917
- });
918
- }
919
- else {
920
- this.addResult({
921
- name: 'ANDROID_HOME',
922
- status: 'fail',
923
- message: 'ANDROID_HOME not set or invalid',
924
- details: 'dev_setup configures ANDROID_HOME for Android development',
925
- fixable: true,
926
- fixCommand: 'valdi dev_setup',
927
- category: 'Android installation',
928
- });
929
- }
930
- const androidNdkHome = process.env['ANDROID_NDK_HOME'];
931
- if (androidNdkHome && fs.existsSync(androidNdkHome)) {
932
- this.addResult({
933
- name: 'ANDROID_NDK_HOME',
934
- status: 'pass',
935
- message: `ANDROID_NDK_HOME set to ${androidNdkHome}`,
936
- category: 'Android installation',
937
- });
938
- }
939
- else {
940
- this.addResult({
941
- name: 'ANDROID_NDK_HOME',
942
- status: 'warn',
943
- message: 'ANDROID_NDK_HOME not set or invalid',
944
- details: 'dev_setup configures ANDROID_NDK_HOME for native development',
945
- fixable: true,
946
- fixCommand: 'valdi dev_setup',
947
- category: 'Android installation',
948
- });
949
- }
950
- const pathEnvAndroid = process.env['PATH'] || '';
951
- const androidHomeForPath = process.env['ANDROID_HOME'];
952
- if (androidHomeForPath) {
953
- const platformToolsInPath = pathEnvAndroid.includes(`${androidHomeForPath}/platform-tools`) ||
954
- pathEnvAndroid.includes('platform-tools');
955
- if (platformToolsInPath) {
956
- this.addResult({
957
- name: 'Android platform-tools PATH',
958
- status: 'pass',
959
- message: 'Android platform-tools in PATH',
960
- category: 'Android installation',
961
- });
962
- }
963
- else {
964
- this.addResult({
965
- name: 'Android platform-tools PATH',
966
- status: 'warn',
967
- message: 'Android platform-tools not in PATH',
968
- details: 'dev_setup adds platform-tools (containing adb) to PATH',
969
- fixable: true,
970
- fixCommand: 'export PATH="$ANDROID_HOME/platform-tools:$PATH"',
971
- category: 'Android installation',
972
- });
973
- }
974
- }
975
754
  const pathEnv = process.env['PATH'] || '';
976
755
  if (os.platform() === 'linux') {
977
756
  if (pathEnv.includes('/.valdi/bin')) {
@@ -1020,15 +799,15 @@ class ValdiDoctor {
1020
799
  case 'watchman': {
1021
800
  return 'brew install watchman';
1022
801
  }
1023
- case 'git-lfs': {
1024
- return 'brew install git-lfs';
1025
- }
1026
802
  case 'bazelisk': {
1027
803
  return 'brew install bazelisk';
1028
804
  }
1029
805
  case 'ios_webkit_debug_proxy': {
1030
806
  return 'brew install ios-webkit-debug-proxy';
1031
807
  }
808
+ case 'adb': {
809
+ return 'brew install android-platform-tools';
810
+ }
1032
811
  default: {
1033
812
  return `brew install ${dep}`;
1034
813
  }
@@ -1051,9 +830,6 @@ class ValdiDoctor {
1051
830
  }
1052
831
  return cmd;
1053
832
  }
1054
- case 'git-lfs': {
1055
- return (0, linuxDistro_1.buildInstallCommand)([(0, linuxDistro_1.getPackageName)(packageMappings['git-lfs'], this.linuxDistro)], this.linuxDistro);
1056
- }
1057
833
  case 'bazelisk': {
1058
834
  return 'valdi dev_setup';
1059
835
  }
@@ -1183,7 +959,7 @@ const builder = (yargs) => {
1183
959
  alias: 'j',
1184
960
  })
1185
961
  .option('framework', {
1186
- describe: 'Include framework development checks (git-lfs, temurin, etc.)',
962
+ describe: 'Include framework development checks (temurin, etc.)',
1187
963
  type: 'boolean',
1188
964
  default: false,
1189
965
  alias: 'F',
@@ -1,13 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ const child_process_1 = require("child_process");
4
5
  const constants_1 = require("../core/constants");
5
6
  const errors_1 = require("../core/errors");
6
7
  const BazelClient_1 = require("../utils/BazelClient");
7
8
  const cliUtils_1 = require("../utils/cliUtils");
8
9
  const errorUtils_1 = require("../utils/errorUtils");
9
10
  const logUtils_1 = require("../utils/logUtils");
11
+ function killExistingHotreloaders() {
12
+ const commands = [
13
+ 'pkill -f valdi_companion',
14
+ 'pkill -f run_hotreloader',
15
+ ];
16
+ for (const cmd of commands) {
17
+ try {
18
+ (0, child_process_1.execSync)(cmd, { stdio: 'ignore' });
19
+ }
20
+ catch {
21
+ }
22
+ }
23
+ }
10
24
  async function hotreloadResolvedTarget(client, resolvedTarget) {
25
+ killExistingHotreloaders();
11
26
  await client.buildTarget(resolvedTarget);
12
27
  const workspaceRoot = await client.getWorkspaceRoot();
13
28
  const buildOutputs = await client.queryBuildOutputs([resolvedTarget]);
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ exports.firstElementId = firstElementId;
5
+ exports.findElementByKey = findElementByKey;
4
6
  const tslib_1 = require("tslib");
5
7
  const fs = tslib_1.__importStar(require("fs"));
6
8
  const path = tslib_1.__importStar(require("path"));
@@ -9,21 +11,79 @@ const errorUtils_1 = require("../../utils/errorUtils");
9
11
  const daemonClient_1 = require("../../utils/daemonClient");
10
12
  const constants_1 = require("../../core/constants");
11
13
  const logUtils_1 = require("../../utils/logUtils");
14
+ function firstElementId(node) {
15
+ if (node === null || typeof node !== 'object')
16
+ return null;
17
+ const obj = node;
18
+ if (obj['element'] && typeof obj['element'] === 'object') {
19
+ const elem = obj['element'];
20
+ if (elem['id'] !== undefined)
21
+ return String(elem['id']);
22
+ }
23
+ const children = obj['children'];
24
+ if (Array.isArray(children)) {
25
+ for (const child of children) {
26
+ const found = firstElementId(child);
27
+ if (found)
28
+ return found;
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+ function findElementByKey(node, targetKey) {
34
+ if (node === null || typeof node !== 'object')
35
+ return null;
36
+ const obj = node;
37
+ if (obj['key'] === targetKey && obj['element'] && typeof obj['element'] === 'object') {
38
+ const elem = obj['element'];
39
+ if (elem['id'] !== undefined)
40
+ return String(elem['id']);
41
+ }
42
+ if (obj['tag'] === targetKey && obj['element'] && typeof obj['element'] === 'object') {
43
+ const elem = obj['element'];
44
+ if (elem['id'] !== undefined)
45
+ return String(elem['id']);
46
+ }
47
+ if (obj['tag'] === targetKey && obj['component'] !== undefined) {
48
+ return firstElementId(obj);
49
+ }
50
+ const children = obj['children'];
51
+ if (Array.isArray(children)) {
52
+ for (const child of children) {
53
+ const found = findElementByKey(child, targetKey);
54
+ if (found)
55
+ return found;
56
+ }
57
+ }
58
+ return null;
59
+ }
12
60
  async function inspectSnapshot(argv) {
13
- const elementId = argv.getArgument('elementId');
61
+ const elementIdArg = argv.getArgument('elementId');
14
62
  const contextIdArg = argv.getArgument('contextId');
15
63
  const port = argv.getArgument('port');
16
64
  const clientOverride = argv.getArgument('client');
17
65
  const outputOverride = argv.getArgument('output');
66
+ const keyOverride = argv.getArgument('key');
18
67
  const conn = await (0, daemonClient_1.connectToDaemon)(port);
19
68
  try {
20
69
  await conn.configure();
21
70
  const clientId = await (0, daemonClient_1.resolveClientId)(conn, clientOverride);
22
71
  const contextId = await (0, daemonClient_1.resolveContextId)(conn, clientId, contextIdArg);
72
+ let elementId = elementIdArg;
73
+ if (keyOverride) {
74
+ const tree = await conn.getContextTree(clientId, contextId);
75
+ const found = findElementByKey(tree, keyOverride);
76
+ if (!found) {
77
+ throw new Error(`No element found with key "${keyOverride}". Use "valdi inspect tree" to see available keys.`);
78
+ }
79
+ elementId = found;
80
+ console.error((0, logUtils_1.wrapInColor)(`Resolved key "${keyOverride}" to element ID ${elementId}`, constants_1.ANSI_COLORS.GREEN_COLOR));
81
+ }
23
82
  const base64Data = await conn.takeSnapshot(clientId, elementId, contextId);
83
+ const snapshotName = keyOverride || elementId;
24
84
  const outPath = outputOverride
25
85
  ? path.resolve(outputOverride)
26
- : path.join(os.tmpdir(), `valdi-snapshot-${elementId}.png`);
86
+ : path.join(os.tmpdir(), `valdi-snapshot-${snapshotName}.png`);
27
87
  fs.writeFileSync(outPath, Buffer.from(base64Data, 'base64'));
28
88
  console.log(JSON.stringify({ path: outPath }));
29
89
  console.error((0, logUtils_1.wrapInColor)(`Screenshot saved: ${outPath}`, constants_1.ANSI_COLORS.GREEN_COLOR));
@@ -32,18 +92,23 @@ async function inspectSnapshot(argv) {
32
92
  conn.close();
33
93
  }
34
94
  }
35
- exports.command = 'snapshot <elementId> [contextId]';
36
- exports.describe = 'Capture a screenshot of an element and write it to a PNG file';
95
+ exports.command = 'snapshot [elementId] [contextId]';
96
+ exports.describe = 'Capture a screenshot of an element by ID or --key';
37
97
  const builder = (yargs) => {
38
98
  yargs
39
99
  .positional('elementId', {
40
- describe: 'Element ID to screenshot',
100
+ describe: 'Element ID to screenshot (not needed when using --key)',
41
101
  type: 'string',
42
- demandOption: true,
102
+ default: '0',
43
103
  })
44
104
  .positional('contextId', {
45
105
  describe: 'Context ID containing the element (omit to auto-select or be prompted)',
46
106
  type: 'string',
107
+ })
108
+ .option('key', {
109
+ describe: 'Find element by key or tag name in the tree (stable across hot-reloads)',
110
+ type: 'string',
111
+ alias: 'k',
47
112
  })
48
113
  .option('port', {
49
114
  describe: 'Daemon TCP port',
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("jasmine");
4
+ const snapshot_1 = require("./snapshot");
5
+ describe('snapshot tree helpers', () => {
6
+ describe('firstElementId', () => {
7
+ it('returns null for null/non-object input', () => {
8
+ expect((0, snapshot_1.firstElementId)(null)).toBeNull();
9
+ expect((0, snapshot_1.firstElementId)(undefined)).toBeNull();
10
+ expect((0, snapshot_1.firstElementId)(42)).toBeNull();
11
+ expect((0, snapshot_1.firstElementId)('string')).toBeNull();
12
+ });
13
+ it('returns the element id from a direct element node', () => {
14
+ const node = { element: { id: 5 } };
15
+ expect((0, snapshot_1.firstElementId)(node)).toBe('5');
16
+ });
17
+ it('returns the first element id from nested children', () => {
18
+ const node = {
19
+ children: [
20
+ { tag: 'view' },
21
+ { children: [{ element: { id: 42 } }] },
22
+ ],
23
+ };
24
+ expect((0, snapshot_1.firstElementId)(node)).toBe('42');
25
+ });
26
+ it('returns null when no element is found', () => {
27
+ const node = { children: [{ tag: 'view' }, { tag: 'label' }] };
28
+ expect((0, snapshot_1.firstElementId)(node)).toBeNull();
29
+ });
30
+ it('handles element id of 0', () => {
31
+ const node = { element: { id: 0 } };
32
+ expect((0, snapshot_1.firstElementId)(node)).toBe('0');
33
+ });
34
+ });
35
+ describe('findElementByKey', () => {
36
+ it('finds element by explicit key', () => {
37
+ const tree = {
38
+ children: [
39
+ { key: 'header', element: { id: 10 } },
40
+ { key: 'body', element: { id: 20 } },
41
+ ],
42
+ };
43
+ expect((0, snapshot_1.findElementByKey)(tree, 'header')).toBe('10');
44
+ expect((0, snapshot_1.findElementByKey)(tree, 'body')).toBe('20');
45
+ });
46
+ it('finds element by tag name', () => {
47
+ const tree = {
48
+ children: [
49
+ { tag: 'ChatFriendsList', element: { id: 15 } },
50
+ ],
51
+ };
52
+ expect((0, snapshot_1.findElementByKey)(tree, 'ChatFriendsList')).toBe('15');
53
+ });
54
+ it('finds component node by tag and returns first child element id', () => {
55
+ const tree = {
56
+ children: [
57
+ {
58
+ tag: 'MyComponent',
59
+ component: 'MyComponent',
60
+ children: [
61
+ { element: { id: 99 } },
62
+ ],
63
+ },
64
+ ],
65
+ };
66
+ expect((0, snapshot_1.findElementByKey)(tree, 'MyComponent')).toBe('99');
67
+ });
68
+ it('searches deeply nested trees', () => {
69
+ const tree = {
70
+ children: [
71
+ {
72
+ children: [
73
+ {
74
+ children: [
75
+ { key: 'deep-key', element: { id: 77 } },
76
+ ],
77
+ },
78
+ ],
79
+ },
80
+ ],
81
+ };
82
+ expect((0, snapshot_1.findElementByKey)(tree, 'deep-key')).toBe('77');
83
+ });
84
+ it('returns null when key is not found', () => {
85
+ const tree = {
86
+ children: [
87
+ { key: 'exists', element: { id: 1 } },
88
+ ],
89
+ };
90
+ expect((0, snapshot_1.findElementByKey)(tree, 'nonexistent')).toBeNull();
91
+ });
92
+ it('returns null for null input', () => {
93
+ expect((0, snapshot_1.findElementByKey)(null, 'anything')).toBeNull();
94
+ });
95
+ it('prefers key match over tag match', () => {
96
+ const tree = {
97
+ children: [
98
+ { key: 'my-key', tag: 'SomeTag', element: { id: 1 } },
99
+ { key: 'other', tag: 'my-key', element: { id: 2 } },
100
+ ],
101
+ };
102
+ expect((0, snapshot_1.findElementByKey)(tree, 'my-key')).toBe('1');
103
+ });
104
+ });
105
+ });
@@ -36,6 +36,12 @@ async function valdiInstall(argv) {
36
36
  await bazel.runTarget(buildInfo.application, buildInfo.bazelArgs);
37
37
  break;
38
38
  }
39
+ case constants_1.PLATFORM.LINUX: {
40
+ (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
41
+ console.log('Running Linux application...');
42
+ await bazel.runTarget(buildInfo.application, buildInfo.bazelArgs);
43
+ break;
44
+ }
39
45
  case constants_1.PLATFORM.CLI: {
40
46
  (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
41
47
  console.log('Running CLI application...');