@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,199 @@
1
+ # valdi-inspect
2
+
3
+ Use this skill when you need to inspect a **live running Valdi app** — to see what components are on screen, traverse the rendered virtual node tree, capture element screenshots, or check JS heap usage.
4
+
5
+ ## When to use
6
+
7
+ - User asks "what's on screen?", "what component is rendering here?", "what contexts are active?"
8
+ - You need to diagnose a layout or rendering issue in a running app
9
+ - You want to verify a component tree change after a hot-reload
10
+ - User asks about memory usage or wants a JS heap dump
11
+
12
+ ## Prerequisites
13
+
14
+ The Valdi app must be **running on a connected device or emulator**. No hot-reloader required — the CLI connects directly to the app's DebuggerService.
15
+
16
+ **Port reference** — determined by how the app is built, not the OS:
17
+
18
+ | Target | Port | When |
19
+ |--------|------|------|
20
+ | iOS in-app (e.g. Snapchat) | **13592** (default) | `isStandalone = false` |
21
+ | Android in-app | **13592** (default) | `isStandalone = false` |
22
+ | macOS Valdi app | **13591** | `isStandalone = true` |
23
+ | Standalone runner / CLI runner | **13591** | `isStandalone = true` |
24
+
25
+ For **Android**, `adb forward` runs automatically. For **iOS simulator**, connect directly to `localhost`.
26
+
27
+ All commands output **JSON by default** (for AI parsing). Add `--pretty` for human-readable output.
28
+
29
+ ---
30
+
31
+ ## Commands
32
+
33
+ ### `valdi inspect status`
34
+
35
+ Check whether the Valdi daemon is reachable and how many devices are connected.
36
+
37
+ ```
38
+ valdi inspect status
39
+ valdi inspect status --pretty
40
+ ```
41
+
42
+ Output: `{ connected: bool, port: number, connectedDevices: number, portName: string }`
43
+
44
+ ---
45
+
46
+ ### `valdi inspect devices`
47
+
48
+ List all devices connected to the Valdi daemon.
49
+
50
+ ```
51
+ valdi inspect devices
52
+ valdi inspect devices --pretty
53
+ ```
54
+
55
+ Output: `[{ client_id, platform, application_id }, ...]`
56
+
57
+ Use `client_id` values with `--client` in other commands. If only one device is connected, other commands auto-select it.
58
+
59
+ ---
60
+
61
+ ### `valdi inspect select`
62
+
63
+ Interactively choose a device and save it to `~/.valdi-inspect.json`. Subsequent commands use this device without prompting.
64
+
65
+ ```
66
+ valdi inspect select
67
+ ```
68
+
69
+ ---
70
+
71
+ ### `valdi inspect contexts`
72
+
73
+ List all active root components (contexts) on the device. A **context** is one mounted Valdi component tree — typically one per screen or overlay.
74
+
75
+ ```
76
+ valdi inspect contexts
77
+ valdi inspect contexts --pretty
78
+ valdi inspect contexts --client <client_id>
79
+ ```
80
+
81
+ Output: `[{ id: string, rootComponentName: string }, ...]`
82
+
83
+ The `id` is the **contextId** used by `tree` and `snapshot`. If there is only one context, commands that take a contextId will auto-select it.
84
+
85
+ ---
86
+
87
+ ### `valdi inspect tree [contextId]`
88
+
89
+ Get the full rendered virtual node tree for a context. If `contextId` is omitted, auto-selects the single context or prompts when there are multiple.
90
+
91
+ ```
92
+ valdi inspect tree
93
+ valdi inspect tree <contextId>
94
+ valdi inspect tree <contextId> --pretty
95
+ valdi inspect tree <contextId> --max-depth <n>
96
+ ```
97
+
98
+ Output: a nested tree where each node has:
99
+ - `tag`: element type (e.g. `"view"`, `"label"`, `"image"`, or a component name)
100
+ - `key`: the Valdi TSX key assigned in source
101
+ - `element.id`: numeric element ID (use this for `snapshot`)
102
+ - `element.frame`: `{ x, y, width, height }` in screen coordinates
103
+ - `element.attributes`: rendered prop values (style, value, etc.)
104
+ - `children`: array of child nodes (same shape)
105
+ - `_childrenTrimmed`: count of trimmed children when `--max-depth` is used
106
+
107
+ **Tip**: Use `--max-depth 3` or `--max-depth 4` first to get a summary, then drill in.
108
+
109
+ ---
110
+
111
+ ### `valdi inspect snapshot <elementId> [contextId]`
112
+
113
+ Capture a screenshot of a specific element and save it as a PNG. If `contextId` is omitted, auto-selects or prompts.
114
+
115
+ ```
116
+ valdi inspect snapshot <elementId>
117
+ valdi inspect snapshot <elementId> <contextId>
118
+ valdi inspect snapshot <elementId> <contextId> --output /tmp/my-snap.png
119
+ ```
120
+
121
+ Output: `{ path: "/tmp/valdi-snapshot-<elementId>.png" }`
122
+
123
+ The PNG is written to disk. Read it with the `Read` tool to view it visually.
124
+
125
+ **Getting elementId**: Use `element.id` from the `tree` output (a number, e.g. `1`, `5`, `42`).
126
+
127
+ ---
128
+
129
+ ### `valdi inspect heap`
130
+
131
+ Dump JS heap statistics for the connected device.
132
+
133
+ ```
134
+ valdi inspect heap
135
+ valdi inspect heap --pretty
136
+ valdi inspect heap --gc
137
+ ```
138
+
139
+ Options:
140
+ - `--gc`: run garbage collection before dumping (more accurate free memory reading)
141
+
142
+ Output: `{ memoryUsageBytes: number, heapDumpJSON: string }`
143
+
144
+ `heapDumpJSON` is a serialized heap snapshot in V8 format. Note: heap dumps can crash small/toy apps — this works best on full production apps.
145
+
146
+ ---
147
+
148
+ ## Common workflows
149
+
150
+ ### "What is rendering on screen right now?"
151
+
152
+ ```
153
+ valdi inspect tree --pretty
154
+ ```
155
+
156
+ (contextId is auto-selected if there's only one)
157
+
158
+ ### "Show me what a specific component looks like"
159
+
160
+ 1. Run `valdi inspect tree --pretty` to find the node — note its `element.id`
161
+ 2. Run `valdi inspect snapshot <element.id>` to capture it
162
+ 3. Read the PNG with the `Read` tool
163
+
164
+ ### "Diagnose a layout issue at position X,Y"
165
+
166
+ Run `valdi inspect tree --pretty` and look for `element.frame` values overlapping with the target position.
167
+
168
+ ### "Check memory usage"
169
+
170
+ ```
171
+ valdi inspect heap --pretty
172
+ ```
173
+
174
+ ### "Verify a hot-reload applied correctly"
175
+
176
+ Run `valdi inspect tree` before and after the edit, compare the JSON output.
177
+
178
+ ---
179
+
180
+ ## Options reference
181
+
182
+ | Option | Commands | Description |
183
+ |--------|----------|-------------|
184
+ | `--port <n>` | all | Daemon TCP port (default: 13592 mobile, 13591 standalone) |
185
+ | `--client <id>` | contexts, tree, snapshot, heap | Target a specific connected device |
186
+ | `--pretty` | devices, status, contexts, tree, heap | Human-readable output |
187
+ | `--max-depth <n>` | tree | Trim tree to N levels deep |
188
+ | `--output <path>` | snapshot | Custom PNG output path |
189
+ | `--gc` | heap | GC before heap dump |
190
+
191
+ ---
192
+
193
+ ## Troubleshooting
194
+
195
+ **"Valdi daemon not running on port 13592"** — Make sure the app is running. macOS Valdi apps and standalone runners use port 13591: add `--port 13591`.
196
+
197
+ **"No devices connected"** — Make sure the Valdi app is running. For Android, ensure a device or emulator is connected via `adb`.
198
+
199
+ **"Timeout waiting for device response"** — The app may be frozen or the JS runtime may be busy. Try again after a moment.
@@ -22,9 +22,21 @@ my_module/
22
22
  ## BUILD.bazel Pattern
23
23
 
24
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.
25
28
  ts_project(
26
29
  name = "my_module_web",
27
- srcs = glob(["web/**/*.ts", "web/**/*.d.ts"]),
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
28
40
  tsconfig = "web/tsconfig.json",
29
41
  visibility = ["//visibility:public"],
30
42
  )
@@ -45,24 +57,50 @@ valdi_module(
45
57
 
46
58
  ## Web Polyglot Entry Pattern
47
59
 
48
- Web entry files export view factories that are auto-registered with the `WebViewClassRegistry` at bundle time. Export a `webPolyglotViews` record mapping class names to factory functions:
60
+ Web entry files export view factories that are auto-registered with the `WebViewClassRegistry` at bundle time. Use typed TypeScript with an `AttributeHandler` interface:
49
61
 
50
62
  ```typescript
51
- export const webPolyglotViews: Record<string, (container: HTMLElement) => void> = {
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> = {
52
86
  MyCustomViewClass: createMyViewFactory(),
53
87
  };
54
88
  ```
55
89
 
56
- Each key must match the `webClass` attribute used in `<custom-view webClass="MyCustomViewClass">`.
90
+ ### Web `tsconfig.json`
57
91
 
58
- A factory receives an `HTMLElement` container and populates it with DOM content:
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):
59
93
 
60
- ```typescript
61
- function createMyViewFactory(): (container: HTMLElement) => void {
62
- return (container: HTMLElement) => {
63
- const element = document.createElement('div');
64
- container.appendChild(element);
65
- };
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
+ }
66
104
  }
67
105
  ```
68
106
 
@@ -70,7 +108,8 @@ function createMyViewFactory(): (container: HTMLElement) => void {
70
108
  - Compiled by `tsc` via `ts_project`, **not** the Valdi compiler
71
109
  - Do **NOT** use Valdi imports (`valdi_core/`, `valdi_tsx/`) — web files run in the browser, not the Valdi runtime
72
110
  - Do **NOT** manually call `globalThis.moduleLoader.resolveRequire()` — build system handles registration
73
- - The `tsconfig.json` in `web/` should target `DOM` + `ES2020` with `module: "commonjs"`
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
74
113
 
75
114
  ## Canonical Example
76
115
 
@@ -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,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 = 'inspect <command>';
5
+ exports.describe = 'Inspect a running Valdi app — component trees, contexts, screenshots, heap';
6
+ const builder = (yargs) => {
7
+ return yargs
8
+ .commandDir('inspect_commands', { extensions: ['js', 'ts'] })
9
+ .demandCommand(1, 'Use devices, select, status, contexts, tree, snapshot, or heap')
10
+ .recommendCommands()
11
+ .wrap(yargs.terminalWidth())
12
+ .help();
13
+ };
14
+ exports.builder = builder;
15
+ const handler = () => { };
16
+ exports.handler = handler;
@@ -0,0 +1,55 @@
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 inspectContexts(argv) {
9
+ const port = argv.getArgument('port');
10
+ const clientOverride = argv.getArgument('client');
11
+ const pretty = argv.getArgument('pretty');
12
+ const conn = await (0, daemonClient_1.connectToDaemon)(port);
13
+ try {
14
+ await conn.configure();
15
+ const clientId = await (0, daemonClient_1.resolveClientId)(conn, clientOverride);
16
+ const contexts = await conn.listContexts(clientId);
17
+ if (pretty) {
18
+ if (contexts.length === 0) {
19
+ console.log((0, logUtils_1.wrapInColor)('No active contexts found.', constants_1.ANSI_COLORS.YELLOW_COLOR));
20
+ return;
21
+ }
22
+ console.log((0, logUtils_1.wrapInColor)(`${contexts.length} context(s) on device ${clientId}:\n`, constants_1.ANSI_COLORS.GRAY_COLOR));
23
+ for (const ctx of contexts) {
24
+ console.log(` ${(0, logUtils_1.wrapInColor)(ctx.id, constants_1.ANSI_COLORS.BLUE_COLOR)} ${ctx.rootComponentName}`);
25
+ }
26
+ }
27
+ else {
28
+ console.log(JSON.stringify(contexts));
29
+ }
30
+ }
31
+ finally {
32
+ conn.close();
33
+ }
34
+ }
35
+ exports.command = 'contexts';
36
+ exports.describe = 'List active Valdi root contexts (components) on the device';
37
+ const builder = (yargs) => {
38
+ yargs
39
+ .option('port', {
40
+ describe: 'Daemon TCP port',
41
+ type: 'number',
42
+ default: daemonClient_1.DEFAULT_PORT,
43
+ })
44
+ .option('client', {
45
+ describe: 'Client ID to target (from "valdi inspect devices")',
46
+ type: 'string',
47
+ })
48
+ .option('pretty', {
49
+ describe: 'Human-readable output instead of JSON',
50
+ type: 'boolean',
51
+ default: false,
52
+ });
53
+ };
54
+ exports.builder = builder;
55
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(inspectContexts);
@@ -0,0 +1,53 @@
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 inspectDevices(argv) {
9
+ const port = argv.getArgument('port');
10
+ const pretty = argv.getArgument('pretty');
11
+ const conn = await (0, daemonClient_1.connectToDaemon)(port);
12
+ try {
13
+ await conn.configure();
14
+ const clients = await conn.listConnectedClients();
15
+ if (pretty) {
16
+ if (clients.length === 0) {
17
+ console.log((0, logUtils_1.wrapInColor)('No devices connected to the Valdi daemon.', constants_1.ANSI_COLORS.YELLOW_COLOR));
18
+ return;
19
+ }
20
+ const nameWidth = 30;
21
+ const platWidth = 12;
22
+ console.log((0, logUtils_1.wrapInColor)(['CLIENT ID'.padEnd(36), 'PLATFORM'.padEnd(platWidth), 'APPLICATION ID'.padEnd(nameWidth)].join(' '), constants_1.ANSI_COLORS.GRAY_COLOR));
23
+ console.log((0, logUtils_1.wrapInColor)('-'.repeat(36 + platWidth + nameWidth + 4), constants_1.ANSI_COLORS.GRAY_COLOR));
24
+ for (const c of clients) {
25
+ console.log([c.client_id.padEnd(36), c.platform.padEnd(platWidth), c.application_id.padEnd(nameWidth)].join(' '));
26
+ }
27
+ console.log((0, logUtils_1.wrapInColor)(`\n${clients.length} device(s) connected`, constants_1.ANSI_COLORS.GRAY_COLOR));
28
+ }
29
+ else {
30
+ console.log(JSON.stringify(clients));
31
+ }
32
+ }
33
+ finally {
34
+ conn.close();
35
+ }
36
+ }
37
+ exports.command = 'devices';
38
+ exports.describe = 'List devices connected to the Valdi daemon';
39
+ const builder = (yargs) => {
40
+ yargs
41
+ .option('port', {
42
+ describe: 'Daemon TCP port',
43
+ type: 'number',
44
+ default: daemonClient_1.DEFAULT_PORT,
45
+ })
46
+ .option('pretty', {
47
+ describe: 'Human-readable output instead of JSON',
48
+ type: 'boolean',
49
+ default: false,
50
+ });
51
+ };
52
+ exports.builder = builder;
53
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(inspectDevices);
@@ -0,0 +1,59 @@
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 inspectHeap(argv) {
9
+ const gc = argv.getArgument('gc');
10
+ const port = argv.getArgument('port');
11
+ const clientOverride = argv.getArgument('client');
12
+ const pretty = argv.getArgument('pretty');
13
+ const conn = await (0, daemonClient_1.connectToDaemon)(port);
14
+ try {
15
+ await conn.configure();
16
+ const clientId = await (0, daemonClient_1.resolveClientId)(conn, clientOverride);
17
+ const result = await conn.dumpHeap(clientId, gc);
18
+ if (pretty) {
19
+ const heap = result;
20
+ if (heap?.memoryUsageBytes !== undefined) {
21
+ const mb = (heap.memoryUsageBytes / 1024 / 1024).toFixed(2);
22
+ console.log(`Memory usage: ${(0, logUtils_1.wrapInColor)(`${mb} MB`, constants_1.ANSI_COLORS.YELLOW_COLOR)} (${heap.memoryUsageBytes} bytes)`);
23
+ }
24
+ console.log(JSON.stringify(result, null, 2));
25
+ }
26
+ else {
27
+ console.log(JSON.stringify(result));
28
+ }
29
+ }
30
+ finally {
31
+ conn.close();
32
+ }
33
+ }
34
+ exports.command = 'heap';
35
+ exports.describe = 'Dump JS heap stats for the connected device';
36
+ const builder = (yargs) => {
37
+ yargs
38
+ .option('gc', {
39
+ describe: 'Run garbage collection before dumping heap',
40
+ type: 'boolean',
41
+ default: false,
42
+ })
43
+ .option('port', {
44
+ describe: 'Daemon TCP port',
45
+ type: 'number',
46
+ default: daemonClient_1.DEFAULT_PORT,
47
+ })
48
+ .option('client', {
49
+ describe: 'Client ID to target (from "valdi inspect devices")',
50
+ type: 'string',
51
+ })
52
+ .option('pretty', {
53
+ describe: 'Human-readable output instead of JSON',
54
+ type: 'boolean',
55
+ default: false,
56
+ });
57
+ };
58
+ exports.builder = builder;
59
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(inspectHeap);
@@ -0,0 +1,43 @@
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 cliUtils_1 = require("../../utils/cliUtils");
7
+ const errors_1 = require("../../core/errors");
8
+ const constants_1 = require("../../core/constants");
9
+ const logUtils_1 = require("../../utils/logUtils");
10
+ async function inspectSelect(argv) {
11
+ const port = argv.getArgument('port');
12
+ const conn = await (0, daemonClient_1.connectToDaemon)(port);
13
+ try {
14
+ await conn.configure();
15
+ const clients = await conn.listConnectedClients();
16
+ if (clients.length === 0) {
17
+ throw new errors_1.CliError('No devices connected to the Valdi daemon.');
18
+ }
19
+ const clientId = await (0, cliUtils_1.getUserChoice)(clients.map((c) => ({
20
+ name: `${c.application_id} (${c.platform}) [${c.client_id}]`,
21
+ value: c.client_id,
22
+ })), 'Select a device to use for inspect commands:');
23
+ const config = (0, daemonClient_1.loadInspectConfig)();
24
+ (0, daemonClient_1.saveInspectConfig)({ ...config, selectedClientId: clientId });
25
+ const chosen = clients.find((c) => c.client_id === clientId);
26
+ console.log(`Selected: ${(0, logUtils_1.wrapInColor)(chosen.application_id, constants_1.ANSI_COLORS.GREEN_COLOR)} (${chosen.platform})`);
27
+ console.log((0, logUtils_1.wrapInColor)(`Saved to ~/.valdi-inspect.json`, constants_1.ANSI_COLORS.GRAY_COLOR));
28
+ }
29
+ finally {
30
+ conn.close();
31
+ }
32
+ }
33
+ exports.command = 'select';
34
+ exports.describe = 'Interactively select a device and save it for subsequent inspect commands';
35
+ const builder = (yargs) => {
36
+ yargs.option('port', {
37
+ describe: 'Daemon TCP port',
38
+ type: 'number',
39
+ default: daemonClient_1.DEFAULT_PORT,
40
+ });
41
+ };
42
+ exports.builder = builder;
43
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(inspectSelect);