@snap/valdi 1.1.7 → 1.2.0

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 +8 -2
  2. package/.metadata/MODULE.bazel.template +20 -3
  3. package/.metadata/bzl/patches/rules_python/1.9.0/BUILD.bazel.template +1 -0
  4. package/.metadata/bzl/patches/rules_python/1.9.0/remove_setuptools_spaces.patch.template +96 -0
  5. package/README.md +35 -1
  6. package/bundled-skills/registry.json +2 -1
  7. package/bundled-skills/skills/valdi-animations/skill.md +49 -0
  8. package/bundled-skills/skills/valdi-async/skill.md +3 -2
  9. package/bundled-skills/skills/valdi-bazel/skill.md +2 -6
  10. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +18 -0
  11. package/bundled-skills/skills/valdi-error-handling/skill.md +1 -1
  12. package/bundled-skills/skills/valdi-gestures/skill.md +3 -3
  13. package/bundled-skills/skills/valdi-migrate/skill.md +2 -1
  14. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +4 -4
  15. package/bundled-skills/skills/valdi-mock-to-module/skill.md +9 -6
  16. package/bundled-skills/skills/valdi-overview/skill.md +2 -1
  17. package/bundled-skills/skills/valdi-perf/skill.md +121 -5
  18. package/bundled-skills/skills/valdi-pr-review/skill.md +189 -0
  19. package/bundled-skills/skills/valdi-profile/skill.md +5 -3
  20. package/bundled-skills/skills/valdi-setup/skill.md +3 -6
  21. package/bundled-skills/skills/valdi-testing/skill.md +1 -1
  22. package/bundled-skills/skills/valdi-tsx/skill.md +47 -11
  23. package/debugger/README.md +356 -0
  24. package/debugger/debugger-actions.js +373 -0
  25. package/debugger/debugger-api.js +225 -0
  26. package/debugger/debugger-bootstrap.js +295 -0
  27. package/debugger/debugger-model.js +790 -0
  28. package/debugger/debugger-performance.js +573 -0
  29. package/debugger/debugger-preview-html.js +676 -0
  30. package/debugger/debugger-providers.js +389 -0
  31. package/debugger/debugger-render.js +529 -0
  32. package/debugger/debugger-runtime.js +387 -0
  33. package/debugger/debugger-session.js +188 -0
  34. package/debugger/debugger-settings.js +209 -0
  35. package/debugger/debugger-state.js +221 -0
  36. package/debugger/debugger-tree-model.js +539 -0
  37. package/debugger/debugger.css +1865 -0
  38. package/debugger/devtools-panel.css +1318 -0
  39. package/debugger/devtools-panel.html +273 -0
  40. package/debugger/devtools-panel.js +3329 -0
  41. package/debugger/index.html +279 -0
  42. package/dist/commands/bootstrap.js +6 -5
  43. package/dist/commands/debugger.js +163 -0
  44. package/dist/commands/doctor.js +3 -62
  45. package/dist/commands/inspect.js +5 -2
  46. package/dist/commands/inspect_commands/input.js +176 -0
  47. package/dist/commands/inspect_commands/snapshot.js +1 -1
  48. package/dist/commands/inspect_commands/tree.js +1 -1
  49. package/dist/commands/projectsync.js +15 -0
  50. package/dist/commands/webHotreload.js +31 -0
  51. package/dist/core/constants.js +22 -6
  52. package/dist/debugger/chromiumConsole.js +279 -0
  53. package/dist/debugger/inputClient.js +473 -0
  54. package/dist/debugger/server.js +3801 -0
  55. package/dist/debugger/targetRegistry.js +436 -0
  56. package/dist/debugger/webPreviewPerformance.js +864 -0
  57. package/dist/index.js +0 -0
  58. package/dist/utils/BazelClient.js +34 -5
  59. package/dist/utils/applicationUtils.js +3 -0
  60. package/dist/utils/chromiumDevToolsClient.js +350 -0
  61. package/dist/utils/daemonClient.js +364 -44
  62. package/dist/utils/hermesClient.js +82 -176
  63. package/dist/utils/loopbackHost.js +14 -0
  64. package/dist/utils/owlCdpClient.js +282 -0
  65. package/dist/utils/owlDevToolsExtension.js +142 -0
  66. package/dist/utils/stringUtils.js +13 -1
  67. package/package.json +4 -2
  68. package/dist/commands/inspect_commands/snapshot.spec.js +0 -105
  69. package/dist/core/packageFiles.spec.js +0 -29
  70. package/dist/preview/previewGenerator.spec.js +0 -203
  71. package/dist/preview/viewModelParser.spec.js +0 -171
  72. package/dist/utils/linuxDistro.spec.js +0 -122
  73. package/dist/utils/skillsAdapters.spec.js +0 -141
  74. package/dist/utils/stringUtils.spec.js +0 -81
