@clagentic/console 1.5.0-beta.4 → 1.6.0-beta.1
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.
- package/README.md +5 -4
- package/bin/cli.js +15 -82
- package/lib/agents-favorites.js +21 -6
- package/lib/config.js +1 -1
- package/lib/daemon.js +59 -22
- package/lib/drain.js +213 -0
- package/lib/lite-detect.js +6 -5
- package/lib/loop-handoff.js +282 -0
- package/lib/mcp-local.js +18 -2
- package/lib/memory-limits.js +436 -0
- package/lib/model-context-windows.js +65 -0
- package/lib/project-loop.js +31 -3
- package/lib/project-team.js +4 -1
- package/lib/project.js +8 -0
- package/lib/public/app.js +4 -0
- package/lib/public/css/diagnostics.css +271 -0
- package/lib/public/index.html +13 -0
- package/lib/public/modules/app-messages.js +8 -0
- package/lib/public/modules/app-panels.js +11 -21
- package/lib/public/modules/diagnostic-format.js +34 -0
- package/lib/public/modules/diagnostics.js +287 -0
- package/lib/public/modules/model-context-windows.js +62 -0
- package/lib/public/style.css +1 -0
- package/lib/sdk-bridge.js +75 -10
- package/lib/sdk-message-processor.js +12 -0
- package/lib/sdk-worker.js +4 -1
- package/lib/server.js +28 -1
- package/lib/sessions.js +11 -2
- package/lib/settings-preflight.js +212 -0
- package/lib/yoke/adapters/claude-worker.js +14 -2
- package/lib/yoke/adapters/claude.js +16 -0
- package/lib/yoke/adapters/diagnostic-patterns.js +120 -0
- package/lib/yoke/index.js +4 -0
- package/lib/yoke/interface.js +99 -0
- package/package.json +1 -1
- package/scripts/postinstall.js +41 -0
- package/lib/certs/fullchain.pem +0 -47
- package/lib/certs/privkey.pem +0 -5
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
Diagnostics — Toast + Panel (lr-8294, epic lr-1a52)
|
|
3
|
+
Visually distinct from runtime errors: uses info/warning/error severity
|
|
4
|
+
colors but NOT the red error style of addSystemMessage.
|
|
5
|
+
========================================================================== */
|
|
6
|
+
|
|
7
|
+
/* --------------------------------------------------------
|
|
8
|
+
Diagnostics panel button (topbar)
|
|
9
|
+
-------------------------------------------------------- */
|
|
10
|
+
#diagnostics-panel-btn {
|
|
11
|
+
position: relative;
|
|
12
|
+
}
|
|
13
|
+
#diagnostics-panel-btn.active {
|
|
14
|
+
color: var(--accent);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* Badge on the panel toggle button */
|
|
18
|
+
.diagnostics-panel-badge {
|
|
19
|
+
position: absolute;
|
|
20
|
+
top: -3px;
|
|
21
|
+
right: -3px;
|
|
22
|
+
min-width: 15px;
|
|
23
|
+
height: 15px;
|
|
24
|
+
line-height: 15px;
|
|
25
|
+
border-radius: 8px;
|
|
26
|
+
font-size: 9px;
|
|
27
|
+
font-weight: 700;
|
|
28
|
+
text-align: center;
|
|
29
|
+
padding: 0 3px;
|
|
30
|
+
pointer-events: none;
|
|
31
|
+
font-family: inherit;
|
|
32
|
+
color: #fff;
|
|
33
|
+
background: var(--text-muted);
|
|
34
|
+
}
|
|
35
|
+
.diagnostics-panel-badge.hidden { display: none; }
|
|
36
|
+
.diagnostics-badge-info { background: var(--text-muted); }
|
|
37
|
+
.diagnostics-badge-warning { background: var(--accent2, #4A7FE8); }
|
|
38
|
+
.diagnostics-badge-error { background: var(--error, #FF4D6A); }
|
|
39
|
+
|
|
40
|
+
/* --------------------------------------------------------
|
|
41
|
+
Diagnostics panel (inside #info-panels)
|
|
42
|
+
Follows the usage-panel / team-panel pattern.
|
|
43
|
+
-------------------------------------------------------- */
|
|
44
|
+
#diagnostics-panel {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
47
|
+
min-height: 0;
|
|
48
|
+
}
|
|
49
|
+
#diagnostics-panel.hidden { display: none; }
|
|
50
|
+
#diagnostics-panel:focus { outline: none; }
|
|
51
|
+
|
|
52
|
+
.diagnostics-panel-body {
|
|
53
|
+
flex: 1;
|
|
54
|
+
overflow-y: auto;
|
|
55
|
+
padding: 0;
|
|
56
|
+
min-height: 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* --------------------------------------------------------
|
|
60
|
+
Diagnostic items
|
|
61
|
+
-------------------------------------------------------- */
|
|
62
|
+
.diagnostics-item {
|
|
63
|
+
padding: 10px 14px;
|
|
64
|
+
border-bottom: 1px solid var(--border-subtle, var(--border));
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: column;
|
|
67
|
+
gap: 4px;
|
|
68
|
+
}
|
|
69
|
+
.diagnostics-item:last-child { border-bottom: none; }
|
|
70
|
+
.diagnostics-item:hover { background: rgba(var(--overlay-rgb), 0.02); }
|
|
71
|
+
|
|
72
|
+
/* Left-border severity indicator */
|
|
73
|
+
.diagnostics-item-info { border-left: 2px solid var(--text-muted); }
|
|
74
|
+
.diagnostics-item-warning { border-left: 2px solid var(--accent2, #4A7FE8); }
|
|
75
|
+
.diagnostics-item-error { border-left: 2px solid var(--error, #FF4D6A); }
|
|
76
|
+
|
|
77
|
+
.diagnostics-item-meta {
|
|
78
|
+
display: flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
gap: 6px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* Severity badge pill */
|
|
84
|
+
.diagnostics-sev-badge {
|
|
85
|
+
font-family: var(--font-mono, monospace);
|
|
86
|
+
font-size: 9px;
|
|
87
|
+
font-weight: 700;
|
|
88
|
+
letter-spacing: 0.06em;
|
|
89
|
+
text-transform: uppercase;
|
|
90
|
+
border-radius: 4px;
|
|
91
|
+
padding: 1px 5px;
|
|
92
|
+
line-height: 1.4;
|
|
93
|
+
flex-shrink: 0;
|
|
94
|
+
}
|
|
95
|
+
.diagnostics-sev-info {
|
|
96
|
+
background: rgba(var(--overlay-rgb), 0.06);
|
|
97
|
+
color: var(--text-muted);
|
|
98
|
+
}
|
|
99
|
+
.diagnostics-sev-warning {
|
|
100
|
+
background: var(--accent2-12, rgba(74, 127, 232, 0.12));
|
|
101
|
+
color: var(--accent2, #4A7FE8);
|
|
102
|
+
}
|
|
103
|
+
.diagnostics-sev-error {
|
|
104
|
+
background: var(--error-12, rgba(255, 77, 106, 0.12));
|
|
105
|
+
color: var(--error, #FF4D6A);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* Source label */
|
|
109
|
+
.diagnostics-source {
|
|
110
|
+
font-family: var(--font-mono, monospace);
|
|
111
|
+
font-size: 9.5px;
|
|
112
|
+
color: var(--text-dimmer);
|
|
113
|
+
text-transform: uppercase;
|
|
114
|
+
letter-spacing: 0.08em;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Message text */
|
|
118
|
+
.diagnostics-message {
|
|
119
|
+
font-size: 12px;
|
|
120
|
+
color: var(--text-secondary);
|
|
121
|
+
line-height: 1.5;
|
|
122
|
+
word-break: break-word;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Actionable hint */
|
|
126
|
+
.diagnostics-actionable {
|
|
127
|
+
display: flex;
|
|
128
|
+
align-items: flex-start;
|
|
129
|
+
gap: 5px;
|
|
130
|
+
margin-top: 2px;
|
|
131
|
+
padding: 4px 6px;
|
|
132
|
+
background: var(--accent2-8, rgba(74, 127, 232, 0.08));
|
|
133
|
+
border-radius: 4px;
|
|
134
|
+
}
|
|
135
|
+
.diagnostics-actionable-icon {
|
|
136
|
+
flex-shrink: 0;
|
|
137
|
+
color: var(--accent2, #4A7FE8);
|
|
138
|
+
display: flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
}
|
|
141
|
+
.diagnostics-actionable-icon .lucide { width: 11px; height: 11px; }
|
|
142
|
+
.diagnostics-actionable-text {
|
|
143
|
+
font-size: 11px;
|
|
144
|
+
color: var(--text-secondary);
|
|
145
|
+
line-height: 1.4;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* Empty state */
|
|
149
|
+
.diagnostics-empty {
|
|
150
|
+
padding: 20px 14px;
|
|
151
|
+
font-size: 12px;
|
|
152
|
+
color: var(--text-muted);
|
|
153
|
+
text-align: center;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* --------------------------------------------------------
|
|
157
|
+
Diagnostic Toast
|
|
158
|
+
Extends the base .toast with richer layout.
|
|
159
|
+
Sits above the regular toast z-index.
|
|
160
|
+
-------------------------------------------------------- */
|
|
161
|
+
.toast-diagnostic {
|
|
162
|
+
position: fixed;
|
|
163
|
+
bottom: 80px;
|
|
164
|
+
left: 50%;
|
|
165
|
+
transform: translateX(-50%) translateY(8px);
|
|
166
|
+
z-index: 450;
|
|
167
|
+
opacity: 0;
|
|
168
|
+
pointer-events: auto;
|
|
169
|
+
transition: opacity 0.2s, transform 0.2s;
|
|
170
|
+
|
|
171
|
+
background: var(--bg-alt);
|
|
172
|
+
border: 1px solid var(--border);
|
|
173
|
+
border-radius: 10px;
|
|
174
|
+
box-shadow: 0 4px 20px rgba(var(--shadow-rgb), 0.3);
|
|
175
|
+
min-width: 280px;
|
|
176
|
+
max-width: 400px;
|
|
177
|
+
padding: 10px 14px;
|
|
178
|
+
display: flex;
|
|
179
|
+
flex-direction: column;
|
|
180
|
+
gap: 4px;
|
|
181
|
+
}
|
|
182
|
+
.toast-diagnostic.visible {
|
|
183
|
+
opacity: 1;
|
|
184
|
+
transform: translateX(-50%) translateY(0);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* Severity border accent */
|
|
188
|
+
.toast-diagnostic-info { border-left: 3px solid var(--text-muted); }
|
|
189
|
+
.toast-diagnostic-warning { border-left: 3px solid var(--accent2, #4A7FE8); }
|
|
190
|
+
.toast-diagnostic-error { border-left: 3px solid var(--error, #FF4D6A); }
|
|
191
|
+
|
|
192
|
+
.toast-diagnostic-header {
|
|
193
|
+
display: flex;
|
|
194
|
+
align-items: center;
|
|
195
|
+
gap: 6px;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.toast-diagnostic-severity {
|
|
199
|
+
font-family: var(--font-mono, monospace);
|
|
200
|
+
font-size: 9px;
|
|
201
|
+
font-weight: 700;
|
|
202
|
+
letter-spacing: 0.06em;
|
|
203
|
+
text-transform: uppercase;
|
|
204
|
+
border-radius: 4px;
|
|
205
|
+
padding: 1px 5px;
|
|
206
|
+
line-height: 1.4;
|
|
207
|
+
flex-shrink: 0;
|
|
208
|
+
}
|
|
209
|
+
.toast-diag-sev-info { background: rgba(var(--overlay-rgb), 0.06); color: var(--text-muted); }
|
|
210
|
+
.toast-diag-sev-warning { background: var(--accent2-12, rgba(74, 127, 232, 0.12)); color: var(--accent2, #4A7FE8); }
|
|
211
|
+
.toast-diag-sev-error { background: var(--error-12, rgba(255, 77, 106, 0.12)); color: var(--error, #FF4D6A); }
|
|
212
|
+
|
|
213
|
+
.toast-diagnostic-source {
|
|
214
|
+
font-family: var(--font-mono, monospace);
|
|
215
|
+
font-size: 9.5px;
|
|
216
|
+
color: var(--text-dimmer);
|
|
217
|
+
text-transform: uppercase;
|
|
218
|
+
letter-spacing: 0.08em;
|
|
219
|
+
flex: 1;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.toast-diagnostic-dismiss {
|
|
223
|
+
margin-left: auto;
|
|
224
|
+
background: none;
|
|
225
|
+
border: none;
|
|
226
|
+
color: var(--text-muted);
|
|
227
|
+
cursor: pointer;
|
|
228
|
+
padding: 2px;
|
|
229
|
+
display: flex;
|
|
230
|
+
align-items: center;
|
|
231
|
+
justify-content: center;
|
|
232
|
+
border-radius: 4px;
|
|
233
|
+
transition: color 0.15s, background 0.15s;
|
|
234
|
+
}
|
|
235
|
+
.toast-diagnostic-dismiss:hover {
|
|
236
|
+
color: var(--text);
|
|
237
|
+
background: rgba(var(--overlay-rgb), 0.06);
|
|
238
|
+
}
|
|
239
|
+
.toast-diagnostic-dismiss:focus-visible {
|
|
240
|
+
outline: 2px solid var(--accent);
|
|
241
|
+
outline-offset: 1px;
|
|
242
|
+
}
|
|
243
|
+
.toast-diagnostic-dismiss .lucide { width: 12px; height: 12px; }
|
|
244
|
+
|
|
245
|
+
.toast-diagnostic-msg {
|
|
246
|
+
font-size: 12.5px;
|
|
247
|
+
color: var(--text-secondary);
|
|
248
|
+
line-height: 1.5;
|
|
249
|
+
word-break: break-word;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.toast-diagnostic-hint {
|
|
253
|
+
font-size: 10.5px;
|
|
254
|
+
color: var(--text-dimmer);
|
|
255
|
+
margin-top: 2px;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* --------------------------------------------------------
|
|
259
|
+
Mobile
|
|
260
|
+
-------------------------------------------------------- */
|
|
261
|
+
@media (max-width: 768px) {
|
|
262
|
+
.toast-diagnostic {
|
|
263
|
+
left: 16px;
|
|
264
|
+
right: 16px;
|
|
265
|
+
transform: translateY(8px);
|
|
266
|
+
max-width: none;
|
|
267
|
+
}
|
|
268
|
+
.toast-diagnostic.visible {
|
|
269
|
+
transform: translateY(0);
|
|
270
|
+
}
|
|
271
|
+
}
|
package/lib/public/index.html
CHANGED
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
<div id="skip-perms-pill" class="top-bar-pill pill-error hidden"><i data-lucide="shield-off"></i> <span>Skip perms</span></div>
|
|
85
85
|
<div id="client-count" class="top-bar-pill pill-accent hidden"><i data-lucide="users"></i> <span id="client-count-text"></span></div>
|
|
86
86
|
<button id="share-pill" title="Share"><i data-lucide="share-2"></i></button>
|
|
87
|
+
<button id="diagnostics-panel-btn" title="Diagnostics" aria-label="Diagnostics" aria-expanded="false"><i data-lucide="activity"></i><span id="diagnostics-panel-badge" class="diagnostics-panel-badge hidden" aria-hidden="true">0</span></button>
|
|
87
88
|
<button id="notif-center-btn" title="Notifications"><i data-lucide="bell"></i><span id="notif-center-badge" class="notif-badge hidden">0</span></button>
|
|
88
89
|
<button id="server-settings-btn" title="Server settings"><i data-lucide="settings"></i></button>
|
|
89
90
|
</div>
|
|
@@ -337,6 +338,18 @@
|
|
|
337
338
|
</div>
|
|
338
339
|
<div id="team-panel-body" class="usage-panel-body team-panel-body"></div>
|
|
339
340
|
</div>
|
|
341
|
+
<!-- Diagnostics panel (lr-8294, epic lr-1a52) -->
|
|
342
|
+
<div id="diagnostics-panel" class="hidden" role="region" aria-label="Diagnostics" aria-expanded="false" tabindex="-1">
|
|
343
|
+
<div class="usage-panel-header">
|
|
344
|
+
<span>Diagnostics</span>
|
|
345
|
+
<button class="diagnostics-panel-close" aria-label="Close diagnostics panel"><i data-lucide="x"></i></button>
|
|
346
|
+
</div>
|
|
347
|
+
<div class="usage-panel-body diagnostics-panel-body">
|
|
348
|
+
<div id="diagnostics-panel-list">
|
|
349
|
+
<div class="diagnostics-empty">No diagnostics this session.</div>
|
|
350
|
+
</div>
|
|
351
|
+
</div>
|
|
352
|
+
</div>
|
|
340
353
|
<div id="context-panel" class="hidden">
|
|
341
354
|
<div class="usage-panel-header">
|
|
342
355
|
<span>Context</span>
|
|
@@ -50,6 +50,7 @@ import { handleSkillInstallWs } from './app-skills-install.js';
|
|
|
50
50
|
import { handleNotificationsState, handleNotificationCreated, handleNotificationDismissed, handleNotificationDismissedAll, showUpdateBanner } from './app-notifications.js';
|
|
51
51
|
import { handleMentionStart, handleMentionActivity, handleMentionStream, handleMentionDone, handleMentionError, renderMentionUser, renderMentionResponse, renderUserMention } from './mention.js';
|
|
52
52
|
import { handleTeamState, handleTeamMemberUpdate, handleTeamTaskUpdate, handleTeamMessage as handleTeamMsg, handleTeamGone } from './team-panel.js';
|
|
53
|
+
import { addDiagnostic } from './diagnostics.js';
|
|
53
54
|
|
|
54
55
|
// --- DOM refs (cached once, stable for page lifetime) ---
|
|
55
56
|
var messagesEl = document.getElementById("messages");
|
|
@@ -1328,6 +1329,13 @@ export function processMessage(msg) {
|
|
|
1328
1329
|
case "team_message": handleTeamMsg(msg); break;
|
|
1329
1330
|
case "team_gone": handleTeamGone(msg); break;
|
|
1330
1331
|
|
|
1332
|
+
case "diagnostic":
|
|
1333
|
+
// Diagnostic events from CLI stderr (stage 4/5, lr-8294, epic lr-1a52).
|
|
1334
|
+
// Future sources (e.g. settings preflight from stage 5/5 lr-1a26) will
|
|
1335
|
+
// also arrive via this same type — the render path must not assume CLI origin.
|
|
1336
|
+
addDiagnostic(msg);
|
|
1337
|
+
break;
|
|
1338
|
+
|
|
1331
1339
|
case "daemon_config":
|
|
1332
1340
|
if (msg.config && msg.config.headless) store.set({ isHeadlessMode: true });
|
|
1333
1341
|
updateDaemonConfig(msg.config);
|
|
@@ -6,6 +6,7 @@ import { escapeHtml, showToast } from "./utils.js";
|
|
|
6
6
|
import { store } from './store.js';
|
|
7
7
|
import { getWs } from './ws-ref.js';
|
|
8
8
|
import { VENDOR_NAMES } from './app-rendering.js';
|
|
9
|
+
import { KNOWN_CONTEXT_WINDOWS, resolveModelContextWindow as _resolveModelContextWindowCore } from './model-context-windows.js';
|
|
9
10
|
|
|
10
11
|
// --- Module-owned state (not in store) ---
|
|
11
12
|
// sessionUsage.context = last-turn context fill (lastStreamInputTokens) — not cumulative,
|
|
@@ -106,17 +107,7 @@ var CODEX_WEBSEARCH_OPTIONS = [
|
|
|
106
107
|
{ value: "cached", label: "Cached" },
|
|
107
108
|
{ value: "live", label: "Live" },
|
|
108
109
|
];
|
|
109
|
-
|
|
110
|
-
"opus-4-6": 1000000,
|
|
111
|
-
"claude-sonnet-4": 1000000,
|
|
112
|
-
"gpt-5.5": 1048576,
|
|
113
|
-
"gpt-5.4": 1048576,
|
|
114
|
-
"gpt-5.3": 1048576,
|
|
115
|
-
"gpt-5.2": 1048576,
|
|
116
|
-
"gpt-4.1": 1047576,
|
|
117
|
-
"o3": 200000,
|
|
118
|
-
"o4-mini": 200000,
|
|
119
|
-
};
|
|
110
|
+
// KNOWN_CONTEXT_WINDOWS imported from ./model-context-windows.js (lr-336f shared source of truth)
|
|
120
111
|
// Categories to hide from the legend (noise, not actionable)
|
|
121
112
|
var CTX_HIDDEN_CATS = { "Free space": 1, "Autocompact buffer": 1 };
|
|
122
113
|
|
|
@@ -796,17 +787,16 @@ export function toggleStatusPanel() {
|
|
|
796
787
|
// --- Context panel ---
|
|
797
788
|
|
|
798
789
|
export function resolveContextWindow(model, sdkValue) {
|
|
799
|
-
//
|
|
800
|
-
//
|
|
801
|
-
|
|
802
|
-
//
|
|
803
|
-
|
|
804
|
-
var
|
|
805
|
-
if (
|
|
790
|
+
// Build the active betas array from store so we can delegate to the shared
|
|
791
|
+
// core (lr-336f) which is store-agnostic and usable on both backend and frontend.
|
|
792
|
+
var activeBetas = store.get('currentBetas') || [];
|
|
793
|
+
// Delegate to shared core: beta-first, then [1m] suffix, then map lookup.
|
|
794
|
+
// Core returns 0 for unknown models; apply frontend-specific fallbacks here.
|
|
795
|
+
var coreResult = _resolveModelContextWindowCore(model, activeBetas);
|
|
796
|
+
if (coreResult > 0) return coreResult;
|
|
797
|
+
// sdkValue fallback: prefer the SDK-reported window when the model is not in the
|
|
798
|
+
// shared map (new models, vendor-specific entries). Returns 200000 as last resort.
|
|
806
799
|
if (sdkValue) return sdkValue;
|
|
807
|
-
for (var key in KNOWN_CONTEXT_WINDOWS) {
|
|
808
|
-
if (lc.includes(key)) return KNOWN_CONTEXT_WINDOWS[key];
|
|
809
|
-
}
|
|
810
800
|
return 200000;
|
|
811
801
|
}
|
|
812
802
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// diagnostic-format.js — Pure formatting helpers for diagnostic messages.
|
|
2
|
+
// No DOM dependencies; importable in unit tests directly.
|
|
3
|
+
// Part of epic lr-1a52 stage 4/5 (lr-8294).
|
|
4
|
+
|
|
5
|
+
// Human-readable labels for known diagnostic source identifiers.
|
|
6
|
+
// Sources from stage 5/5 (lr-1a26) preflight may add new entries here;
|
|
7
|
+
// the default falls back to the raw source string.
|
|
8
|
+
var SOURCE_LABELS = {
|
|
9
|
+
hook: "Hook",
|
|
10
|
+
cli: "CLI",
|
|
11
|
+
settings: "Settings",
|
|
12
|
+
stderr: "CLI",
|
|
13
|
+
preflight: "Preflight",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Format a raw diagnostic source identifier for display.
|
|
18
|
+
* @param {string} source - The source field from the diagnostic message.
|
|
19
|
+
* @returns {string} Human-readable source label.
|
|
20
|
+
*/
|
|
21
|
+
export function formatDiagnosticSource(source) {
|
|
22
|
+
if (!source) return "Diagnostic";
|
|
23
|
+
return SOURCE_LABELS[source] || source;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Map severity to a short display label.
|
|
28
|
+
* @param {string} severity - 'info' | 'warning' | 'error'
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
export function formatDiagnosticSeverity(severity) {
|
|
32
|
+
if (!severity) return "INFO";
|
|
33
|
+
return severity.toUpperCase();
|
|
34
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// diagnostics.js — Diagnostic event rendering for epic lr-1a52 stage 4/5 (lr-8294).
|
|
2
|
+
//
|
|
3
|
+
// Consumes { type:'diagnostic', severity:'info'|'warning'|'error', source:string, message:string,
|
|
4
|
+
// actionable?:{label:string, action:string} } messages from the backend.
|
|
5
|
+
//
|
|
6
|
+
// Contract (set by stages 1-3, do NOT modify):
|
|
7
|
+
// - The message arrives via sendAndRecord — it is persisted in session history.
|
|
8
|
+
// - Diagnostics can arrive from any source (CLI stderr today, settings preflight in stage 5).
|
|
9
|
+
// - severity 'warning' and 'error' produce a toast (info lands quietly in the panel).
|
|
10
|
+
//
|
|
11
|
+
// Public surface:
|
|
12
|
+
// initDiagnostics() — call once on page load (wires up panel button)
|
|
13
|
+
// addDiagnostic(msg) — call from processMessage case 'diagnostic'
|
|
14
|
+
// formatDiagnosticSource(source) — pure helper, exported for tests
|
|
15
|
+
|
|
16
|
+
import { iconHtml, refreshIcons } from './icons.js';
|
|
17
|
+
import { formatDiagnosticSource as _formatSource } from './diagnostic-format.js';
|
|
18
|
+
|
|
19
|
+
// --- Module state ---
|
|
20
|
+
var diagnostics = []; // [{severity, source, message, actionable, ts}]
|
|
21
|
+
var panelEl = null;
|
|
22
|
+
var panelListEl = null;
|
|
23
|
+
var panelToggleBtn = null;
|
|
24
|
+
var panelBadgeEl = null;
|
|
25
|
+
|
|
26
|
+
// Severity priority (higher = more prominent).
|
|
27
|
+
var SEVERITY_ORDER = { error: 2, warning: 1, info: 0 };
|
|
28
|
+
|
|
29
|
+
// ============================================================
|
|
30
|
+
// Init
|
|
31
|
+
// ============================================================
|
|
32
|
+
|
|
33
|
+
export function initDiagnostics() {
|
|
34
|
+
panelEl = document.getElementById("diagnostics-panel");
|
|
35
|
+
panelListEl = document.getElementById("diagnostics-panel-list");
|
|
36
|
+
panelToggleBtn = document.getElementById("diagnostics-panel-btn");
|
|
37
|
+
panelBadgeEl = document.getElementById("diagnostics-panel-badge");
|
|
38
|
+
|
|
39
|
+
if (!panelEl || !panelListEl || !panelToggleBtn) return;
|
|
40
|
+
|
|
41
|
+
// Shared helper: close panel and return focus to the topbar button (WCAG 2.1 §2.4.3).
|
|
42
|
+
// Both the close button click and the Escape-key path use this so focus restoration
|
|
43
|
+
// is consistent for all keyboard-accessible dismiss gestures.
|
|
44
|
+
function closePanelAndRefocus() {
|
|
45
|
+
closePanel();
|
|
46
|
+
if (panelToggleBtn) panelToggleBtn.focus();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Close button inside the panel header.
|
|
50
|
+
var closeBtn = panelEl.querySelector(".diagnostics-panel-close");
|
|
51
|
+
if (closeBtn) {
|
|
52
|
+
closeBtn.addEventListener("click", function () {
|
|
53
|
+
closePanelAndRefocus();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Toggle button in the topbar.
|
|
58
|
+
panelToggleBtn.addEventListener("click", function () {
|
|
59
|
+
if (panelEl.classList.contains("hidden")) {
|
|
60
|
+
openPanel();
|
|
61
|
+
} else {
|
|
62
|
+
closePanel();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Keyboard: dismiss on Escape when panel is focused.
|
|
67
|
+
panelEl.addEventListener("keydown", function (e) {
|
|
68
|
+
if (e.key === "Escape") {
|
|
69
|
+
closePanelAndRefocus();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ============================================================
|
|
75
|
+
// Public: add a diagnostic
|
|
76
|
+
// ============================================================
|
|
77
|
+
|
|
78
|
+
export function addDiagnostic(msg) {
|
|
79
|
+
var entry = {
|
|
80
|
+
severity: msg.severity || "info",
|
|
81
|
+
source: msg.source || "",
|
|
82
|
+
message: msg.message || "",
|
|
83
|
+
actionable: msg.actionable || null,
|
|
84
|
+
ts: Date.now(),
|
|
85
|
+
};
|
|
86
|
+
diagnostics.push(entry);
|
|
87
|
+
|
|
88
|
+
// Render the new entry in the panel list.
|
|
89
|
+
_appendEntry(entry);
|
|
90
|
+
|
|
91
|
+
// Update the badge to reflect the highest-severity unread diagnostic.
|
|
92
|
+
_updateBadge();
|
|
93
|
+
|
|
94
|
+
// Toast for warning and error severity only.
|
|
95
|
+
if (entry.severity === "warning" || entry.severity === "error") {
|
|
96
|
+
_showDiagnosticToast(entry);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Re-export the pure formatter so callers that import from this module
|
|
101
|
+
// can reach it without a second import. Tests should import from
|
|
102
|
+
// diagnostic-format.js directly (no DOM deps there).
|
|
103
|
+
export { formatDiagnosticSource } from './diagnostic-format.js';
|
|
104
|
+
|
|
105
|
+
// ============================================================
|
|
106
|
+
// Toast
|
|
107
|
+
// ============================================================
|
|
108
|
+
|
|
109
|
+
function _showDiagnosticToast(entry) {
|
|
110
|
+
var el = document.createElement("div");
|
|
111
|
+
// Use a dedicated class so diagnostics are visually distinct from error messages.
|
|
112
|
+
el.className = "toast toast-diagnostic toast-diagnostic-" + entry.severity;
|
|
113
|
+
el.setAttribute("role", "alert");
|
|
114
|
+
el.setAttribute("aria-live", "assertive");
|
|
115
|
+
|
|
116
|
+
var headerEl = document.createElement("div");
|
|
117
|
+
headerEl.className = "toast-diagnostic-header";
|
|
118
|
+
|
|
119
|
+
var severityEl = document.createElement("span");
|
|
120
|
+
severityEl.className = "toast-diagnostic-severity toast-diag-sev-" + entry.severity;
|
|
121
|
+
severityEl.textContent = entry.severity.toUpperCase();
|
|
122
|
+
|
|
123
|
+
var sourceEl = document.createElement("span");
|
|
124
|
+
sourceEl.className = "toast-diagnostic-source";
|
|
125
|
+
sourceEl.textContent = _formatSource(entry.source);
|
|
126
|
+
|
|
127
|
+
var dismissBtn = document.createElement("button");
|
|
128
|
+
dismissBtn.className = "toast-diagnostic-dismiss";
|
|
129
|
+
dismissBtn.setAttribute("aria-label", "Dismiss diagnostic notification");
|
|
130
|
+
dismissBtn.innerHTML = iconHtml("x");
|
|
131
|
+
|
|
132
|
+
headerEl.appendChild(severityEl);
|
|
133
|
+
headerEl.appendChild(sourceEl);
|
|
134
|
+
headerEl.appendChild(dismissBtn);
|
|
135
|
+
|
|
136
|
+
var msgEl = document.createElement("div");
|
|
137
|
+
msgEl.className = "toast-diagnostic-msg";
|
|
138
|
+
msgEl.textContent = entry.message;
|
|
139
|
+
|
|
140
|
+
var hintEl = document.createElement("div");
|
|
141
|
+
hintEl.className = "toast-diagnostic-hint";
|
|
142
|
+
hintEl.textContent = "See Diagnostics panel for details";
|
|
143
|
+
|
|
144
|
+
el.appendChild(headerEl);
|
|
145
|
+
el.appendChild(msgEl);
|
|
146
|
+
el.appendChild(hintEl);
|
|
147
|
+
|
|
148
|
+
document.body.appendChild(el);
|
|
149
|
+
refreshIcons();
|
|
150
|
+
|
|
151
|
+
// Animate in.
|
|
152
|
+
requestAnimationFrame(function () { el.classList.add("visible"); });
|
|
153
|
+
|
|
154
|
+
// Auto-dismiss after 6s.
|
|
155
|
+
var timer = setTimeout(function () { _removeDiagnosticToast(el); }, 6000);
|
|
156
|
+
|
|
157
|
+
// Manual dismiss.
|
|
158
|
+
dismissBtn.addEventListener("click", function () {
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
_removeDiagnosticToast(el);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Keyboard dismiss.
|
|
164
|
+
el.addEventListener("keydown", function (e) {
|
|
165
|
+
if (e.key === "Escape" || e.key === "Enter" || e.key === " ") {
|
|
166
|
+
clearTimeout(timer);
|
|
167
|
+
_removeDiagnosticToast(el);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function _removeDiagnosticToast(el) {
|
|
173
|
+
el.classList.remove("visible");
|
|
174
|
+
setTimeout(function () {
|
|
175
|
+
if (el.parentNode) el.parentNode.removeChild(el);
|
|
176
|
+
}, 300);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ============================================================
|
|
180
|
+
// Panel
|
|
181
|
+
// ============================================================
|
|
182
|
+
|
|
183
|
+
function openPanel() {
|
|
184
|
+
if (!panelEl) return;
|
|
185
|
+
panelEl.classList.remove("hidden");
|
|
186
|
+
panelEl.setAttribute("aria-expanded", "true");
|
|
187
|
+
if (panelToggleBtn) {
|
|
188
|
+
panelToggleBtn.setAttribute("aria-expanded", "true");
|
|
189
|
+
panelToggleBtn.classList.add("active");
|
|
190
|
+
}
|
|
191
|
+
// Focus the panel for keyboard navigation.
|
|
192
|
+
panelEl.focus();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function closePanel() {
|
|
196
|
+
if (!panelEl) return;
|
|
197
|
+
panelEl.classList.add("hidden");
|
|
198
|
+
panelEl.setAttribute("aria-expanded", "false");
|
|
199
|
+
if (panelToggleBtn) {
|
|
200
|
+
panelToggleBtn.setAttribute("aria-expanded", "false");
|
|
201
|
+
panelToggleBtn.classList.remove("active");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function _appendEntry(entry) {
|
|
206
|
+
if (!panelListEl) return;
|
|
207
|
+
|
|
208
|
+
// Remove the empty-state placeholder if present.
|
|
209
|
+
var emptyEl = panelListEl.querySelector(".diagnostics-empty");
|
|
210
|
+
if (emptyEl) emptyEl.parentNode.removeChild(emptyEl);
|
|
211
|
+
|
|
212
|
+
var item = document.createElement("div");
|
|
213
|
+
item.className = "diagnostics-item diagnostics-item-" + entry.severity;
|
|
214
|
+
|
|
215
|
+
// Icon strip: severity pill.
|
|
216
|
+
var meta = document.createElement("div");
|
|
217
|
+
meta.className = "diagnostics-item-meta";
|
|
218
|
+
|
|
219
|
+
var sevEl = document.createElement("span");
|
|
220
|
+
sevEl.className = "diagnostics-sev-badge diagnostics-sev-" + entry.severity;
|
|
221
|
+
sevEl.setAttribute("aria-label", "Severity: " + entry.severity);
|
|
222
|
+
sevEl.textContent = entry.severity;
|
|
223
|
+
|
|
224
|
+
var srcEl = document.createElement("span");
|
|
225
|
+
srcEl.className = "diagnostics-source";
|
|
226
|
+
srcEl.textContent = _formatSource(entry.source);
|
|
227
|
+
|
|
228
|
+
meta.appendChild(sevEl);
|
|
229
|
+
meta.appendChild(srcEl);
|
|
230
|
+
|
|
231
|
+
var msgEl = document.createElement("div");
|
|
232
|
+
msgEl.className = "diagnostics-message";
|
|
233
|
+
msgEl.textContent = entry.message;
|
|
234
|
+
|
|
235
|
+
item.appendChild(meta);
|
|
236
|
+
item.appendChild(msgEl);
|
|
237
|
+
|
|
238
|
+
// Actionable hint: surface label when present.
|
|
239
|
+
if (entry.actionable && entry.actionable.label) {
|
|
240
|
+
var actionEl = document.createElement("div");
|
|
241
|
+
actionEl.className = "diagnostics-actionable";
|
|
242
|
+
|
|
243
|
+
var fixIcon = document.createElement("span");
|
|
244
|
+
fixIcon.className = "diagnostics-actionable-icon";
|
|
245
|
+
fixIcon.innerHTML = iconHtml("info");
|
|
246
|
+
|
|
247
|
+
var fixText = document.createElement("span");
|
|
248
|
+
fixText.className = "diagnostics-actionable-text";
|
|
249
|
+
fixText.textContent = entry.actionable.label;
|
|
250
|
+
|
|
251
|
+
actionEl.appendChild(fixIcon);
|
|
252
|
+
actionEl.appendChild(fixText);
|
|
253
|
+
item.appendChild(actionEl);
|
|
254
|
+
refreshIcons();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
panelListEl.appendChild(item);
|
|
258
|
+
|
|
259
|
+
// Scroll the panel to the newest entry.
|
|
260
|
+
panelListEl.scrollTop = panelListEl.scrollHeight;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ============================================================
|
|
264
|
+
// Badge
|
|
265
|
+
// ============================================================
|
|
266
|
+
|
|
267
|
+
function _updateBadge() {
|
|
268
|
+
if (!panelBadgeEl) return;
|
|
269
|
+
var count = diagnostics.length;
|
|
270
|
+
if (count === 0) {
|
|
271
|
+
panelBadgeEl.classList.add("hidden");
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
// Show count; cap at 99.
|
|
275
|
+
panelBadgeEl.textContent = count > 99 ? "99+" : String(count);
|
|
276
|
+
panelBadgeEl.classList.remove("hidden");
|
|
277
|
+
|
|
278
|
+
// Badge color reflects the highest-severity diagnostic in the list.
|
|
279
|
+
panelBadgeEl.className = "diagnostics-panel-badge";
|
|
280
|
+
var maxSev = "info";
|
|
281
|
+
for (var i = 0; i < diagnostics.length; i++) {
|
|
282
|
+
if (SEVERITY_ORDER[diagnostics[i].severity] > SEVERITY_ORDER[maxSev]) {
|
|
283
|
+
maxSev = diagnostics[i].severity;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
panelBadgeEl.classList.add("diagnostics-badge-" + maxSev);
|
|
287
|
+
}
|