-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdashboard.js
More file actions
4615 lines (4157 loc) · 193 KB
/
dashboard.js
File metadata and controls
4615 lines (4157 loc) · 193 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Dashboard component for workspace management
class Dashboard {
constructor(orchestrator) {
this.orchestrator = orchestrator;
this.workspaces = [];
this.config = {};
this.isVisible = false;
this.quickLinks = null;
this._escHandler = null;
this._projectLaunchInFlight = false;
this._resizeHandler = null;
this._layoutMode = 'desktop';
this.compactTab = 'workspaces';
}
async show() {
console.log('Showing dashboard...');
// Initialize Quick Links if available
if (window.QuickLinks && !this.quickLinks) {
this.quickLinks = new QuickLinks(this.orchestrator);
window.quickLinks = this.quickLinks; // Make available globally for onclick handlers
}
const visibility = this.orchestrator.getUiVisibilityConfig()?.dashboard || {};
// Fetch quick links data - re-render when complete
if (this.quickLinks && visibility.quickLinks !== false) {
this.quickLinks.fetchData().then(() => {
// Re-render to show quick links once loaded
if (this.isVisible) {
this.render();
}
}).catch(() => {});
}
// Request workspaces from server (with refresh to reload from disk)
this.orchestrator.socket.emit('list-workspaces', { refresh: true });
// Wait for workspace data
this.orchestrator.socket.once('workspaces-list', (workspaces) => {
console.log('Received workspaces:', workspaces);
this.workspaces = workspaces;
// Also update orchestrator's cached list
this.orchestrator.availableWorkspaces = workspaces;
try {
const withHealth = Array.isArray(workspaces) ? workspaces : [];
const noisy = withHealth.filter((w) => (w?.health && (w.health.removedTerminals?.length || w.health.dedupedTerminalIds?.length)));
if (noisy.length) {
const count = noisy.reduce((sum, w) => sum + Number(w.health?.removedTerminals?.length || 0), 0);
this.orchestrator.showToast?.(`Cleaned ${count} stale terminal entries from workspace configs`, 'info');
}
} catch {}
this.render();
this.isVisible = true;
});
}
hide() {
const dashboard = document.getElementById('dashboard-container');
if (dashboard) {
dashboard.classList.add('hidden');
}
this.isVisible = false;
if (this._escHandler) {
document.removeEventListener('keydown', this._escHandler);
this._escHandler = null;
}
if (this._resizeHandler) {
window.removeEventListener('resize', this._resizeHandler);
this._resizeHandler = null;
}
}
getLayoutMode() {
if (typeof window === 'undefined') return 'desktop';
return window.innerWidth <= 1100 ? 'compact' : 'desktop';
}
render() {
// Create dashboard container if it doesn't exist
let dashboard = document.getElementById('dashboard-container');
if (!dashboard) {
dashboard = document.createElement('div');
dashboard.id = 'dashboard-container';
dashboard.className = 'dashboard-container';
document.body.appendChild(dashboard);
}
// Hide main content while showing dashboard
const mainContainer = document.querySelector('.main-container');
const sidebar = document.querySelector('.sidebar');
if (mainContainer) mainContainer.classList.add('hidden');
if (sidebar) sidebar.classList.add('hidden');
// Render dashboard content
dashboard.innerHTML = this.generateDashboardHTML();
dashboard.classList.remove('hidden');
// Set up event listeners
this.setupEventListeners();
// Set up quick links drag and drop
const visibility = this.orchestrator.getUiVisibilityConfig()?.dashboard || {};
if (this.quickLinks && visibility.quickLinks !== false) {
this.quickLinks.setupDragAndDrop();
}
// Load ports for dashboard
if (visibility.runningServices !== false) {
this.loadDashboardPorts();
}
// Load process status/telemetry/advice summaries
if (visibility.processSection !== false) {
this.loadDashboardProcessSummary();
}
}
generateDashboardHTML() {
const sortByLastAccess = (a, b) => {
const aTime = a.lastAccess ? new Date(a.lastAccess).getTime() : 0;
const bTime = b.lastAccess ? new Date(b.lastAccess).getTime() : 0;
return bTime - aTime;
};
const escapeHtml = (value) => String(value ?? '')
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>');
const activeWorkspaces = this.workspaces.filter(ws => this.isWorkspaceActive(ws)).sort(sortByLastAccess);
const inactiveWorkspaces = this.workspaces.filter(ws => !this.isWorkspaceActive(ws)).sort(sortByLastAccess);
const canReturnToWorkspaces = !!(this.orchestrator.tabManager?.tabs?.size);
const visibility = this.orchestrator.getUiVisibilityConfig()?.dashboard || {};
const showProcessBanner = visibility.processBanner !== false;
const layoutMode = this.getLayoutMode();
const isCompactLayout = layoutMode === 'compact';
this._layoutMode = layoutMode;
// SVG Icons replacing Emojis
const svgIcon = (path, cls="dashboard-svg-icon") => `<svg class="${cls}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${path}</svg>`;
const SVGS = {
back: svgIcon('<path d="M19 12H5M12 19l-7-7 7-7"/>'),
status: svgIcon('<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>'),
telemetry: svgIcon('<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline>'),
details: svgIcon('<path d="M3 3v18h18"/><path d="M18 17V9"/><path d="M13 17V5"/><path d="M8 17v-3"/>'),
perf: svgIcon('<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>'),
polecats: svgIcon('<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/>'),
hooks: svgIcon('<path d="M12 22v-5"/><path d="M9 7H7a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h2"/><path d="M15 7h2a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-2"/><circle cx="12" cy="7" r="3"/>'),
deacon: svgIcon('<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>'),
tests: svgIcon('<path d="M9 2v2"/><path d="M15 2v2"/><path d="M12 2v10"/><path d="M5 20a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8l-4-4H9L5 8v12Z"/>'),
export: svgIcon('<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/>'),
discord: svgIcon('<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>'),
projects: svgIcon('<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>'),
prs: svgIcon('<circle cx="18" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><path d="M13 6h3a2 2 0 0 1 2 2v7"/><line x1="6" y1="9" x2="6" y2="21"/>'),
health: svgIcon('<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>'),
board: svgIcon('<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/>'),
advice: svgIcon('<path d="M12 2a5 5 0 0 0-5 5v2a5 5 0 0 0 5 5h0a5 5 0 0 0 5-5V7a5 5 0 0 0-5-5z"/><path d="M12 14v7"/><path d="M9 21h6"/>'),
queue: svgIcon('<polyline points="22 12 16 12 14 15 10 15 8 12 2 12"/><path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/>'),
viz: svgIcon('<circle cx="12" cy="12" r="10"/><polygon points="16.24 7.76 14.12 14.12 7.76 16.24 9.88 9.88 16.24 7.76"/>'),
convoys: svgIcon('<rect x="1" y="3" width="15" height="13"/><polygon points="16 8 20 8 23 11 23 16 16 16 16 8"/><circle cx="5.5" cy="18.5" r="2.5"/><circle cx="18.5" cy="18.5" r="2.5"/>'),
suggestions: svgIcon('<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/>'),
distribution: svgIcon('<circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/>'),
readiness: svgIcon('<polyline points="9 11 12 14 22 4"/><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/>'),
workspace: svgIcon('<polygon points="12 2 2 7 12 12 22 7 12 2"/><polyline points="2 17 12 22 22 17"/><polyline points="2 12 12 17 22 12"/>'),
ensure: svgIcon('<path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 9.36l-7.1 7.1a2.12 2.12 0 0 1-3-3l7.1-7.1a6 6 0 0 1 9.36-7.94z"/>'),
services: svgIcon('<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/>'),
add: svgIcon('<line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/>'),
quickLinks: svgIcon('<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>')
};
const processCards = [
visibility.statusCard !== false ? `
<div class="dashboard-bento-card dashboard-status">
<div class="dashboard-bento-header">
ℹ️ <span class="dashboard-bento-title">Status</span>
</div>
<div id="dashboard-status-summary" class="dashboard-bento-body">Loading…</div>
</div>
` : '',
visibility.telemetryCard !== false ? `
<div class="dashboard-bento-card dashboard-telemetry">
<div class="dashboard-bento-header">
📈 <span class="dashboard-bento-title">Telemetry</span>
</div>
<div id="dashboard-telemetry-summary" class="dashboard-bento-body">Loading…</div>
<div class="dashboard-bento-actions">
<button class="bento-btn" id="dashboard-open-telemetry-details" title="View trends">📈 Details</button>
<button class="bento-btn" id="dashboard-open-performance" title="Resource usage">⚙ Perf</button>
<button class="bento-btn" id="dashboard-open-hooks" title="Hook browser">🪝 Hooks</button>
<button class="bento-btn" id="dashboard-open-deacon" title="Health dashboard">🛡 Deacon</button>
<button class="bento-btn" id="dashboard-open-tests" title="Run tests">🧪 Tests</button>
<button class="bento-btn" id="dashboard-export-telemetry" title="Export CSV">⬇ CSV</button>
<button class="bento-btn" id="dashboard-export-telemetry-json" title="Export JSON">⬇ JSON</button>
</div>
</div>
` : '',
visibility.polecatsCard !== false ? `
<div class="dashboard-bento-card dashboard-polecats">
<div class="dashboard-bento-header">
🐾 <span class="dashboard-bento-title">Polecats</span>
</div>
<div id="dashboard-polecats-summary" class="dashboard-bento-body">Loading…</div>
<div class="dashboard-bento-actions">
<button class="bento-btn" id="dashboard-open-polecats-card" title="Open Polecats panel">🐾 Manage</button>
</div>
</div>
` : '',
visibility.discordCard !== false ? `
<div class="dashboard-bento-card dashboard-discord">
<div class="dashboard-bento-header">
🎮 <span class="dashboard-bento-title">Discord</span>
</div>
<div id="dashboard-discord-summary" class="dashboard-bento-body">Loading…</div>
<div class="dashboard-bento-actions">
<label class="bento-checkbox-label" title="Auto-start Discord bot">
<input type="checkbox" id="dashboard-discord-autostart" /> Auto-start
</label>
<button class="bento-btn" id="dashboard-discord-ensure" title="Ensure Services">🧰 Ensure</button>
<button class="bento-btn" id="dashboard-discord-process" title="Trigger processing">📥 Process</button>
<button class="bento-btn" id="dashboard-discord-open-services" title="Open Services">↗ Services</button>
</div>
</div>
` : '',
visibility.projectsCard !== false ? `
<div class="dashboard-bento-card dashboard-projects">
<div class="dashboard-bento-header">
🗂 <span class="dashboard-bento-title">Projects</span>
</div>
<div id="dashboard-projects-summary" class="dashboard-bento-body">Loading…</div>
<div class="dashboard-bento-actions">
<button class="bento-btn" id="dashboard-open-prs" title="Pull Requests">🔀 PRs</button>
<button class="bento-btn" id="dashboard-open-project-health" title="Health dashboard">🩺 Health</button>
<button class="bento-btn" id="dashboard-open-project-board" title="Kanban board">🗂 Board</button>
</div>
</div>
` : '',
visibility.adviceCard !== false ? `
<div class="dashboard-bento-card dashboard-advice">
<div class="dashboard-bento-header">
🧠 <span class="dashboard-bento-title">Advice</span>
</div>
<div id="dashboard-advice-summary" class="dashboard-bento-body">Loading…</div>
<div class="dashboard-bento-actions">
<button class="bento-btn" id="dashboard-open-queue" title="Queue">📥 Queue</button>
<button class="bento-btn" id="dashboard-open-queue-viz" title="Queue visualization">🧭 Viz</button>
<button class="bento-btn" id="dashboard-open-convoys" title="Convoys">🚚 Convoys</button>
<button class="bento-btn" id="dashboard-open-advice" title="Advice">🧠 Advice</button>
<button class="bento-btn" id="dashboard-open-suggestions" title="Suggestions">✨ Hints</button>
<button class="bento-btn" id="dashboard-open-distribution" title="Distribution">🎯 Dist</button>
</div>
</div>
` : '',
visibility.readinessCard !== false ? `
<div class="dashboard-bento-card dashboard-readiness">
<div class="dashboard-bento-header">
✅ <span class="dashboard-bento-title">Readiness</span>
</div>
<div id="dashboard-readiness-summary" class="dashboard-bento-body">Loading…</div>
<div class="dashboard-bento-actions">
<button class="bento-btn" id="dashboard-open-readiness" title="Checklists">✅ Checklists</button>
</div>
</div>
` : ''
].filter(Boolean).join('');
const processSection = processCards ? `
<div class="dashboard-bento-section">
<h2 class="dashboard-section-title">Process & Telemetry</h2>
<div class="bento-grid">
${processCards}
</div>
</div>
` : '';
const createSection = (visibility.createSection !== false) ? `
<div class="dashboard-create-banner">
<div class="dashboard-create-info">
<div class="dashboard-create-title">✨ Get Started</div>
<div class="dashboard-create-desc">Set up a new workspace environment to begin building.</div>
</div>
<button id="dashboard-add-workspace-btn" class="btn-primary workspace-create-empty-btn dashboard-create-btn">
➕ Create Workspace
</button>
</div>
` : '';
const quickLinksSection = (visibility.quickLinks !== false) ? `
<div class="dashboard-bento-card dashboard-quick-links">
<div class="dashboard-bento-header">
🔗 <span class="dashboard-bento-title">Quick Links</span>
</div>
<div class="quick-links-grid">
${this.generateQuickLinksHTML()}
</div>
</div>
` : '';
const runningServicesSection = (visibility.runningServices !== false) ? `
<div class="dashboard-bento-card ports-dashboard-section">
<div class="dashboard-bento-header">
📈 <span class="dashboard-bento-title">Running Services</span>
</div>
<div class="ports-dashboard-grid" id="ports-dashboard-grid">
<div class="ports-loading">Loading services...</div>
</div>
</div>
` : '';
const workspaceCards = [];
if (visibility.workspacesActive !== false) {
workspaceCards.push(...activeWorkspaces.map((ws) => this.generateWorkspaceCard(ws, true)));
}
if (visibility.workspacesAll !== false) {
workspaceCards.push(...inactiveWorkspaces.map((ws) => this.generateWorkspaceCard(ws, false)));
}
const totalWorkspaceCount = workspaceCards.length;
const workspaceSection = workspaceCards.length ? `
<div class="dashboard-bento-section dashboard-workspaces-section">
<h2 class="dashboard-section-title">Workspaces</h2>
<div class="workspace-grid bento-workspace-grid dashboard-workspaces-grid">
${workspaceCards.join('')}
</div>
</div>
` : '';
const resourcesCards = [quickLinksSection, runningServicesSection].filter(Boolean);
const resourcesSection = resourcesCards.join('');
const compactTabs = [
(createSection || workspaceSection) ? { id: 'workspaces', label: 'Workspaces', content: `${createSection}${workspaceSection}` } : null,
processSection ? { id: 'process', label: 'Process', content: processSection } : null,
resourcesSection ? { id: 'resources', label: 'Resources', content: resourcesSection } : null
].filter(Boolean);
if (!compactTabs.some((tab) => tab.id === this.compactTab)) {
this.compactTab = compactTabs[0]?.id || 'workspaces';
}
const desktopResourcesGrid = resourcesCards.length
? `
<div class="dashboard-resource-cards">
${resourcesCards.join('')}
</div>
`
: '';
const desktopResourceStack = [processSection, desktopResourcesGrid].filter(Boolean).join('');
const desktopSidebar = `
<aside class="dashboard-side-panel">
<div class="dashboard-side-header">
<div class="dashboard-side-overview">
<div class="dashboard-side-stats">
<div class="dashboard-side-stat">
<strong>${escapeHtml(activeWorkspaces.length)}</strong>
<span>Active</span>
</div>
<div class="dashboard-side-stat">
<strong>${escapeHtml(inactiveWorkspaces.length)}</strong>
<span>Standby</span>
</div>
</div>
</div>
<div class="dashboard-side-divider" aria-hidden="true"></div>
<div class="dashboard-side-stack">
<div class="dashboard-side-pill is-active">
<span>Workspaces</span>
<strong>${escapeHtml(totalWorkspaceCount)}</strong>
</div>
</div>
</div>
<div class="dashboard-side-scroll" aria-hidden="true"></div>
${(visibility.createSection !== false) ? `
<div class="dashboard-side-footer">
<button class="btn-primary workspace-create-empty-btn dashboard-side-create-btn">
✚ New Workspace
</button>
</div>
` : ''}
</aside>
`;
const desktopBody = (workspaceSection && desktopResourceStack)
? `
<div class="dashboard-main-content">
<div class="dashboard-content-left">
${workspaceSection}
</div>
<div class="dashboard-content-right dashboard-resource-stack">
${desktopResourceStack}
</div>
</div>
`
: `
<div class="dashboard-main-content dashboard-main-content-single">
${workspaceSection ? `
<div class="dashboard-content-left">
${workspaceSection}
</div>
` : ''}
${desktopResourceStack ? `
<div class="dashboard-content-right dashboard-resource-stack">
${desktopResourceStack}
</div>
` : ''}
</div>
`;
const desktopLayout = `
<div class="dashboard-desktop-shell">
${desktopSidebar}
<div class="dashboard-desktop-body">
<div class="dashboard-desktop-header">
<div class="dashboard-desktop-title-group">
<div class="brand-orb dashboard-brand-orb" aria-hidden="true"></div>
<h1>Agent Workspace</h1>
</div>
</div>
${desktopBody}
</div>
</div>
`;
const compactLayout = `
<div class="dashboard-compact-shell">
<div class="dashboard-compact-tabs" role="tablist" aria-label="Dashboard sections">
${compactTabs.map((tab) => `
<button
type="button"
class="dashboard-compact-tab ${tab.id === this.compactTab ? 'is-active' : ''}"
data-dashboard-tab="${tab.id}"
role="tab"
aria-selected="${tab.id === this.compactTab ? 'true' : 'false'}"
>
${escapeHtml(tab.label)}
</button>
`).join('')}
</div>
<div class="dashboard-compact-panel-shell">
${compactTabs.map((tab) => `
<section
class="dashboard-compact-panel ${tab.id === this.compactTab ? 'is-active' : ''}"
data-dashboard-panel="${tab.id}"
role="tabpanel"
>
${tab.content}
</section>
`).join('')}
</div>
</div>
`;
return `
<div class="dashboard-wrapper dashboard-layout-${layoutMode}">
<div class="dashboard-topbar">
${canReturnToWorkspaces ? `<button class="dashboard-topbar-btn" id="dashboard-back-btn" title="Back to workspaces">← Back</button>` : ''}
${showProcessBanner ? `<div id="dashboard-process-banner" class="process-banner" title="WIP and queue status"></div>` : ''}
</div>
${isCompactLayout ? `
<div class="dashboard-header-modern">
<div class="dashboard-title-group">
<div class="brand-orb dashboard-brand-orb" aria-hidden="true"></div>
<div>
<h1>Agent Workspace</h1>
<p>Select a workspace to begin development</p>
</div>
</div>
</div>
` : ''}
${isCompactLayout ? compactLayout : desktopLayout}
</div>
`;
}
async loadDashboardProcessSummary() {
const visibility = this.orchestrator.getUiVisibilityConfig()?.dashboard || {};
const showStatus = visibility.statusCard !== false;
const showTelemetry = visibility.telemetryCard !== false;
const showPolecats = visibility.polecatsCard !== false;
const showDiscord = visibility.discordCard !== false;
const showProjects = visibility.projectsCard !== false;
const showAdvice = visibility.adviceCard !== false;
const showReadiness = visibility.readinessCard !== false;
const showAny = showStatus || showTelemetry || showPolecats || showDiscord || showProjects || showAdvice || showReadiness;
if (!showAny) return;
const statusEl = document.getElementById('dashboard-status-summary');
const telemetryEl = document.getElementById('dashboard-telemetry-summary');
const polecatsEl = document.getElementById('dashboard-polecats-summary');
const discordEl = document.getElementById('dashboard-discord-summary');
const projectsEl = document.getElementById('dashboard-projects-summary');
const adviceEl = document.getElementById('dashboard-advice-summary');
const readinessEl = document.getElementById('dashboard-readiness-summary');
document.getElementById('dashboard-open-telemetry-details')?.addEventListener('click', (e) => {
e.preventDefault();
this.showTelemetryOverlay();
});
document.getElementById('dashboard-open-performance')?.addEventListener('click', (e) => {
e.preventDefault();
this.showPerformanceOverlay();
});
document.getElementById('dashboard-open-polecats')?.addEventListener('click', (e) => {
e.preventDefault();
this.showPolecatOverlay().catch(() => {});
});
document.getElementById('dashboard-open-hooks')?.addEventListener('click', (e) => {
e.preventDefault();
this.showHooksOverlay().catch(() => {});
});
document.getElementById('dashboard-open-deacon')?.addEventListener('click', (e) => {
e.preventDefault();
this.showDeaconOverlay().catch(() => {});
});
document.getElementById('dashboard-open-polecats-card')?.addEventListener('click', (e) => {
e.preventDefault();
this.showPolecatOverlay().catch(() => {});
});
// Discord auto-start checkbox
const discordAutostartCb = document.getElementById('dashboard-discord-autostart');
if (discordAutostartCb) {
// Load current setting
try {
const res = await fetch('/api/user-settings').catch(() => null);
const settings = res ? await res.json().catch(() => ({})) : {};
discordAutostartCb.checked = settings?.global?.ui?.discord?.autoEnsureServicesAtStartup === true;
} catch { /* leave unchecked */ }
discordAutostartCb.addEventListener('change', async (e) => {
const enabled = !!e.target.checked;
await this.orchestrator?.updateGlobalUserSetting?.('ui.discord.autoEnsureServicesAtStartup', enabled);
if (enabled) {
await this.ensureDiscordServices();
await this.loadDashboardDiscordSummary(discordEl);
}
});
}
document.getElementById('dashboard-discord-ensure')?.addEventListener('click', async (e) => {
e.preventDefault();
await this.ensureDiscordServices();
await this.loadDashboardDiscordSummary(discordEl);
});
document.getElementById('dashboard-discord-process')?.addEventListener('click', async (e) => {
e.preventDefault();
await this.processDiscordQueue();
await this.loadDashboardDiscordSummary(discordEl);
});
document.getElementById('dashboard-discord-open-services')?.addEventListener('click', async (e) => {
e.preventDefault();
await this.openDiscordServicesWorkspace();
});
document.getElementById('dashboard-open-tests')?.addEventListener('click', (e) => {
e.preventDefault();
try {
this.showTestOrchestrationOverlay();
} catch {}
});
document.getElementById('dashboard-export-telemetry')?.addEventListener('click', (e) => {
e.preventDefault();
const hours = Number(this._telemetrySummary?.lookbackHours ?? 24);
this.downloadTelemetryCsv(hours);
});
document.getElementById('dashboard-export-telemetry-json')?.addEventListener('click', (e) => {
e.preventDefault();
const hours = Number(this._telemetrySummary?.lookbackHours ?? 24);
this.downloadTelemetryJson(hours);
});
document.getElementById('dashboard-open-queue')?.addEventListener('click', (e) => {
e.preventDefault();
this.orchestrator?.showQueuePanel?.().catch?.(() => {});
});
document.getElementById('dashboard-open-queue-viz')?.addEventListener('click', (e) => {
e.preventDefault();
this.showQueueVizOverlay().catch(() => {});
});
document.getElementById('dashboard-open-convoys')?.addEventListener('click', (e) => {
e.preventDefault();
this.showConvoysOverlay().catch(() => {});
});
document.getElementById('dashboard-open-prs')?.addEventListener('click', (e) => {
e.preventDefault();
try {
this.orchestrator?.showPRsPanel?.();
} catch {}
});
document.getElementById('dashboard-open-project-health')?.addEventListener('click', (e) => {
e.preventDefault();
try {
this.showProjectHealthOverlay();
} catch {}
});
document.getElementById('dashboard-open-project-board')?.addEventListener('click', (e) => {
e.preventDefault();
try {
this.orchestrator?.projectsBoardUI?.show?.();
} catch {}
});
document.getElementById('dashboard-open-advice')?.addEventListener('click', (e) => {
e.preventDefault();
try {
this.orchestrator?.handleCommanderAction?.('open-advice', {});
} catch {}
});
document.getElementById('dashboard-open-readiness')?.addEventListener('click', (e) => {
e.preventDefault();
try {
this.showReadinessOverlay();
} catch {}
});
document.getElementById('dashboard-open-suggestions')?.addEventListener('click', (e) => {
e.preventDefault();
try {
this.showSuggestionsOverlay();
} catch {}
});
document.getElementById('dashboard-open-distribution')?.addEventListener('click', (e) => {
e.preventDefault();
try {
this.showDistributionOverlay();
} catch {}
});
if (showPolecats) {
try {
this.updatePolecatSummary(polecatsEl);
} catch {
// ignore
}
}
const escapeHtml = (value) => String(value ?? '')
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>');
const renderAdvice = async ({ force = false } = {}) => {
if (!adviceEl) return;
adviceEl.textContent = 'Loading…';
let adviceRes = null;
let data = {};
try {
const url = new URL('/api/process/advice', window.location.origin);
url.searchParams.set('mode', 'mine');
if (force) url.searchParams.set('force', 'true');
adviceRes = await fetch(url.toString()).catch(() => null);
data = adviceRes ? await adviceRes.json().catch(() => ({})) : {};
} catch {
adviceRes = null;
data = {};
}
if (adviceRes && adviceRes.ok) {
const items = Array.isArray(data?.advice) ? data.advice : [];
const m = data?.metrics || {};
const reviewsCompleted = Number(m?.reviewsCompleted ?? 0);
const needsFix = Number(m?.reviewsNeedsFix ?? 0);
const blockedPrs = Number(m?.prsBlockedByDeps ?? 0);
const needsFixRate = Number.isFinite(Number(m?.needsFixRate)) ? Number(m.needsFixRate) : null;
const metricsHtml = `
<div style="display:grid; gap:4px; margin-bottom:8px; opacity:0.92;">
<div>Blocked PRs <strong>${blockedPrs}</strong></div>
<div>Reviews <strong>${reviewsCompleted}</strong> • needs_fix <strong>${needsFix}</strong>${needsFixRate === null ? '' : ` • rate <strong>${Math.round(needsFixRate * 100)}%</strong>`}</div>
</div>
`;
if (!items.length) {
adviceEl.innerHTML = metricsHtml + '<div style="opacity:0.8;">No advice right now.</div>';
} else {
adviceEl.innerHTML = `
${metricsHtml}
<ul style="margin:0;padding-left:18px;">
${items.slice(0, 3).map((a) => `<li><strong>${escapeHtml(a.title || '')}</strong> — ${escapeHtml(a.message || '')}</li>`).join('')}
</ul>
`;
}
return;
}
const statusText = adviceRes
? `HTTP ${Number(adviceRes.status || 0)}`
: 'Network error';
const errorText = String(data?.error || '').trim();
adviceEl.innerHTML = `
<div style="opacity:0.9;">Failed to load advice.</div>
<div style="opacity:0.7; font-size:0.85rem; margin-top:4px;">${escapeHtml(statusText)}${errorText ? ` • ${escapeHtml(errorText)}` : ''}</div>
<div style="margin-top:10px;">
<button class="dashboard-topbar-btn" type="button" id="dashboard-advice-retry">↻ Retry</button>
</div>
`;
adviceEl.querySelector('#dashboard-advice-retry')?.addEventListener('click', () => {
renderAdvice({ force: true });
});
};
try {
const projectsBoardPromise = (showProjects && this.orchestrator?.getProjectsBoard)
? this.orchestrator.getProjectsBoard({ force: false }).catch(() => null)
: Promise.resolve(null);
const scannedReposPromise = (showProjects && this.orchestrator?.getScannedRepos)
? this.orchestrator.getScannedRepos({ force: false }).catch(() => [])
: Promise.resolve([]);
const [statusRes, telemetryRes, projectsRes, readinessRes, projectsBoardData, scannedRepos] = await Promise.all([
showStatus ? fetch('/api/process/status?mode=mine').catch(() => null) : Promise.resolve(null),
showTelemetry ? fetch('/api/process/telemetry').catch(() => null) : Promise.resolve(null),
showProjects ? fetch('/api/process/projects?mode=mine').catch(() => null) : Promise.resolve(null),
showReadiness ? fetch('/api/process/readiness/templates').catch(() => null) : Promise.resolve(null),
projectsBoardPromise,
scannedReposPromise
]);
if (showStatus && statusEl) {
const data = statusRes ? await statusRes.json().catch(() => ({})) : {};
if (statusRes && statusRes.ok) {
const q = data?.qByTier || {};
statusEl.innerHTML = `
<div>WIP <strong>${Number(data?.wip ?? 0)}</strong> (${escapeHtml(data?.wipKind || 'workspaces')})</div>
<div>T1 ${Number(q[1] ?? 0)} • T2 ${Number(q[2] ?? 0)} • T3 ${Number(q[3] ?? 0)} • T4 ${Number(q[4] ?? 0)}</div>
<div>Level <strong>${escapeHtml(data?.level || 'ok')}</strong></div>
`;
} else {
statusEl.textContent = 'Failed to load.';
}
}
if (showTelemetry && telemetryEl) {
const data = telemetryRes ? await telemetryRes.json().catch(() => ({})) : {};
if (telemetryRes && telemetryRes.ok) {
this._telemetrySummary = data;
const avgReview = data?.avgReviewSeconds ? `${Math.round(Number(data.avgReviewSeconds))}s` : '—';
const avgChars = Number.isFinite(Number(data?.avgPromptChars)) ? Math.round(Number(data.avgPromptChars)) : null;
const createdCount = Number(data?.createdCount ?? 0);
const doneCount = Number(data?.doneCount ?? 0);
const avgVerify = Number.isFinite(Number(data?.avgVerifyMinutes)) ? Math.round(Number(data.avgVerifyMinutes)) : null;
const oc = (data?.outcomeCounts && typeof data.outcomeCounts === 'object') ? data.outcomeCounts : {};
const needsFix = Number(oc?.needs_fix ?? 0);
telemetryEl.innerHTML = `
<div>Lookback <strong>${Number(data?.lookbackHours ?? 24)}h</strong></div>
<div>Avg review <strong>${escapeHtml(avgReview)}</strong></div>
<div>Avg prompt chars <strong>${avgChars === null ? '—' : avgChars}</strong></div>
<div>Created <strong>${createdCount}</strong> • Done <strong>${doneCount}</strong> • needs_fix <strong>${needsFix}</strong></div>
<div>Avg verify <strong>${avgVerify === null ? '—' : `${avgVerify}m`}</strong></div>
`;
} else {
telemetryEl.textContent = 'Failed to load.';
}
}
if (showProjects && projectsEl) {
const data = projectsRes ? await projectsRes.json().catch(() => ({})) : {};
const projectsBoard = projectsBoardData?.board && typeof projectsBoardData.board === 'object' ? projectsBoardData.board : null;
const scanned = Array.isArray(scannedRepos) ? scannedRepos : [];
const normalizeKey = (value) => (this.orchestrator?.normalizeProjectsBoardProjectKey?.(value) ?? String(value || '').trim().replace(/\\/g, '/'));
const boardHtml = (() => {
if (!projectsBoard || scanned.length === 0) return '';
const repoByKey = new Map();
for (const repo of scanned) {
const key = normalizeKey(repo?.relativePath);
if (!key) continue;
if (!repoByKey.has(key)) repoByKey.set(key, repo);
}
if (!repoByKey.size) return '';
const getOrderIndex = (columnId) => {
const raw = projectsBoard?.orderByColumn && typeof projectsBoard.orderByColumn === 'object'
? projectsBoard.orderByColumn[columnId]
: null;
const order = Array.isArray(raw) ? raw : [];
const index = new Map();
order.forEach((k, i) => {
const key = normalizeKey(k);
if (!key || index.has(key)) return;
index.set(key, i);
});
return index;
};
const collect = (columnId) => {
const out = [];
for (const [key, repo] of repoByKey.entries()) {
const col = this.orchestrator?.getProjectsBoardColumnForProjectKey?.(key, projectsBoardData) || 'backlog';
if (col === columnId) out.push({ key, repo });
}
const index = getOrderIndex(columnId);
out.sort((a, b) => {
const aRank = index.has(a.key) ? index.get(a.key) : Number.POSITIVE_INFINITY;
const bRank = index.has(b.key) ? index.get(b.key) : Number.POSITIVE_INFINITY;
if (aRank !== bRank) return aRank - bRank;
return String(a.repo?.name || '').localeCompare(String(b.repo?.name || ''));
});
return out;
};
const shipNext = collect('next');
const active = collect('active');
const total = shipNext.length + active.length;
if (total === 0) return '';
const tagMap = projectsBoard?.tagsByProjectKey && typeof projectsBoard.tagsByProjectKey === 'object'
? projectsBoard.tagsByProjectKey
: {};
const renderTile = (item) => {
const icon = this.orchestrator?.getProjectIcon?.(item?.repo?.type) || '📁';
const name = String(item?.repo?.name || item?.key || '').trim();
const key = normalizeKey(item?.key);
const category = String(item?.repo?.category || '').trim();
const type = String(item?.repo?.type || '').trim();
const subtitle = category ? `${category} • ${key}` : key;
const isLive = !!tagMap[key]?.live;
return `
<button type="button"
class="dashboard-project-tile ${isLive ? 'is-live' : ''}"
data-dashboard-start-project="${escapeHtml(key)}"
data-project-type="${escapeHtml(type)}"
title="Start worktree: ${escapeHtml(name)}">
<span class="dashboard-project-tile-icon">${escapeHtml(icon)}</span>
<span class="dashboard-project-tile-text">
<span class="dashboard-project-tile-name">${escapeHtml(name)}</span>
<span class="dashboard-project-tile-subtitle">${escapeHtml(subtitle)}</span>
</span>
${isLive ? `<span class="dashboard-project-tile-live" title="Live">★</span>` : ''}
</button>
`;
};
const renderGroup = (label, list) => {
if (!list.length) return '';
return `
<div class="dashboard-project-group">
<div class="dashboard-project-group-title">${escapeHtml(label)} <span class="dashboard-project-group-count">${list.length}</span></div>
<div class="dashboard-project-grid">
${list.map(renderTile).join('')}
</div>
</div>
`;
};
return `
<div class="dashboard-projects-board">
${renderGroup('Ship Next', shipNext)}
${renderGroup('Active', active)}
</div>
`;
})();
const prSummaryHtml = (() => {
if (!(projectsRes && projectsRes.ok)) {
return `<div style="opacity:0.85;">Failed to load PR summary.</div>`;
}
const totals = data?.totals || {};
const repos = Array.isArray(data?.repos) ? data.repos : [];
const top = repos.slice(0, 6);
const pickWorstRisk = (counts) => {
const c = counts && typeof counts === 'object' ? counts : {};
if (Number(c.critical || 0) > 0) return 'critical';
if (Number(c.high || 0) > 0) return 'high';
if (Number(c.medium || 0) > 0) return 'medium';
if (Number(c.low || 0) > 0) return 'low';
return '';
};
const riskChip = (risk) => {
const r = String(risk || '').trim().toLowerCase();
if (!r) return '';
const cls = (r === 'critical' || r === 'high') ? 'level-warn' : '';
return `<span class="process-chip ${cls}">${escapeHtml(r)}</span>`;
};
return `
<div>Repos <strong>${Number(totals?.repos ?? top.length ?? 0)}</strong> • Open PRs <strong>${Number(totals?.prsOpen ?? 0)}</strong></div>
<div>Unreviewed <strong>${Number(totals?.prsUnreviewed ?? 0)}</strong> • Needs fix <strong>${Number(totals?.prsNeedsFix ?? 0)}</strong></div>
<div style="margin-top:8px; display:flex; flex-direction:column; gap:6px;">
${top.length ? top.map((r) => {
const repo = String(r?.repo || '').trim();
const open = Number(r?.prsOpen ?? 0);
const unrev = Number(r?.prsUnreviewed ?? 0);
const avgReview = r?.telemetry?.avgReviewSeconds ? `${Math.round(Number(r.telemetry.avgReviewSeconds))}s` : '—';
const worstRisk = pickWorstRisk(r?.riskCounts);
return `
<button class="btn-secondary" type="button" data-open-repo="${escapeHtml(repo)}" title="Open PRs filtered to ${escapeHtml(repo)}" style="width:100%; display:flex; justify-content:space-between; align-items:center; gap:10px;">
<span style="min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">${escapeHtml(repo)} (${open} open, ${unrev} unrev)</span>
<span style="display:flex; align-items:center; gap:8px; flex-shrink:0;">
${worstRisk ? riskChip(worstRisk) : ''}
<span style="opacity:0.8;">${escapeHtml(avgReview)}</span>
</span>
</button>
`;
}).join('') : `<div style="opacity:0.8;">No PRs found.</div>`}
</div>
`;
})();
projectsEl.innerHTML = `${boardHtml}${prSummaryHtml}`;
projectsEl.querySelectorAll('[data-dashboard-start-project]').forEach((btn) => {
btn.addEventListener('click', async () => {
if (this._projectLaunchInFlight) return;
const key = String(btn.getAttribute('data-dashboard-start-project') || '').trim();
if (!key) return;
this._projectLaunchInFlight = true;
btn.disabled = true;
try {
const currentId = String(this.orchestrator?.currentWorkspace?.id || '').trim();
const workspaces = Array.isArray(this.workspaces) ? this.workspaces : [];
const pickRecent = () => {
if (currentId) return currentId;
let best = null;
let bestTime = 0;
for (const ws of workspaces) {
const t = ws?.lastAccess ? new Date(ws.lastAccess).getTime() : 0;
if (!best || t > bestTime) {
best = ws;
bestTime = t;
}
}
return String(best?.id || '').trim();
};
const targetId = pickRecent();
try { this.orchestrator?.hideDashboard?.(); } catch {}
if (targetId && targetId !== currentId) {
this.orchestrator?.switchToWorkspace?.(targetId);
await this.orchestrator?.waitForWorkspaceActive?.(targetId).catch(() => false);
}
await this.orchestrator?.startProjectWorktreeFromBoardKey?.(key);
} catch {
this.orchestrator?.showToast?.('Failed to start worktree', 'error');
} finally {
btn.disabled = false;
this._projectLaunchInFlight = false;
}
});
});
projectsEl.querySelectorAll('[data-open-repo]').forEach((btn) => {
btn.addEventListener('click', () => {
const repo = btn.getAttribute('data-open-repo') || '';
if (!repo) return;
try {
localStorage.setItem('prs-panel-repo', repo);
} catch {}
try {
this.orchestrator?.showPRsPanel?.();
} catch {}
});
});
}
if (showReadiness && readinessEl) {
const data = readinessRes ? await readinessRes.json().catch(() => ({})) : {};
if (readinessRes && readinessRes.ok) {
const templates = Array.isArray(data?.templates) ? data.templates : [];
const titles = templates.map(t => String(t?.title || '').trim()).filter(Boolean);
readinessEl.innerHTML = `
<div>Templates <strong>${templates.length}</strong></div>
<div style="opacity:0.9;">${escapeHtml(titles.slice(0, 5).join(' • ') || '—')}</div>
`;
} else {
readinessEl.textContent = 'Failed to load.';
}
}
if (showDiscord) {
await this.loadDashboardDiscordSummary(discordEl);
}
if (showAdvice) {
await renderAdvice({ force: false });
}
} catch (error) {
if (showStatus && statusEl) statusEl.textContent = 'Failed to load.';
if (showTelemetry && telemetryEl) telemetryEl.textContent = 'Failed to load.';
if (showProjects && projectsEl) projectsEl.textContent = 'Failed to load.';
if (showReadiness && readinessEl) readinessEl.textContent = 'Failed to load.';
if (showDiscord && discordEl) discordEl.textContent = 'Failed to load.';
if (showAdvice) await renderAdvice({ force: false });
}
}
async ensureDiscordServices() {
try {
const res = await fetch('/api/discord/ensure-services', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
}).catch(() => null);
if (!res || !res.ok) {
this.orchestrator?.showTemporaryMessage?.('Failed to ensure Discord services', 'error');
return null;
}
const data = await res.json().catch(() => ({}));
this.orchestrator?.showTemporaryMessage?.('Discord services ensured', 'success');