@snap/valdi 1.0.8 → 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 (64) hide show
  1. package/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
  2. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
  3. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
  4. package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
  5. package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
  6. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
  7. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  8. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
  9. package/.bootstrap/apps/ui_application/package.json +24 -0
  10. package/.bootstrap/modules/polyglot_bridge_module/BUILD.bazel.template +54 -0
  11. package/.bootstrap/modules/polyglot_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
  12. package/.bootstrap/modules/polyglot_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
  13. package/.bootstrap/modules/polyglot_bridge_module/src/Calculator.d.ts +4 -0
  14. package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
  15. package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
  16. package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
  17. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
  18. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
  19. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
  20. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
  21. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
  22. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
  23. package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
  24. package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
  25. package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
  26. package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
  27. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
  28. package/.metadata/.bazelrc.template +91 -0
  29. package/.metadata/.bazelversion.template +1 -0
  30. package/.metadata/.editorconfig.template +37 -0
  31. package/.metadata/.eslintrc.js.template +27 -0
  32. package/.metadata/.gitignore.template +4 -0
  33. package/.metadata/.prettierrc.json.template +7 -0
  34. package/.metadata/.watchmanconfig.template +8 -0
  35. package/.metadata/AGENTS.md.template +16 -0
  36. package/.metadata/README.md.template +31 -0
  37. package/.metadata/WORKSPACE.template +57 -0
  38. package/.metadata/config.yaml.template +1 -0
  39. package/.metadata/package.json.template +23 -0
  40. package/.metadata/skill-reference.tsx.template +8 -0
  41. package/.metadata/skill-tests-BUILD.bazel.template +21 -0
  42. package/.metadata/skill-tests-README.md.template +17 -0
  43. package/.metadata/skill.md.template +27 -0
  44. package/bundled-skills/registry.json +2 -1
  45. package/bundled-skills/skills/valdi-bazel/skill.md +21 -2
  46. package/bundled-skills/skills/valdi-custom-view/skill.md +6 -4
  47. package/bundled-skills/skills/valdi-inspect/skill.md +199 -0
  48. package/bundled-skills/skills/valdi-polyglot-module/skill.md +51 -12
  49. package/bundled-skills/skills/valdi-profile/skill.md +126 -0
  50. package/dist/commands/inspect.js +16 -0
  51. package/dist/commands/inspect_commands/contexts.js +55 -0
  52. package/dist/commands/inspect_commands/devices.js +53 -0
  53. package/dist/commands/inspect_commands/heap.js +59 -0
  54. package/dist/commands/inspect_commands/select.js +43 -0
  55. package/dist/commands/inspect_commands/snapshot.js +64 -0
  56. package/dist/commands/inspect_commands/status.js +68 -0
  57. package/dist/commands/inspect_commands/tree.js +86 -0
  58. package/dist/commands/profile.js +16 -0
  59. package/dist/commands/profile_commands/capture.js +106 -0
  60. package/dist/core/packageFiles.spec.js +29 -0
  61. package/dist/utils/daemonClient.js +342 -0
  62. package/dist/utils/hermesClient.js +252 -0
  63. package/dist/utils/stringUtils.spec.js +1 -1
  64. package/package.json +16 -6
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const os = tslib_1.__importStar(require("os"));
8
+ const errorUtils_1 = require("../../utils/errorUtils");
9
+ const daemonClient_1 = require("../../utils/daemonClient");
10
+ const constants_1 = require("../../core/constants");
11
+ const logUtils_1 = require("../../utils/logUtils");
12
+ async function inspectSnapshot(argv) {
13
+ const elementId = argv.getArgument('elementId');
14
+ const contextIdArg = argv.getArgument('contextId');
15
+ const port = argv.getArgument('port');
16
+ const clientOverride = argv.getArgument('client');
17
+ const outputOverride = argv.getArgument('output');
18
+ const conn = await (0, daemonClient_1.connectToDaemon)(port);
19
+ try {
20
+ await conn.configure();
21
+ const clientId = await (0, daemonClient_1.resolveClientId)(conn, clientOverride);
22
+ const contextId = await (0, daemonClient_1.resolveContextId)(conn, clientId, contextIdArg);
23
+ const base64Data = await conn.takeSnapshot(clientId, elementId, contextId);
24
+ const outPath = outputOverride
25
+ ? path.resolve(outputOverride)
26
+ : path.join(os.tmpdir(), `valdi-snapshot-${elementId}.png`);
27
+ fs.writeFileSync(outPath, Buffer.from(base64Data, 'base64'));
28
+ console.log(JSON.stringify({ path: outPath }));
29
+ console.error((0, logUtils_1.wrapInColor)(`Screenshot saved: ${outPath}`, constants_1.ANSI_COLORS.GREEN_COLOR));
30
+ }
31
+ finally {
32
+ conn.close();
33
+ }
34
+ }
35
+ exports.command = 'snapshot <elementId> [contextId]';
36
+ exports.describe = 'Capture a screenshot of an element and write it to a PNG file';
37
+ const builder = (yargs) => {
38
+ yargs
39
+ .positional('elementId', {
40
+ describe: 'Element ID to screenshot',
41
+ type: 'string',
42
+ demandOption: true,
43
+ })
44
+ .positional('contextId', {
45
+ describe: 'Context ID containing the element (omit to auto-select or be prompted)',
46
+ type: 'string',
47
+ })
48
+ .option('port', {
49
+ describe: 'Daemon TCP port',
50
+ type: 'number',
51
+ default: daemonClient_1.DEFAULT_PORT,
52
+ })
53
+ .option('client', {
54
+ describe: 'Client ID to target (from "valdi inspect devices")',
55
+ type: 'string',
56
+ })
57
+ .option('output', {
58
+ describe: 'Output PNG file path (defaults to /tmp/valdi-snapshot-<elementId>.png)',
59
+ type: 'string',
60
+ alias: 'o',
61
+ });
62
+ };
63
+ exports.builder = builder;
64
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(inspectSnapshot);
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ const errorUtils_1 = require("../../utils/errorUtils");
5
+ const daemonClient_1 = require("../../utils/daemonClient");
6
+ const constants_1 = require("../../core/constants");
7
+ const logUtils_1 = require("../../utils/logUtils");
8
+ async function inspectStatus(argv) {
9
+ const port = argv.getArgument('port');
10
+ const pretty = argv.getArgument('pretty');
11
+ let connected = false;
12
+ let clientCount = 0;
13
+ let error;
14
+ try {
15
+ const conn = await (0, daemonClient_1.connectToDaemon)(port);
16
+ try {
17
+ await conn.configure();
18
+ const clients = await conn.listConnectedClients();
19
+ connected = true;
20
+ clientCount = clients.length;
21
+ }
22
+ finally {
23
+ conn.close();
24
+ }
25
+ }
26
+ catch (err) {
27
+ error = err instanceof Error ? err.message : String(err);
28
+ }
29
+ const result = {
30
+ connected,
31
+ port,
32
+ connectedDevices: clientCount,
33
+ portName: port === daemonClient_1.MOBILE_PORT ? 'mobile' : port === daemonClient_1.STANDALONE_PORT ? 'standalone' : 'custom',
34
+ error: error ?? null,
35
+ };
36
+ if (pretty) {
37
+ const statusColor = connected ? constants_1.ANSI_COLORS.GREEN_COLOR : constants_1.ANSI_COLORS.RED_COLOR;
38
+ const statusLabel = connected ? '● connected' : '○ not connected';
39
+ console.log(`Daemon status: ${(0, logUtils_1.wrapInColor)(statusLabel, statusColor)}`);
40
+ console.log(`Port: ${(0, logUtils_1.wrapInColor)(String(port), constants_1.ANSI_COLORS.BLUE_COLOR)} (${result.portName})`);
41
+ if (connected) {
42
+ console.log(`Connected devices: ${(0, logUtils_1.wrapInColor)(String(clientCount), constants_1.ANSI_COLORS.GREEN_COLOR)}`);
43
+ }
44
+ if (error) {
45
+ console.log((0, logUtils_1.wrapInColor)(error, constants_1.ANSI_COLORS.RED_COLOR));
46
+ }
47
+ }
48
+ else {
49
+ console.log(JSON.stringify(result));
50
+ }
51
+ }
52
+ exports.command = 'status';
53
+ exports.describe = 'Check Valdi daemon connection status and connected device count';
54
+ const builder = (yargs) => {
55
+ yargs
56
+ .option('port', {
57
+ describe: 'Daemon TCP port',
58
+ type: 'number',
59
+ default: daemonClient_1.DEFAULT_PORT,
60
+ })
61
+ .option('pretty', {
62
+ describe: 'Human-readable output instead of JSON',
63
+ type: 'boolean',
64
+ default: false,
65
+ });
66
+ };
67
+ exports.builder = builder;
68
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(inspectStatus);
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ const errorUtils_1 = require("../../utils/errorUtils");
5
+ const daemonClient_1 = require("../../utils/daemonClient");
6
+ function trimDepth(node, depth) {
7
+ if (depth <= 0 || node === null || typeof node !== 'object')
8
+ return node;
9
+ const obj = node;
10
+ const result = {};
11
+ for (const key of Object.keys(obj)) {
12
+ if (key === 'children') {
13
+ const children = obj['children'];
14
+ if (depth === 1) {
15
+ const count = Array.isArray(children) ? children.length : 0;
16
+ if (count > 0)
17
+ result['_childrenTrimmed'] = count;
18
+ }
19
+ else if (Array.isArray(children)) {
20
+ result['children'] = children.map((c) => trimDepth(c, depth - 1));
21
+ }
22
+ else {
23
+ result['children'] = children;
24
+ }
25
+ }
26
+ else {
27
+ result[key] = obj[key];
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+ async function inspectTree(argv) {
33
+ const contextIdArg = argv.getArgument('contextId');
34
+ const port = argv.getArgument('port');
35
+ const clientOverride = argv.getArgument('client');
36
+ const pretty = argv.getArgument('pretty');
37
+ const maxDepth = argv.getArgument('maxDepth');
38
+ const conn = await (0, daemonClient_1.connectToDaemon)(port);
39
+ try {
40
+ await conn.configure();
41
+ const clientId = await (0, daemonClient_1.resolveClientId)(conn, clientOverride);
42
+ const contextId = await (0, daemonClient_1.resolveContextId)(conn, clientId, contextIdArg);
43
+ let tree = await conn.getContextTree(clientId, contextId);
44
+ if (maxDepth !== undefined) {
45
+ tree = trimDepth(tree, maxDepth);
46
+ }
47
+ if (pretty) {
48
+ console.log(JSON.stringify(tree, null, 2));
49
+ }
50
+ else {
51
+ console.log(JSON.stringify(tree));
52
+ }
53
+ }
54
+ finally {
55
+ conn.close();
56
+ }
57
+ }
58
+ exports.command = 'tree [contextId]';
59
+ exports.describe = 'Get the full rendered virtual node tree for a context';
60
+ const builder = (yargs) => {
61
+ yargs
62
+ .positional('contextId', {
63
+ describe: 'Context ID (omit to auto-select or be prompted)',
64
+ type: 'string',
65
+ })
66
+ .option('port', {
67
+ describe: 'Daemon TCP port',
68
+ type: 'number',
69
+ default: daemonClient_1.DEFAULT_PORT,
70
+ })
71
+ .option('client', {
72
+ describe: 'Client ID to target (from "valdi inspect devices")',
73
+ type: 'string',
74
+ })
75
+ .option('pretty', {
76
+ describe: 'Pretty-print JSON output',
77
+ type: 'boolean',
78
+ default: false,
79
+ })
80
+ .option('max-depth', {
81
+ describe: 'Trim the tree to this many levels deep (children beyond the limit are replaced with _childrenTrimmed count)',
82
+ type: 'number',
83
+ });
84
+ };
85
+ exports.builder = builder;
86
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(inspectTree);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ exports.command = 'profile <command>';
5
+ exports.describe = 'Capture a CPU profile from the Hermes JS runtime';
6
+ const builder = (yargs) => {
7
+ return yargs
8
+ .commandDir('profile_commands', { extensions: ['js', 'ts'] })
9
+ .demandCommand(1, 'Use: capture')
10
+ .recommendCommands()
11
+ .wrap(yargs.terminalWidth())
12
+ .help();
13
+ };
14
+ exports.builder = builder;
15
+ const handler = () => { };
16
+ exports.handler = handler;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const os = tslib_1.__importStar(require("os"));
8
+ const ora_1 = tslib_1.__importDefault(require("ora"));
9
+ const errorUtils_1 = require("../../utils/errorUtils");
10
+ const hermesClient_1 = require("../../utils/hermesClient");
11
+ const errors_1 = require("../../core/errors");
12
+ const cliUtils_1 = require("../../utils/cliUtils");
13
+ const constants_1 = require("../../core/constants");
14
+ const logUtils_1 = require("../../utils/logUtils");
15
+ async function profileCapture(argv) {
16
+ const duration = argv.getArgument('duration');
17
+ const outputOverride = argv.getArgument('output');
18
+ const port = argv.getArgument('port');
19
+ const contextOverride = argv.getArgument('context');
20
+ const devices = await (0, hermesClient_1.listHermesDevices)(port);
21
+ if (devices.length === 0) {
22
+ throw new errors_1.CliError('No debuggable JS contexts found. Make sure the Valdi app is running.');
23
+ }
24
+ let targetId;
25
+ if (contextOverride) {
26
+ if (!devices.some((d) => d.id === contextOverride)) {
27
+ throw new errors_1.CliError(`Context "${contextOverride}" not found.\n` +
28
+ `Available: ${devices.map((d) => d.id).join(', ')}`);
29
+ }
30
+ targetId = contextOverride;
31
+ }
32
+ else if (devices.length === 1) {
33
+ targetId = devices[0].id;
34
+ }
35
+ else {
36
+ targetId = await (0, cliUtils_1.getUserChoice)(devices.map((d) => ({ name: `${d.id} ${d.title}`, value: d.id })), 'Multiple JS contexts found. Select one:');
37
+ }
38
+ const conn = await hermesClient_1.HermesConnection.connect(port, targetId);
39
+ try {
40
+ await conn.startProfiling();
41
+ const startMs = Date.now();
42
+ const spinner = (0, ora_1.default)({ stream: process.stderr });
43
+ await new Promise((resolve) => {
44
+ let timer;
45
+ const stop = () => {
46
+ if (timer)
47
+ clearTimeout(timer);
48
+ process.off('SIGINT', stop);
49
+ process.exitCode = 0;
50
+ resolve();
51
+ };
52
+ if (duration !== undefined) {
53
+ spinner.start(`Profiling context "${targetId}"… (${duration}s)`);
54
+ timer = setTimeout(stop, duration * 1000);
55
+ }
56
+ else {
57
+ spinner.start(`Profiling context "${targetId}"… (Ctrl+C to stop)`);
58
+ }
59
+ process.once('SIGINT', stop);
60
+ });
61
+ spinner.text = 'Stopping profiler…';
62
+ const profile = await conn.stopProfiling();
63
+ spinner.stop();
64
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
65
+ const outPath = outputOverride
66
+ ? path.resolve(outputOverride)
67
+ : path.join(os.tmpdir(), `valdi-profile-${timestamp}.cpuprofile`);
68
+ fs.writeFileSync(outPath, JSON.stringify(profile), 'utf8');
69
+ const elapsedS = ((Date.now() - startMs) / 1000).toFixed(1);
70
+ const sampleCount = profile.samples?.length ?? 0;
71
+ const sizeKb = Math.round(fs.statSync(outPath).size / 1024);
72
+ console.log(JSON.stringify({ path: outPath }));
73
+ console.error((0, logUtils_1.wrapInColor)(`Profile saved: ${outPath}`, constants_1.ANSI_COLORS.GREEN_COLOR) + '\n' +
74
+ ` Duration: ${elapsedS}s | Samples: ${sampleCount} | Size: ${sizeKb} KB\n` +
75
+ ` Open in: Chrome DevTools → Performance → Load | speedscope.app`);
76
+ }
77
+ finally {
78
+ conn.close();
79
+ }
80
+ }
81
+ exports.command = 'capture';
82
+ exports.describe = 'Capture a CPU profile from the Hermes JS runtime';
83
+ const builder = (yargs) => {
84
+ yargs
85
+ .option('duration', {
86
+ describe: 'Profile for N seconds then stop automatically (omit to stop with Ctrl+C)',
87
+ type: 'number',
88
+ alias: 'd',
89
+ })
90
+ .option('output', {
91
+ describe: 'Output .cpuprofile file path (default: /tmp/valdi-profile-<timestamp>.cpuprofile)',
92
+ type: 'string',
93
+ alias: 'o',
94
+ })
95
+ .option('port', {
96
+ describe: 'Hermes debug socket port',
97
+ type: 'number',
98
+ default: hermesClient_1.HERMES_PORT,
99
+ })
100
+ .option('context', {
101
+ describe: 'JS context ID to profile (from /json/list); auto-selected if only one',
102
+ type: 'string',
103
+ });
104
+ };
105
+ exports.builder = builder;
106
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(profileCapture);
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ require("jasmine");
5
+ const child_process_1 = require("child_process");
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ describe('npm package contents', () => {
8
+ let packedFiles;
9
+ beforeAll(() => {
10
+ const cliRoot = path_1.default.join(__dirname, '../..');
11
+ packedFiles = (0, child_process_1.execSync)('npm pack --dry-run 2>&1', {
12
+ cwd: cliRoot,
13
+ encoding: 'utf-8',
14
+ });
15
+ });
16
+ it('includes .metadata templates for bootstrap config', () => {
17
+ expect(packedFiles).toContain('.metadata/config.yaml.template');
18
+ expect(packedFiles).toContain('.metadata/WORKSPACE.template');
19
+ });
20
+ it('includes .bootstrap templates for project scaffolding', () => {
21
+ expect(packedFiles).toContain('.bootstrap/');
22
+ });
23
+ it('includes dist output', () => {
24
+ expect(packedFiles).toContain('dist/');
25
+ });
26
+ it('includes bundled-skills', () => {
27
+ expect(packedFiles).toContain('bundled-skills/');
28
+ });
29
+ });