@@ -0,0 +1,387 @@
1
+ // Runtime logs, daemon target refresh, snapshots, heap, exports, and preview copy.
2
+ function renderLogs() {
3
+ const search = elements.logSearch.value.trim().toLowerCase();
4
+ const rows = state.snapshot.logs
5
+ .filter(log => !search || `${log.level} ${log.source} ${log.message}`.toLowerCase().includes(search))
6
+ .map(
7
+ log => `
8
+ <div class="log-row">
9
+ <span>${escapeHtml(log.time)}</span>
10
+ <span class="level-${escapeHtml(log.level)}">${escapeHtml(log.level.toUpperCase())}</span>
11
+ <span>[${escapeHtml(log.source)}] ${escapeHtml(log.message)}</span>
12
+ </div>
13
+ `,
14
+ )
15
+ .join('');
16
+ elements.logs.innerHTML = rows || `<div class="empty">No logs match the current filter.</div>`;
17
+ }
18
+
19
+ function trimRuntimeLogs() {
20
+ if (state.snapshot.logs.length <= MAX_RUNTIME_LOG_ROWS) return;
21
+ state.snapshot.logs = state.snapshot.logs.slice(-MAX_RUNTIME_LOG_ROWS);
22
+ }
23
+
24
+ function addLog(level, source, message) {
25
+ const now = new Date();
26
+ const time = now.toTimeString().slice(0, 8);
27
+ state.snapshot.logs.push({ time, level, source, message });
28
+ trimRuntimeLogs();
29
+ if (state.activeSection === 'logs') {
30
+ renderLogs();
31
+ elements.logs.scrollTop = elements.logs.scrollHeight;
32
+ }
33
+ }
34
+
35
+ function appendRuntimeLogs(logs) {
36
+ let added = 0;
37
+ for (const log of logs || []) {
38
+ const normalized = {
39
+ time: log.time || '',
40
+ level: log.level || 'info',
41
+ source: log.source || 'valdi',
42
+ message: log.message || '',
43
+ };
44
+ state.snapshot.logs.push(normalized);
45
+ added++;
46
+ }
47
+ if (added > 0) {
48
+ trimRuntimeLogs();
49
+ if (state.activeSection === 'logs') {
50
+ renderLogs();
51
+ elements.logs.scrollTop = elements.logs.scrollHeight;
52
+ }
53
+ }
54
+ return added;
55
+ }
56
+
57
+ function runtimeLogParams() {
58
+ const target = state.snapshot.target || {};
59
+ const params = new URLSearchParams();
60
+ params.set('limit', '120');
61
+ if (target.applicationId) params.set('applicationId', target.applicationId);
62
+ if (target.platform) params.set('platform', target.platform);
63
+ return params;
64
+ }
65
+
66
+ function stopRuntimeLogStream() {
67
+ if (state.runtimeLogStream) {
68
+ state.runtimeLogStream.close();
69
+ state.runtimeLogStream = null;
70
+ }
71
+ state.runtimeLogStreamKey = null;
72
+ }
73
+
74
+ function startRuntimeLogStream(options = {}) {
75
+ if (state.source !== 'daemon' || !isDebuggerAttached()) {
76
+ stopRuntimeLogStream();
77
+ return;
78
+ }
79
+
80
+ const params = runtimeLogParams();
81
+ const key = params.toString();
82
+ if (state.runtimeLogStream && state.runtimeLogStreamKey === key) return;
83
+
84
+ stopRuntimeLogStream();
85
+ const source = new EventSource(debuggerEventSourceUrl(`/api/runtime-logs/stream?${key}`));
86
+ state.runtimeLogStream = source;
87
+ state.runtimeLogStreamKey = key;
88
+
89
+ source.addEventListener('meta', event => {
90
+ const payload = JSON.parse(event.data);
91
+ state.runtimeLogPath = payload.logFile || null;
92
+ if (!options.silent) {
93
+ addLog(
94
+ 'info',
95
+ 'logs',
96
+ payload.logFile
97
+ ? `Streaming runtime logs from ${payload.logFile}.`
98
+ : 'Runtime log stream is waiting for a Valdi log file.',
99
+ );
100
+ }
101
+ });
102
+
103
+ source.addEventListener('logs', event => {
104
+ const payload = JSON.parse(event.data);
105
+ appendRuntimeLogs(payload.logs || []);
106
+ });
107
+
108
+ source.addEventListener('stream-error', event => {
109
+ const payload = JSON.parse(event.data);
110
+ addLog('error', 'logs', payload.error || 'Runtime log stream failed.');
111
+ });
112
+
113
+ source.addEventListener('error', () => {
114
+ if (state.runtimeLogStream === source) {
115
+ state.runtimeLogPath = null;
116
+ }
117
+ });
118
+ }
119
+
120
+ async function refreshTargets(options = {}) {
121
+ try {
122
+ if (!options.silent) addLog('info', 'daemon', 'Refreshing Valdi daemon targets.');
123
+ const status = await apiGet('/api/status');
124
+ state.lastStatus = status;
125
+ const targets = [];
126
+
127
+ for (const portStatus of status.ports) {
128
+ for (const client of portStatus.clients || []) {
129
+ for (const context of client.contexts || []) {
130
+ targets.push({
131
+ id: `${portStatus.port}:${client.client_id}:${context.id}`,
132
+ name: context.rootComponentName || client.application_id || `Client ${client.client_id}`,
133
+ platform: client.platform || portStatus.portName,
134
+ state: 'available',
135
+ transport: `daemon:${portStatus.port}`,
136
+ port: portStatus.port,
137
+ proxyPort: portStatus.port,
138
+ clientId: client.client_id,
139
+ contextId: context.id,
140
+ applicationId: client.application_id,
141
+ });
142
+ }
143
+ }
144
+ }
145
+
146
+ if (targets.length) {
147
+ const previousTargetId = state.snapshot.target?.id || null;
148
+ const selectedTarget = chooseLiveTarget(targets);
149
+ const targetChanged = selectedTarget.id !== previousTargetId;
150
+ if (targetChanged && !(await preparePerformanceTraceTargetSwitch(selectedTarget))) {
151
+ return;
152
+ }
153
+ state.snapshot.targets = markSelectedTarget(targets, selectedTarget);
154
+ state.snapshot.target = {
155
+ ...state.snapshot.target,
156
+ ...selectedTarget,
157
+ };
158
+ elements.portSelect.value = String(selectedTarget.port);
159
+ state.attached = false;
160
+ state.rootSnapshotImage = null;
161
+ state.rootSnapshotRequestId++;
162
+ state.lastError = null;
163
+ if (!options.silent)
164
+ addLog('info', 'daemon', `Found ${targets.length} Valdi context(s); selected ${selectedTarget.name}.`);
165
+ if (!state.manualDetach && options.autoAttach !== false) {
166
+ if (options.skipSnapshotIfSame && !targetChanged) {
167
+ render();
168
+ return;
169
+ }
170
+ await loadRealSnapshot(selectedTarget, {
171
+ silent: options.silent,
172
+ preserveSelection: state.source === 'daemon' && !targetChanged,
173
+ queueIfBusy: options.queueIfBusy === true,
174
+ });
175
+ return;
176
+ }
177
+ } else {
178
+ const errors = status.ports
179
+ .map(portStatus => `${portStatus.port}: ${portStatus.error || 'no contexts'}`)
180
+ .join('; ');
181
+ state.lastError = errors;
182
+ state.snapshot.targets = [];
183
+ state.attached = false;
184
+ state.source = 'empty';
185
+ state.rootSnapshotImage = null;
186
+ state.rootSnapshotRequestId++;
187
+ if (!options.silent) addLog('warn', 'daemon', `No live Valdi contexts found. ${errors}`);
188
+ }
189
+ render();
190
+ } catch (error) {
191
+ state.lastError = error.message;
192
+ if (!options.silent) addLog('error', 'daemon', error.message);
193
+ renderHeader();
194
+ }
195
+ }
196
+
197
+ async function loadRealSnapshot(target, options = {}) {
198
+ if (state.refreshInFlight) {
199
+ // A fetch is already running. apiGet aborts on its own timeout and the finally block below
200
+ // always clears refreshInFlight, so the in-flight request can never get permanently stuck.
201
+ // Never force-restart here: the old 5s "stalled" bypass left the original request running and
202
+ // stacked overlapping /api/snapshot calls onto the daemon. Queue the latest request or drop it.
203
+ if (options.queueIfBusy) {
204
+ state.pendingRefreshRequest = {
205
+ target,
206
+ options: {
207
+ ...options,
208
+ queueIfBusy: false,
209
+ silent: false,
210
+ },
211
+ };
212
+ if (!options.silent)
213
+ addLog('info', 'daemon', 'A Valdi snapshot fetch is already running; queued another refresh.');
214
+ }
215
+ return;
216
+ }
217
+ state.refreshInFlight = true;
218
+ state.refreshStartedAt = Date.now();
219
+ const params = target
220
+ ? { port: target.port || target.proxyPort, clientId: target.clientId, contextId: target.contextId }
221
+ : getSelectedTargetParams();
222
+ const previousSelectedNodeId = state.selectedNodeId;
223
+ const previousTargetKey = debuggerTargetKey();
224
+ const previousLogs = state.source === 'daemon' ? state.snapshot.logs : [];
225
+
226
+ try {
227
+ if (!options.silent) addLog('info', 'daemon', `Fetching Valdi tree from port ${params.port}.`);
228
+ const snapshot = await apiGet('/api/snapshot', params, { timeoutMs: 20000 });
229
+ state.snapshot = decorateSnapshot(snapshot);
230
+ if (debuggerTargetKey() !== previousTargetKey) resetDebuggerToolsForTarget();
231
+ state.snapshot.logs = [...previousLogs, ...(state.snapshot.logs || [])];
232
+ trimRuntimeLogs();
233
+ state.selectedNodeId =
234
+ options.preserveSelection && findNodeInTree(state.snapshot.tree, previousSelectedNodeId)
235
+ ? previousSelectedNodeId
236
+ : getNodeId(state.snapshot.tree);
237
+ if (!options.preserveSelection) collapseTree();
238
+ state.source = 'daemon';
239
+ state.attached = true;
240
+ state.manualDetach = false;
241
+ state.lastError = null;
242
+ state.selectedSnapshotImage = null;
243
+ state.lastUpdated = new Date().toLocaleTimeString();
244
+ elements.portSelect.value = String(state.snapshot.target.proxyPort || params.port);
245
+ render();
246
+ maybeRefreshDebuggerTools(state.activeSection);
247
+ if (!options.silent || !state.rootSnapshotImage) {
248
+ void captureRootSnapshot(params, options);
249
+ }
250
+ if (state.activeSection === 'logs') {
251
+ startRuntimeLogStream({ silent: options.silent });
252
+ } else {
253
+ stopRuntimeLogStream();
254
+ }
255
+ } catch (error) {
256
+ state.lastError = error.message;
257
+ state.source = 'empty';
258
+ state.attached = false;
259
+ state.rootSnapshotImage = null;
260
+ state.rootSnapshotRequestId++;
261
+ stopRuntimeLogStream();
262
+ if (!options.silent) addLog('error', 'daemon', error.message);
263
+ render();
264
+ } finally {
265
+ state.refreshInFlight = false;
266
+ state.refreshStartedAt = null;
267
+ const pendingRefreshRequest = state.pendingRefreshRequest;
268
+ state.pendingRefreshRequest = null;
269
+ if (pendingRefreshRequest) {
270
+ window.setTimeout(() => {
271
+ loadRealSnapshot(pendingRefreshRequest.target, pendingRefreshRequest.options);
272
+ }, 0);
273
+ }
274
+ }
275
+ }
276
+
277
+ function firstElementDescendant(node) {
278
+ if (!node) return null;
279
+ let found = null;
280
+ valdiDebuggerTreeModel.walk(
281
+ node,
282
+ current => {
283
+ if (!current.element || current.element.id === undefined) return true;
284
+ found = current;
285
+ return false;
286
+ },
287
+ [],
288
+ 0,
289
+ );
290
+ return found;
291
+ }
292
+
293
+ async function captureSelectedElementSnapshot() {
294
+ const node = selectedNode();
295
+ if (!node) {
296
+ addLog('warn', 'inspector', 'No node is selected because no snapshot is loaded.');
297
+ return;
298
+ }
299
+ const elementNode = firstElementDescendant(node);
300
+ const elementId =
301
+ elementNode && elementNode.element && elementNode.element.id !== undefined ? String(elementNode.element.id) : null;
302
+ if (!elementId) {
303
+ addLog('warn', 'inspector', 'No element descendant is available for the selected node.');
304
+ return;
305
+ }
306
+
307
+ try {
308
+ const params = {
309
+ ...getSelectedTargetParams(),
310
+ elementId,
311
+ };
312
+ const result = await apiGet('/api/element-snapshot', params, { timeoutMs: 20000 });
313
+ state.selectedSnapshotImage = result.image;
314
+ const sourceNote = elementNode === node ? '' : ` via ${elementNode.tag} #${elementId}`;
315
+ addLog('info', 'inspector', `Captured element snapshot for ${node.tag} #${getNodeId(node)}${sourceNote}.`);
316
+ renderInspector();
317
+ } catch (error) {
318
+ addLog('error', 'inspector', error.message);
319
+ }
320
+ }
321
+
322
+ async function dumpHeap() {
323
+ try {
324
+ const result = await apiPost('/api/heap', getSelectedTargetParams(), { performGC: false }, { timeoutMs: 65000 });
325
+ const heap = result.heap || {};
326
+ const fileName = `${targetFilePrefix()}-heap-${new Date().toISOString().replaceAll(':', '-')}.json`;
327
+ downloadJson(heap, fileName, 'Captured heap report.');
328
+ if (heap.memoryUsageBytes !== undefined) {
329
+ const mb = (heap.memoryUsageBytes / 1024 / 1024).toFixed(2);
330
+ addLog('info', 'heap', `Memory usage: ${mb} MB. The full report is available in the export panel.`);
331
+ }
332
+ } catch (error) {
333
+ addLog('error', 'heap', error.message);
334
+ }
335
+ }
336
+
337
+ function targetFilePrefix() {
338
+ return (state.snapshot.target?.name || 'valdi').replace(/[^a-z0-9_-]+/gi, '-').toLowerCase();
339
+ }
340
+
341
+ function downloadJson(payload, fileName, logMessage) {
342
+ const json = JSON.stringify(payload, null, 2);
343
+ const blob = new Blob([json], { type: 'application/json' });
344
+ if (state.exportObjectUrl) {
345
+ URL.revokeObjectURL(state.exportObjectUrl);
346
+ state.exportObjectUrl = null;
347
+ }
348
+ const url = URL.createObjectURL(blob);
349
+ state.exportObjectUrl = url;
350
+ elements.exportTitle.textContent = fileName;
351
+ elements.exportText.value = json;
352
+ elements.exportOpenLink.href = url;
353
+ elements.exportOpenLink.download = fileName;
354
+ elements.exportPanel.classList.add('open');
355
+ addLog('info', 'debugger', `${logMessage} Open or copy it from the export panel.`);
356
+ }
357
+
358
+ async function copyPreview() {
359
+ if (state.rootSnapshotImage && navigator.clipboard?.write && window.ClipboardItem) {
360
+ try {
361
+ const response = await fetch(state.rootSnapshotImage);
362
+ const blob = await response.blob();
363
+ const type = blob.type || 'image/png';
364
+ await navigator.clipboard.write([new ClipboardItem({ [type]: blob })]);
365
+ addLog('info', 'preview', 'Copied live preview image.');
366
+ return;
367
+ } catch (error) {
368
+ addLog('warn', 'preview', `Preview image copy failed: ${error.message}. Copying snapshot JSON instead.`);
369
+ }
370
+ }
371
+
372
+ if (!hasSnapshotTree()) {
373
+ addLog('warn', 'preview', 'No preview image or snapshot JSON is available to copy.');
374
+ return;
375
+ }
376
+
377
+ try {
378
+ await navigator.clipboard.writeText(previewSnapshotProjectionJson());
379
+ addLog('info', 'preview', 'Copied current snapshot JSON.');
380
+ } catch (error) {
381
+ addLog('error', 'preview', `Copy failed: ${error.message}`);
382
+ }
383
+ }
384
+
385
+ function previewSnapshotProjectionJson() {
386
+ return JSON.stringify(valdiDebuggerTreeModel.projectSnapshot(state.snapshot), null, 2);
387
+ }
@@ -0,0 +1,188 @@
1
+ // Lightweight debugger UI session persistence across page reloads.
2
+ const DEBUGGER_SESSION_STORAGE_KEY = 'valdi.debugger.session.v1';
3
+
4
+ let debuggerSessionPersistInterval = null;
5
+
6
+ function debuggerSessionTarget() {
7
+ const target = state.snapshot.target || {};
8
+ if (!target.id && !target.clientId && !target.contextId) return null;
9
+ return {
10
+ id: target.id || '',
11
+ name: target.name || '',
12
+ platform: target.platform || '',
13
+ transport: target.transport || '',
14
+ state: target.state || 'available',
15
+ port: target.port || target.proxyPort || selectedDaemonPort(),
16
+ proxyPort: target.proxyPort || target.port || selectedDaemonPort(),
17
+ clientId: target.clientId,
18
+ contextId: target.contextId,
19
+ applicationId: target.applicationId,
20
+ };
21
+ }
22
+
23
+ function debuggerSessionPayload() {
24
+ return {
25
+ activeSection: state.activeSection,
26
+ activeTab: state.activeTab,
27
+ overlayMode: state.overlayMode,
28
+ autoRefresh: state.autoRefresh,
29
+ followLatestTarget: state.followLatestTarget,
30
+ manualDetach: state.manualDetach,
31
+ selectedNodeId: state.selectedNodeId,
32
+ target: debuggerSessionTarget(),
33
+ port: selectedDaemonPort(),
34
+ treeSearch: elements.treeSearch.value,
35
+ logSearch: elements.logSearch.value,
36
+ expandedNodeIds: Array.from(state.expandedNodeIds),
37
+ rendererTracing: elements.rendererTracingToggle.checked,
38
+ traceDuration: elements.traceDurationInput.value,
39
+ activeTraceTarget: state.performance.activeTraceTarget,
40
+ traceActive: state.performance.traceActive,
41
+ traceResultPending: state.performance.traceResultPending,
42
+ traceStateUnknown: state.performance.traceStateUnknown,
43
+ profileDuration: elements.profileDurationInput.value,
44
+ profileContextId: elements.profileContextSelect.value,
45
+ providerTab: state.providers.activeTab,
46
+ settingsGroupId: state.settings.selectedGroupId,
47
+ };
48
+ }
49
+
50
+ function persistDebuggerSessionState() {
51
+ try {
52
+ window.sessionStorage.setItem(DEBUGGER_SESSION_STORAGE_KEY, JSON.stringify(debuggerSessionPayload()));
53
+ } catch (error) {
54
+ console.warn(`Could not persist debugger session: ${error.message}`);
55
+ }
56
+ }
57
+
58
+ function readDebuggerSessionState() {
59
+ try {
60
+ const raw = window.sessionStorage.getItem(DEBUGGER_SESSION_STORAGE_KEY);
61
+ return raw ? JSON.parse(raw) : null;
62
+ } catch (error) {
63
+ console.warn(`Could not read debugger session: ${error.message}`);
64
+ return null;
65
+ }
66
+ }
67
+
68
+ function restoreDebuggerSessionState() {
69
+ const saved = readDebuggerSessionState();
70
+ if (!saved || typeof saved !== 'object') return false;
71
+
72
+ const activeSection = normalizeSection(saved.activeSection);
73
+ if (elements.sectionPanels.some(panel => panel.dataset.sectionPanel === activeSection)) {
74
+ state.activeSection = activeSection;
75
+ }
76
+
77
+ if (['overview', 'props', 'state', 'issues', 'raw'].includes(saved.activeTab)) {
78
+ state.activeTab = saved.activeTab;
79
+ }
80
+
81
+ if (['live', 'views', 'components', 'issues'].includes(saved.overlayMode)) {
82
+ state.overlayMode =
83
+ saved.overlayMode === 'views' || saved.overlayMode === 'components' ? 'live' : saved.overlayMode;
84
+ }
85
+
86
+ if (typeof saved.autoRefresh === 'boolean') state.autoRefresh = saved.autoRefresh;
87
+ if (typeof saved.followLatestTarget === 'boolean') state.followLatestTarget = saved.followLatestTarget;
88
+ if (typeof saved.manualDetach === 'boolean') state.manualDetach = saved.manualDetach;
89
+ if (saved.selectedNodeId !== undefined && saved.selectedNodeId !== null) {
90
+ state.selectedNodeId = String(saved.selectedNodeId);
91
+ }
92
+
93
+ if (Array.isArray(saved.expandedNodeIds)) {
94
+ state.expandedNodeIds = new Set(saved.expandedNodeIds.map(String));
95
+ }
96
+
97
+ const port = Number.parseInt(String(saved.port || saved.target?.port || saved.target?.proxyPort || ''), 10);
98
+ if (Number.isFinite(port)) {
99
+ elements.portSelect.value = String(port);
100
+ state.snapshot.target = {
101
+ ...state.snapshot.target,
102
+ port,
103
+ proxyPort: port,
104
+ };
105
+ }
106
+
107
+ if (saved.target && typeof saved.target === 'object') {
108
+ state.snapshot.target = {
109
+ ...state.snapshot.target,
110
+ ...saved.target,
111
+ };
112
+ state.snapshot.targets = [state.snapshot.target];
113
+ state.source = 'daemon';
114
+ }
115
+
116
+ if (saved.treeSearch !== undefined) elements.treeSearch.value = String(saved.treeSearch);
117
+ if (saved.logSearch !== undefined) elements.logSearch.value = String(saved.logSearch);
118
+ if (typeof saved.rendererTracing === 'boolean') elements.rendererTracingToggle.checked = saved.rendererTracing;
119
+ if (saved.traceDuration !== undefined) elements.traceDurationInput.value = String(saved.traceDuration);
120
+ const persistedTraceMayBeActive =
121
+ saved.traceStateUnknown === true || saved.traceActive === true || saved.traceResultPending === true;
122
+ if (saved.activeTraceTarget && typeof saved.activeTraceTarget === 'object') {
123
+ const activeTracePort = Number.parseInt(String(saved.activeTraceTarget.port || ''), 10);
124
+ if (
125
+ Number.isFinite(activeTracePort) &&
126
+ saved.activeTraceTarget.clientId !== undefined &&
127
+ saved.activeTraceTarget.contextId !== undefined
128
+ ) {
129
+ state.performance.activeTraceTarget = {
130
+ port: activeTracePort,
131
+ clientId: String(saved.activeTraceTarget.clientId),
132
+ contextId: String(saved.activeTraceTarget.contextId),
133
+ };
134
+ }
135
+ }
136
+ if (state.performance.activeTraceTarget === null && persistedTraceMayBeActive) {
137
+ const fallbackTraceTarget = state.snapshot.target || saved.target;
138
+ const fallbackTracePort = Number.parseInt(String(fallbackTraceTarget?.port || ''), 10);
139
+ if (
140
+ Number.isFinite(fallbackTracePort) &&
141
+ fallbackTraceTarget?.clientId !== undefined &&
142
+ fallbackTraceTarget?.contextId !== undefined
143
+ ) {
144
+ state.performance.activeTraceTarget = {
145
+ port: fallbackTracePort,
146
+ clientId: String(fallbackTraceTarget.clientId),
147
+ contextId: String(fallbackTraceTarget.contextId),
148
+ };
149
+ }
150
+ }
151
+ state.performance.traceActive = false;
152
+ state.performance.traceResultPending = false;
153
+ state.performance.traceStateUnknown = state.performance.activeTraceTarget !== null || persistedTraceMayBeActive;
154
+ if (saved.profileDuration !== undefined) elements.profileDurationInput.value = String(saved.profileDuration);
155
+ if (saved.profileContextId !== undefined) elements.profileContextSelect.value = String(saved.profileContextId);
156
+ if (saved.providerTab === 'storage' || saved.providerTab === 'sql') state.providers.activeTab = saved.providerTab;
157
+ if (saved.settingsGroupId !== undefined && saved.settingsGroupId !== null) {
158
+ state.settings.selectedGroupId = String(saved.settingsGroupId);
159
+ }
160
+
161
+ return true;
162
+ }
163
+
164
+ function applyDebuggerSessionDomState() {
165
+ elements.sectionButtons.forEach(button => {
166
+ button.classList.toggle('active', button.dataset.sectionButton === state.activeSection);
167
+ });
168
+ elements.sectionPanels.forEach(panel => {
169
+ panel.classList.toggle('active', panel.dataset.sectionPanel === state.activeSection);
170
+ });
171
+ document.querySelectorAll('.tabs button').forEach(button => {
172
+ button.classList.toggle('active', button.dataset.tab === state.activeTab);
173
+ });
174
+ document.querySelectorAll('.segmented button').forEach(button => button.classList.remove('active'));
175
+ document
176
+ .getElementById(`mode${state.overlayMode[0].toUpperCase()}${state.overlayMode.slice(1)}`)
177
+ ?.classList.add('active');
178
+ if (state.activeSection === 'logs') renderLogs();
179
+ }
180
+
181
+ function installDebuggerSessionPersistence() {
182
+ if (debuggerSessionPersistInterval) clearInterval(debuggerSessionPersistInterval);
183
+ debuggerSessionPersistInterval = window.setInterval(persistDebuggerSessionState, 1000);
184
+ window.addEventListener('beforeunload', persistDebuggerSessionState);
185
+ document.addEventListener('visibilitychange', () => {
186
+ if (document.hidden) persistDebuggerSessionState();
187
+ });
188
+ }