@d86e/hive-panel 0.0.0-stage → 0.3.4

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.
@@ -0,0 +1,4326 @@
1
+ // Hive panel — zero-dependency ESM renderer for hive-panel 0.3.2 snapshots.
2
+ // User-provided values are always written with textContent; no raw HTML is assigned.
3
+ //
4
+ // Visible copy is translated through the built-in \`messages\` dictionaries
5
+ // (en / zh) and, when a host provides one, a \`t(key)\` translate function.
6
+ // Hosts can hot-swap languages by calling \`subscribeLocale\` and re-rendering.
7
+
8
+ const LANE_ORDER = Object.freeze(["pending", "claimed", "done", "blocked", "failed"]);
9
+ const MAX_EVENTS = 80;
10
+ const DEFAULT_SNAPSHOT_URL = "/api/snapshot";
11
+ const DEFAULT_ACTIONS_URL = "/api/actions";
12
+ const DEFAULT_SUPERVISOR_URL = "/api/hive-runner";
13
+ const DEFAULT_INTERVAL_MS = 3000;
14
+
15
+ const CARD_ACTIONS = Object.freeze({
16
+ pending: Object.freeze(["claim"]),
17
+ claimed: Object.freeze(["done", "fail"]),
18
+ done: Object.freeze([]),
19
+ blocked: Object.freeze(["retry"]),
20
+ failed: Object.freeze(["retry"]),
21
+ });
22
+
23
+ const ACTION_META = Object.freeze({
24
+ freeze: { labelKey: "action.freeze", helpKey: "help.action.freeze", paramsKey: "help.params.mode" },
25
+ unfreeze: { labelKey: "action.unfreeze", helpKey: "help.action.unfreeze", paramsKey: "help.params.mode" },
26
+ add: { labelKey: "action.add", helpKey: "help.action.add", paramsKey: "help.params.add" },
27
+ plan: { labelKey: "action.plan", helpKey: "help.action.plan", paramsKey: "help.params.plan" },
28
+ commit: { labelKey: "action.commit", helpKey: "help.action.commit", paramsKey: "help.params.commit" },
29
+ claim: { labelKey: "action.claim", helpKey: "help.action.claim", paramsKey: "help.params.claim" },
30
+ done: { labelKey: "action.done", helpKey: "help.action.done", paramsKey: "help.params.done" },
31
+ fail: { labelKey: "action.fail", helpKey: "help.action.fail", paramsKey: "help.params.fail" },
32
+ retry: { labelKey: "action.retry", helpKey: "help.action.retry", paramsKey: "help.params.retry" },
33
+ });
34
+
35
+ const MIN_PLAN_CARDS = 1;
36
+
37
+ const PANEL_STYLES = `.hive { position: relative; }
38
+
39
+ .hive-action-group {
40
+ display: flex;
41
+ flex: 1 1 auto;
42
+ flex-wrap: nowrap;
43
+ align-items: center;
44
+ justify-content: flex-end;
45
+ gap: 6px;
46
+ min-width: 0;
47
+ max-width: 100%;
48
+ margin-left: auto;
49
+ }
50
+
51
+ .hive-actions {
52
+ display: flex;
53
+ flex: 0 1 auto;
54
+ flex-wrap: nowrap;
55
+ align-items: center;
56
+ gap: 6px;
57
+ min-width: 0;
58
+ max-width: 100%;
59
+ margin-left: 0;
60
+ overflow-x: auto;
61
+ overflow-y: hidden;
62
+ overscroll-behavior-x: contain;
63
+ scrollbar-color: var(--hive-line, #232b38) transparent;
64
+ scrollbar-width: thin;
65
+ }
66
+
67
+ .hive-actions > .hive-btn {
68
+ flex: 0 0 auto;
69
+ white-space: nowrap;
70
+ }
71
+
72
+ .hive-freeze-slot:empty { display: none; }
73
+
74
+ .hive-freeze-banner {
75
+ display: flex;
76
+ flex-wrap: wrap;
77
+ align-items: center;
78
+ gap: 6px 10px;
79
+ padding: 6px 12px;
80
+ border-bottom: 1px solid color-mix(in srgb, var(--hive-warn) 45%, var(--hive-line, #232b38));
81
+ background: color-mix(in srgb, var(--hive-warn) 10%, transparent);
82
+ color: var(--hive-warn);
83
+ font-size: 11px;
84
+ line-height: 1.5;
85
+ }
86
+
87
+ .hive-freeze-text { flex: 1 1 160px; min-width: 0; }
88
+
89
+ .hive-freeze-banner .hive-btn {
90
+ flex: 0 0 auto;
91
+ padding: 3px 8px;
92
+ border-color: color-mix(in srgb, var(--hive-warn) 45%, var(--hive-line, #232b38));
93
+ background: color-mix(in srgb, var(--hive-warn) 12%, transparent);
94
+ color: var(--hive-warn);
95
+ font-size: 10.5px;
96
+ }
97
+
98
+ .hive-help-trigger {
99
+ flex: 0 0 auto;
100
+ min-width: 28px;
101
+ padding-inline: 8px;
102
+ font-weight: 700;
103
+ }
104
+
105
+ .hive-overlay { position: absolute; inset: 0; z-index: 2147483000; }
106
+ .hive-help-scrim { background: transparent; }
107
+ .hive-dialog-scrim {
108
+ display: flex;
109
+ align-items: center;
110
+ justify-content: center;
111
+ padding: 12px;
112
+ background: rgb(0 0 0 / 45%);
113
+ }
114
+
115
+ .hive-help {
116
+ position: absolute;
117
+ z-index: 2147483001;
118
+ top: 58px;
119
+ right: 12px;
120
+ width: min(360px, calc(100% - 24px));
121
+ max-height: min(70vh, 560px);
122
+ overflow: auto;
123
+ padding: 12px;
124
+ border: 1px solid var(--hive-line, #232b38);
125
+ border-radius: 12px;
126
+ background: color-mix(in srgb, var(--hive-bg, #0b0f17) 97%, var(--hive-fg, #e6edf3) 3%);
127
+ color: var(--hive-fg, #e6edf3);
128
+ box-shadow: 0 18px 48px rgb(0 0 0 / 38%);
129
+ scrollbar-color: var(--hive-line, #232b38) transparent;
130
+ scrollbar-width: thin;
131
+ color-scheme: dark;
132
+ }
133
+
134
+ .hive-help-head, .hive-dialog-head, .hive-toast-head { display: flex; align-items: flex-start; gap: 8px; }
135
+ .hive-help-title, .hive-dialog-title { margin: 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 650; line-height: 1.4; }
136
+ .hive-help-title { padding-top: 3px; }
137
+ .hive-help-head .hive-btn-ghost, .hive-dialog-head .hive-btn-ghost, .hive-toast-head .hive-btn-ghost { flex: 0 0 auto; margin-left: auto; }
138
+
139
+ .hive-help-section { margin-top: 12px; color: var(--hive-fg-faint); font-size: 9.5px; font-weight: 650; letter-spacing: 0.1em; text-transform: uppercase; }
140
+ .hive-help-action { padding: 7px 0; border-bottom: 1px solid color-mix(in srgb, var(--hive-line, #232b38) 70%, transparent); }
141
+ .hive-help-action:last-of-type { border-bottom: 0; }
142
+ .hive-help-name { color: var(--hive-fg, #e6edf3); font-size: 11.5px; font-weight: 600; }
143
+ .hive-help-desc { margin-top: 2px; color: var(--hive-fg-soft); font-size: 11px; line-height: 1.5; }
144
+ .hive-help-params { margin-top: 3px; overflow-wrap: anywhere; color: var(--hive-fg-faint); font-family: var(--hive-mono); font-size: 10px; line-height: 1.5; }
145
+ .hive-help-actionrow { margin-top: 7px; }
146
+ .hive-help-note {
147
+ margin-top: 10px;
148
+ padding: 7px 8px;
149
+ border: 1px solid color-mix(in srgb, var(--hive-warn) 40%, transparent);
150
+ border-radius: 6px;
151
+ background: color-mix(in srgb, var(--hive-warn) 10%, transparent);
152
+ color: var(--hive-warn);
153
+ font-size: 11px;
154
+ line-height: 1.5;
155
+ }
156
+ .hive-help-hint { margin-top: 10px; color: var(--hive-fg-faint); font-size: 10px; line-height: 1.5; }
157
+
158
+ .hive-dialog {
159
+ display: flex;
160
+ flex-direction: column;
161
+ width: min(560px, 100%);
162
+ max-height: 100%;
163
+ overflow: hidden;
164
+ border: 1px solid var(--hive-line, #232b38);
165
+ border-radius: 12px;
166
+ background: color-mix(in srgb, var(--hive-bg, #0b0f17) 97%, var(--hive-fg, #e6edf3) 3%);
167
+ color: var(--hive-fg, #e6edf3);
168
+ box-shadow: 0 24px 70px rgb(0 0 0 / 52%);
169
+ color-scheme: dark;
170
+ }
171
+ .hive-dialog-head { flex: 0 0 auto; padding: 12px 14px; border-bottom: 1px solid var(--hive-line, #232b38); }
172
+ .hive-dialog-head-title { min-width: 0; }
173
+ .hive-dialog-eyebrow { margin-bottom: 2px; color: var(--hive-fg-faint); font-family: var(--hive-mono); font-size: 9.5px; letter-spacing: 0.06em; text-transform: uppercase; }
174
+ .hive-dialog-body { display: flex; flex: 1 1 auto; flex-direction: column; gap: 10px; min-height: 0; padding: 14px; overflow: auto; scrollbar-color: var(--hive-line, #232b38) transparent; scrollbar-width: thin; }
175
+ .hive-dialog-foot { display: flex; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--hive-line, #232b38); }
176
+
177
+ .hive-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
178
+ .hive-field-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
179
+ .hive-field-row .hive-field { flex: 1 1 220px; }
180
+ .hive-field-row .hive-field.is-narrow { flex: 0 0 110px; }
181
+ .hive-field-label { color: var(--hive-fg-soft); font-size: 10px; font-weight: 600; letter-spacing: 0.04em; }
182
+ .hive-field-hint { color: var(--hive-fg-faint); font-size: 10px; line-height: 1.4; }
183
+ .hive-input, .hive-textarea {
184
+ width: 100%;
185
+ padding: 6px 8px;
186
+ border: 1px solid var(--hive-line, #232b38);
187
+ border-radius: 7px;
188
+ background: var(--hive-bg, #0b0f17);
189
+ color: var(--hive-fg, #e6edf3);
190
+ font: inherit;
191
+ font-size: 12px;
192
+ line-height: 1.45;
193
+ }
194
+ .hive-textarea { min-height: 76px; resize: vertical; }
195
+ .hive-input:focus-visible, .hive-textarea:focus-visible { outline: 2px solid var(--hive-accent, #58c4dc); outline-offset: 1px; }
196
+
197
+ .hive-plan-preview-head { display: flex; align-items: baseline; gap: 6px; color: var(--hive-fg-soft); font-size: 10px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }
198
+ .hive-plan-count { color: var(--hive-fg-faint); font-family: var(--hive-mono); font-weight: 400; letter-spacing: 0; }
199
+ .hive-plan-list { display: flex; flex-direction: column; gap: 6px; }
200
+ .hive-plan-item { padding: 8px 9px; border: 1px solid var(--hive-line, #232b38); border-radius: 8px; background: var(--hive-surface); }
201
+ .hive-plan-item-title { overflow-wrap: anywhere; font-size: 12px; font-weight: 600; line-height: 1.35; }
202
+ .hive-plan-key { margin-left: 6px; color: var(--hive-fg-faint); font-family: var(--hive-mono); font-size: 9.5px; font-weight: 400; }
203
+ .hive-plan-meta { margin-top: 3px; overflow-wrap: anywhere; color: var(--hive-fg-soft); font-size: 10.5px; line-height: 1.5; }
204
+ .hive-plan-chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
205
+ .hive-plan-chip { max-width: 100%; overflow: hidden; padding: 1px 5px; border: 1px solid var(--hive-line, #232b38); border-radius: 4px; background: var(--hive-surface-strong); color: var(--hive-fg-soft); font-family: var(--hive-mono); font-size: 9.5px; text-overflow: ellipsis; white-space: nowrap; }
206
+ .hive-plan-empty, .hive-plan-hint { color: var(--hive-fg-faint); font-size: 10.5px; line-height: 1.5; }
207
+ .hive-plan-error { padding: 8px 9px; border-left: 2px solid var(--hive-danger); border-radius: 0 5px 5px 0; background: color-mix(in srgb, var(--hive-danger) 10%, transparent); color: color-mix(in srgb, var(--hive-danger) 82%, var(--hive-fg, #e6edf3)); font-family: var(--hive-mono); font-size: 10.5px; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
208
+ .hive-plan-error:empty { display: none; }
209
+ .hive-plan-raw { max-height: 180px; margin: 0; padding: 8px; overflow: auto; border: 1px solid var(--hive-line, #232b38); border-radius: 6px; background: var(--hive-surface); color: var(--hive-fg-soft); font-family: var(--hive-mono); font-size: 10px; line-height: 1.5; white-space: pre-wrap; }
210
+
211
+ .hive-toast {
212
+ position: absolute;
213
+ z-index: 2147483002;
214
+ right: 12px;
215
+ bottom: 12px;
216
+ width: min(380px, calc(100% - 24px));
217
+ max-height: min(42vh, 340px);
218
+ overflow: auto;
219
+ padding: 9px 11px;
220
+ border: 1px solid color-mix(in srgb, var(--hive-danger) 45%, var(--hive-line, #232b38));
221
+ border-left: 3px solid var(--hive-danger);
222
+ border-radius: 8px;
223
+ background: color-mix(in srgb, var(--hive-bg, #0b0f17) 96%, var(--hive-fg, #e6edf3) 4%);
224
+ color: var(--hive-fg, #e6edf3);
225
+ box-shadow: 0 16px 40px rgb(0 0 0 / 38%);
226
+ scrollbar-color: var(--hive-line, #232b38) transparent;
227
+ scrollbar-width: thin;
228
+ color-scheme: dark;
229
+ }
230
+ .hive-toast.is-success { border-color: color-mix(in srgb, var(--hive-ok) 45%, var(--hive-line, #232b38)); border-left-color: var(--hive-ok); }
231
+ .hive-toast-title { padding-top: 1px; font-size: 11.5px; font-weight: 650; }
232
+ .hive-toast-title.is-error { color: var(--hive-danger); }
233
+ .hive-toast-title.is-success { color: var(--hive-ok); }
234
+ .hive-toast-detail { margin-top: 3px; overflow-wrap: anywhere; color: var(--hive-fg-soft); font-family: var(--hive-mono); font-size: 10px; line-height: 1.5; white-space: pre-wrap; }
235
+
236
+ .hive-main {
237
+ display: flex;
238
+ flex: 1 1 auto;
239
+ flex-direction: column;
240
+ min-width: 0;
241
+ min-height: 0;
242
+ }
243
+
244
+ .hive-viewport {
245
+ min-width: 0;
246
+ container: hiveboard / inline-size;
247
+ }
248
+
249
+ .hive-board {
250
+ flex: 1 1 auto;
251
+ min-width: 0;
252
+ min-height: 0;
253
+ }
254
+
255
+ .hive-stage {
256
+ display: flex;
257
+ flex: 1 1 auto;
258
+ flex-direction: column;
259
+ min-width: 0;
260
+ min-height: 0;
261
+ }
262
+
263
+ .hive-agents-strip {
264
+ display: flex;
265
+ flex: 0 0 auto;
266
+ flex-wrap: wrap;
267
+ align-items: center;
268
+ gap: 6px;
269
+ min-width: 0;
270
+ padding: 7px 12px;
271
+ border-bottom: 1px solid var(--hive-line, #232b38);
272
+ background: color-mix(in srgb, var(--hive-fg, #e6edf3) 1.5%, transparent);
273
+ }
274
+
275
+ .hive-strip-label {
276
+ color: var(--hive-fg-soft);
277
+ font-size: 9.5px;
278
+ font-weight: 650;
279
+ letter-spacing: 0.12em;
280
+ text-transform: uppercase;
281
+ }
282
+
283
+ .hive-agents-strip .hive-count { margin-left: 0; }
284
+
285
+ .hive-agent-pills {
286
+ display: flex;
287
+ flex: 1 1 auto;
288
+ flex-wrap: wrap;
289
+ gap: 5px;
290
+ min-width: 0;
291
+ }
292
+
293
+ .hive-agent-pill {
294
+ display: inline-flex;
295
+ align-items: center;
296
+ gap: 6px;
297
+ max-width: 100%;
298
+ padding: 2px 8px;
299
+ border: 1px solid var(--hive-line, #232b38);
300
+ border-radius: 999px;
301
+ background: var(--hive-surface);
302
+ color: var(--hive-fg, #e6edf3);
303
+ font: inherit;
304
+ font-size: 10.5px;
305
+ line-height: 1.6;
306
+ cursor: pointer;
307
+ }
308
+
309
+ .hive-agent-pill:hover {
310
+ border-color: color-mix(in srgb, var(--hive-accent, #58c4dc) 50%, var(--hive-line, #232b38));
311
+ background: var(--hive-surface-hover);
312
+ }
313
+
314
+ .hive-agent-pill:focus-visible {
315
+ outline: 2px solid var(--hive-accent, #58c4dc);
316
+ outline-offset: 1px;
317
+ }
318
+
319
+ .hive-agent-pill-name {
320
+ max-width: 150px;
321
+ overflow: hidden;
322
+ font-weight: 600;
323
+ text-overflow: ellipsis;
324
+ white-space: nowrap;
325
+ }
326
+
327
+ .hive-agent-pill .hive-dot {
328
+ width: 6px;
329
+ height: 6px;
330
+ }
331
+
332
+ .hive-agent-pill-task {
333
+ max-width: 160px;
334
+ overflow: hidden;
335
+ color: var(--hive-fg-soft);
336
+ font-family: var(--hive-mono);
337
+ font-size: 9.5px;
338
+ text-overflow: ellipsis;
339
+ white-space: nowrap;
340
+ }
341
+
342
+ .hive-agents-empty {
343
+ color: var(--hive-fg-faint);
344
+ font-size: 10.5px;
345
+ }
346
+
347
+ .hive-stage-chips {
348
+ display: flex;
349
+ flex: 0 0 auto;
350
+ flex-wrap: wrap;
351
+ gap: 5px;
352
+ padding: 8px 10px 0;
353
+ }
354
+
355
+ .hive-stage-chip {
356
+ appearance: none;
357
+ padding: 2px 8px;
358
+ border: 1px solid var(--hive-line, #232b38);
359
+ border-radius: 999px;
360
+ background: var(--hive-surface);
361
+ color: var(--hive-fg-soft);
362
+ font: inherit;
363
+ font-size: 10.5px;
364
+ line-height: 1.6;
365
+ cursor: pointer;
366
+ white-space: nowrap;
367
+ }
368
+
369
+ .hive-stage-chip:hover {
370
+ border-color: color-mix(in srgb, var(--hive-accent, #58c4dc) 50%, var(--hive-line, #232b38));
371
+ }
372
+
373
+ .hive-stage-chip.is-active {
374
+ border-color: color-mix(in srgb, var(--hive-accent, #58c4dc) 55%, transparent);
375
+ background: var(--hive-accent-soft);
376
+ color: var(--hive-accent, #58c4dc);
377
+ }
378
+
379
+ .hive-stage-chip:focus-visible {
380
+ outline: 2px solid var(--hive-accent, #58c4dc);
381
+ outline-offset: 1px;
382
+ }
383
+
384
+ .hive-lanes {
385
+ display: flex;
386
+ flex: 1 1 auto;
387
+ flex-direction: column;
388
+ gap: 8px;
389
+ min-width: 0;
390
+ min-height: 0;
391
+ padding: 10px;
392
+ overflow-x: hidden;
393
+ overflow-y: auto;
394
+ }
395
+
396
+ .hive-lane {
397
+ display: contents;
398
+ }
399
+
400
+ .hive-lane-head {
401
+ display: none;
402
+ }
403
+
404
+ .hive-lane-cards {
405
+ display: flex;
406
+ flex: 0 0 auto;
407
+ flex-direction: column;
408
+ gap: 7px;
409
+ min-width: 0;
410
+ min-height: 0;
411
+ padding: 0;
412
+ overflow: visible;
413
+ }
414
+
415
+ .hive-card {
416
+ width: 100%;
417
+ min-width: 0;
418
+ }
419
+
420
+ .hive-filter-empty {
421
+ display: none;
422
+ flex: 0 0 auto;
423
+ padding: 16px 10px;
424
+ color: var(--hive-fg-faint);
425
+ font-size: 11px;
426
+ text-align: center;
427
+ }
428
+
429
+ .hive-filter-empty.is-visible { display: block; }
430
+
431
+ .hive-events-drawer {
432
+ flex: 0 0 auto;
433
+ min-width: 0;
434
+ border-top: 1px solid var(--hive-line, #232b38);
435
+ background: color-mix(in srgb, var(--hive-fg, #e6edf3) 1.5%, transparent);
436
+ }
437
+
438
+ .hive-events-toggle {
439
+ display: flex;
440
+ align-items: center;
441
+ gap: 7px;
442
+ width: 100%;
443
+ padding: 6px 12px;
444
+ border: 0;
445
+ background: transparent;
446
+ color: var(--hive-fg-soft);
447
+ font: inherit;
448
+ font-size: 10px;
449
+ font-weight: 650;
450
+ letter-spacing: 0.12em;
451
+ line-height: 1.6;
452
+ text-align: left;
453
+ text-transform: uppercase;
454
+ cursor: pointer;
455
+ }
456
+
457
+ .hive-events-toggle:hover { background: var(--hive-surface); }
458
+
459
+ .hive-events-toggle:focus-visible {
460
+ outline: 2px solid var(--hive-accent, #58c4dc);
461
+ outline-offset: -2px;
462
+ }
463
+
464
+ .hive-events-title { min-width: 0; }
465
+
466
+ .hive-events-count {
467
+ margin-left: auto;
468
+ color: var(--hive-fg-faint);
469
+ font-family: var(--hive-mono);
470
+ font-size: 10px;
471
+ font-weight: 400;
472
+ letter-spacing: 0;
473
+ }
474
+
475
+ .hive-events-caret {
476
+ color: var(--hive-fg-faint);
477
+ font-size: 10px;
478
+ }
479
+
480
+ .hive-event-list {
481
+ display: flex;
482
+ flex: 0 0 auto;
483
+ flex-direction: column;
484
+ gap: 4px;
485
+ max-height: none;
486
+ min-height: 0;
487
+ padding: 0 10px 9px;
488
+ overflow: visible;
489
+ }
490
+
491
+ .hive-events-drawer.is-open .hive-event-list {
492
+ max-height: 38vh;
493
+ overflow-x: hidden;
494
+ overflow-y: auto;
495
+ }
496
+
497
+ .hive-events-drawer.is-open .hive-events-toggle {
498
+ color: var(--hive-fg, #e6edf3);
499
+ }
500
+
501
+ @container hiveboard (max-width: 899px) {
502
+ .hive-lane.is-empty,
503
+ .hive-lane.is-filtered-out { display: none; }
504
+
505
+ .hive-hint { display: none; }
506
+ }
507
+
508
+ @container hiveboard (min-width: 900px) {
509
+ .hive-stage-chips { display: none; }
510
+ .hive-filter-empty,
511
+ .hive-filter-empty.is-visible { display: none; }
512
+ .hive-lanes {
513
+ display: grid;
514
+ grid-template-columns: repeat(5, minmax(0, 1fr));
515
+ align-items: stretch;
516
+ gap: 9px;
517
+ overflow: hidden;
518
+ }
519
+ .hive-lane {
520
+ display: flex;
521
+ flex-direction: column;
522
+ min-width: 0;
523
+ min-height: 0;
524
+ overflow: hidden;
525
+ }
526
+ .hive-lane-head { display: flex; }
527
+ .hive-lane-cards {
528
+ display: flex;
529
+ flex: 1 1 auto;
530
+ flex-direction: column;
531
+ gap: 7px;
532
+ padding: 7px;
533
+ overflow-x: hidden;
534
+ overflow-y: auto;
535
+ }
536
+ .hive-hint { display: inline; }
537
+ }
538
+
539
+ .hive-init-pane {
540
+ display: none;
541
+ flex: 1 1 auto;
542
+ align-items: center;
543
+ justify-content: center;
544
+ min-width: 0;
545
+ min-height: 0;
546
+ padding: 20px;
547
+ overflow: auto;
548
+ }
549
+
550
+ .hive.is-uninitialised .hive-init-pane { display: flex; }
551
+
552
+ .hive.is-uninitialised .hive-agents-strip,
553
+ .hive.is-uninitialised .hive-board,
554
+ .hive.is-uninitialised .hive-events-drawer,
555
+ .hive.is-uninitialised .hive-freeze-slot,
556
+ .hive.is-uninitialised .hive-queen-hint { display: none; }
557
+
558
+ .hive-init-card {
559
+ width: min(520px, 100%);
560
+ padding: 20px;
561
+ border: 1px solid var(--hive-line, #232b38);
562
+ border-radius: 14px;
563
+ background: color-mix(in srgb, var(--hive-bg, #0b0f17) 96%, var(--hive-fg, #e6edf3) 4%);
564
+ color: var(--hive-fg, #e6edf3);
565
+ box-shadow: 0 18px 50px rgb(0 0 0 / 28%);
566
+ }
567
+
568
+ .hive-init-repo-row {
569
+ display: flex;
570
+ align-items: baseline;
571
+ gap: 8px;
572
+ min-width: 0;
573
+ color: var(--hive-fg-soft);
574
+ }
575
+
576
+ .hive-init-repo-label {
577
+ flex: 0 0 auto;
578
+ font-size: 9.5px;
579
+ font-weight: 650;
580
+ letter-spacing: 0.1em;
581
+ text-transform: uppercase;
582
+ }
583
+
584
+ .hive-init-repo {
585
+ min-width: 0;
586
+ overflow-wrap: anywhere;
587
+ color: var(--hive-fg, #e6edf3);
588
+ font-family: var(--hive-mono);
589
+ font-size: 11px;
590
+ }
591
+
592
+ .hive-init-title {
593
+ margin: 10px 0 0;
594
+ font-size: 16px;
595
+ font-weight: 650;
596
+ line-height: 1.35;
597
+ }
598
+
599
+ .hive-init-description {
600
+ margin: 6px 0 0;
601
+ color: var(--hive-fg-soft);
602
+ font-size: 11.5px;
603
+ line-height: 1.55;
604
+ }
605
+
606
+ .hive-init-button { margin-top: 14px; }
607
+
608
+ .hive-init-button:disabled {
609
+ opacity: 0.55;
610
+ cursor: not-allowed;
611
+ }
612
+
613
+ .hive-init-readonly {
614
+ margin-top: 8px;
615
+ color: var(--hive-warn);
616
+ font-size: 11px;
617
+ line-height: 1.5;
618
+ }
619
+
620
+ .hive-init-progress {
621
+ display: flex;
622
+ align-items: center;
623
+ gap: 7px;
624
+ margin-top: 10px;
625
+ color: var(--hive-accent, #58c4dc);
626
+ font-size: 11px;
627
+ line-height: 1.5;
628
+ }
629
+
630
+ .hive-spinner {
631
+ width: 12px;
632
+ height: 12px;
633
+ flex: 0 0 auto;
634
+ border: 2px solid color-mix(in srgb, var(--hive-accent, #58c4dc) 25%, transparent);
635
+ border-top-color: var(--hive-accent, #58c4dc);
636
+ border-radius: 50%;
637
+ animation: hive-spin 0.8s linear infinite;
638
+ }
639
+
640
+ @keyframes hive-spin {
641
+ to { transform: rotate(360deg); }
642
+ }
643
+
644
+ .hive-init-error {
645
+ margin-top: 10px;
646
+ padding: 8px 9px;
647
+ border-left: 2px solid var(--hive-danger);
648
+ border-radius: 0 5px 5px 0;
649
+ background: color-mix(in srgb, var(--hive-danger) 10%, transparent);
650
+ color: color-mix(in srgb, var(--hive-danger) 82%, var(--hive-fg, #e6edf3));
651
+ font-family: var(--hive-mono);
652
+ font-size: 10.5px;
653
+ line-height: 1.5;
654
+ overflow-wrap: anywhere;
655
+ white-space: pre-wrap;
656
+ }
657
+
658
+ .hive-init-output {
659
+ margin-top: 10px;
660
+ border: 1px solid var(--hive-line, #232b38);
661
+ border-radius: 7px;
662
+ background: var(--hive-surface);
663
+ }
664
+
665
+ .hive-output-summary {
666
+ padding: 6px 8px;
667
+ color: var(--hive-fg-soft);
668
+ font-size: 10px;
669
+ line-height: 1.5;
670
+ cursor: pointer;
671
+ user-select: none;
672
+ }
673
+
674
+ .hive-output-pre {
675
+ max-height: 160px;
676
+ margin: 0;
677
+ padding: 8px;
678
+ overflow: auto;
679
+ color: var(--hive-fg-soft);
680
+ font-family: var(--hive-mono);
681
+ font-size: 10px;
682
+ line-height: 1.5;
683
+ overflow-wrap: anywhere;
684
+ white-space: pre-wrap;
685
+ }
686
+
687
+ .hive-init-output.is-hidden,
688
+ .hive-init-readonly.is-hidden,
689
+ .hive-init-progress.is-hidden,
690
+ .hive-init-error.is-hidden { display: none; }
691
+
692
+ .hive-queen-hint {
693
+ display: none;
694
+ flex: 0 0 auto;
695
+ flex-direction: column;
696
+ gap: 4px;
697
+ padding: 10px 16px;
698
+ border-bottom: 1px solid color-mix(in srgb, var(--hive-accent, #58c4dc) 32%, var(--hive-line, #232b38));
699
+ background: var(--hive-accent-soft);
700
+ color: var(--hive-accent, #58c4dc);
701
+ font-size: 10.5px;
702
+ line-height: 1.55;
703
+ }
704
+
705
+ .hive-queen-hint.is-visible { display: flex; }
706
+ .hive-queen-badge {
707
+ padding: 2px 8px;
708
+ border: 1px solid var(--hive-line, #232b38);
709
+ border-radius: 999px;
710
+ font-size: 10px;
711
+ font-weight: 650;
712
+ letter-spacing: 0.09em;
713
+ line-height: 1.5;
714
+ text-transform: uppercase;
715
+ white-space: nowrap;
716
+ }
717
+
718
+ .hive-queen-badge.is-hidden { display: none; }
719
+
720
+ .hive-queen-badge.is-active {
721
+ border-color: color-mix(in srgb, var(--hive-accent, #58c4dc) 45%, transparent);
722
+ background: var(--hive-accent-soft);
723
+ color: var(--hive-accent, #58c4dc);
724
+ }
725
+
726
+ .hive-queen-badge.is-inactive {
727
+ border-color: var(--hive-line, #232b38);
728
+ background: var(--hive-surface);
729
+ color: var(--hive-fg-soft);
730
+ }
731
+
732
+ .hive-queen-hint.is-offer {
733
+ border-bottom-color: var(--hive-line, #232b38);
734
+ background: var(--hive-surface);
735
+ color: var(--hive-fg-soft);
736
+ }
737
+
738
+ .hive-queen-offer {
739
+ display: flex;
740
+ flex-wrap: wrap;
741
+ align-items: center;
742
+ gap: 8px;
743
+ max-width: 76ch;
744
+ }
745
+
746
+ .hive-queen-offer.is-hidden,
747
+ .hive-queen-exit.is-hidden { display: none; }
748
+
749
+ .hive-queen-takeover {
750
+ border-color: color-mix(in srgb, var(--hive-accent, #58c4dc) 45%, var(--hive-line, #232b38));
751
+ background: var(--hive-accent-soft);
752
+ color: var(--hive-accent, #58c4dc);
753
+ }
754
+
755
+ .hive-queen-takeover:disabled {
756
+ opacity: 0.6;
757
+ cursor: wait;
758
+ }
759
+
760
+
761
+
762
+ .hive-queen-text {
763
+ max-width: 76ch;
764
+ overflow-wrap: anywhere;
765
+ }
766
+
767
+ .hive-queen-exit {
768
+ display: flex;
769
+ flex-wrap: wrap;
770
+ align-items: baseline;
771
+ gap: 5px;
772
+ max-width: 76ch;
773
+ color: color-mix(in srgb, var(--hive-accent, #58c4dc) 80%, var(--hive-fg, #e6edf3));
774
+ }
775
+
776
+ .hive-queen-command {
777
+ padding: 1px 6px;
778
+ border: 1px solid color-mix(in srgb, var(--hive-accent, #58c4dc) 30%, var(--hive-line, #232b38));
779
+ border-radius: 4px;
780
+ background: color-mix(in srgb, var(--hive-fg, #e6edf3) 10%, transparent);
781
+ color: var(--hive-fg, #e6edf3);
782
+ font-family: var(--hive-mono);
783
+ font-size: 10px;
784
+ line-height: 1.5;
785
+ cursor: text;
786
+ user-select: text;
787
+ }
788
+
789
+ .hive-queen-output {
790
+ margin-top: 6px;
791
+ border-color: color-mix(in srgb, var(--hive-accent, #58c4dc) 32%, var(--hive-line, #232b38));
792
+ background: color-mix(in srgb, var(--hive-bg, #0b0f17) 80%, transparent);
793
+ }
794
+
795
+ .hive-queen-output .hive-output-summary { color: var(--hive-accent, #58c4dc); }
796
+ .hive-queen-output .hive-output-pre { max-height: 120px; }
797
+
798
+ .hive-supervisor {
799
+ display: flex;
800
+ flex: 0 0 auto;
801
+ flex-wrap: wrap;
802
+ align-items: center;
803
+ gap: 5px 8px;
804
+ min-width: 0;
805
+ padding: 6px 12px;
806
+ border-bottom: 1px solid var(--hive-line, #232b38);
807
+ background: color-mix(in srgb, var(--hive-fg, #e6edf3) 2%, transparent);
808
+ font-size: 10.5px;
809
+ }
810
+
811
+ .hive-supervisor.is-hidden { display: none; }
812
+
813
+ .hive-supervisor-label {
814
+ color: var(--hive-fg-soft);
815
+ font-size: 9.5px;
816
+ font-weight: 650;
817
+ letter-spacing: 0.12em;
818
+ text-transform: uppercase;
819
+ }
820
+
821
+ .hive-supervisor-repos {
822
+ display: flex;
823
+ flex: 1 1 auto;
824
+ flex-wrap: wrap;
825
+ gap: 5px;
826
+ min-width: 0;
827
+ }
828
+
829
+ .hive-supervisor-item {
830
+ display: inline-flex;
831
+ align-items: center;
832
+ gap: 5px;
833
+ max-width: 100%;
834
+ padding: 1px 7px;
835
+ border: 1px solid var(--hive-line, #232b38);
836
+ border-radius: 999px;
837
+ background: var(--hive-surface);
838
+ }
839
+
840
+ .hive-supervisor-path {
841
+ max-width: 170px;
842
+ overflow: hidden;
843
+ color: var(--hive-fg-soft);
844
+ font-family: var(--hive-mono);
845
+ font-size: 9.5px;
846
+ text-overflow: ellipsis;
847
+ white-space: nowrap;
848
+ }
849
+
850
+ .hive-supervisor-state {
851
+ font-size: 9.5px;
852
+ font-weight: 600;
853
+ white-space: nowrap;
854
+ }
855
+
856
+ .hive-supervisor-state.is-running { color: var(--hive-ok); }
857
+ .hive-supervisor-state.is-idle { color: var(--hive-fg-soft); }
858
+ .hive-supervisor-state.is-backoff { color: var(--hive-warn); }
859
+ .hive-supervisor-state.is-paused { color: var(--hive-danger); }
860
+
861
+ .hive-supervisor-resume {
862
+ margin-left: 2px;
863
+ padding: 2px 6px;
864
+ font-size: 9.5px;
865
+ line-height: 1.3;
866
+ }
867
+
868
+ .hive-supervisor-limits {
869
+ flex: 0 0 auto;
870
+ margin-left: auto;
871
+ padding: 2px 7px;
872
+ font-size: 9.5px;
873
+ line-height: 1.4;
874
+ }
875
+
876
+ .hive-supervisor-limits.is-hidden { display: none; }
877
+
878
+ .hive-limits-repo {
879
+ display: flex;
880
+ flex-wrap: wrap;
881
+ align-items: baseline;
882
+ gap: 6px;
883
+ min-width: 0;
884
+ }
885
+
886
+ .hive-limits-repo-label {
887
+ color: var(--hive-fg-faint);
888
+ font-size: 9.5px;
889
+ font-weight: 650;
890
+ letter-spacing: 0.1em;
891
+ text-transform: uppercase;
892
+ }
893
+
894
+ .hive-limits-repo-path {
895
+ overflow-wrap: anywhere;
896
+ color: var(--hive-fg, #e6edf3);
897
+ font-family: var(--hive-mono);
898
+ font-size: 10px;
899
+ }
900
+
901
+ .hive-limits-description {
902
+ color: var(--hive-fg-soft);
903
+ font-size: 10.5px;
904
+ line-height: 1.5;
905
+ }
906
+
907
+ .hive-limits-table {
908
+ display: flex;
909
+ flex-direction: column;
910
+ gap: 2px;
911
+ min-width: 0;
912
+ }
913
+
914
+ .hive-limits-row {
915
+ display: grid;
916
+ grid-template-columns: minmax(0, 1fr) 72px 48px 48px;
917
+ align-items: center;
918
+ gap: 6px;
919
+ min-width: 0;
920
+ padding: 3px 0;
921
+ border-top: 1px solid color-mix(in srgb, var(--hive-line, #232b38) 70%, transparent);
922
+ }
923
+
924
+ .hive-limits-row.is-head {
925
+ padding: 0 0 2px;
926
+ border-top: 0;
927
+ color: var(--hive-fg-faint);
928
+ font-size: 9px;
929
+ letter-spacing: 0.06em;
930
+ text-transform: uppercase;
931
+ }
932
+
933
+ .hive-limits-cell { min-width: 0; }
934
+ .hive-limits-cell.is-number { text-align: right; color: var(--hive-fg-soft); font-family: var(--hive-mono); font-size: 10px; }
935
+
936
+ .hive-limits-role {
937
+ overflow: hidden;
938
+ color: var(--hive-fg, #e6edf3);
939
+ font-family: var(--hive-mono);
940
+ font-size: 10.5px;
941
+ text-overflow: ellipsis;
942
+ white-space: nowrap;
943
+ }
944
+
945
+ .hive-limits-input {
946
+ width: 100%;
947
+ padding: 4px 5px;
948
+ font-family: var(--hive-mono);
949
+ font-size: 10.5px;
950
+ text-align: right;
951
+ }
952
+
953
+ .hive-limits-hint {
954
+ color: var(--hive-fg-faint);
955
+ font-size: 9.5px;
956
+ line-height: 1.4;
957
+ }
958
+
959
+ .hive-limits-empty {
960
+ color: var(--hive-fg-faint);
961
+ font-size: 10.5px;
962
+ line-height: 1.5;
963
+ }
964
+
965
+ .hive-limits-error {
966
+ padding: 8px 9px;
967
+ border-left: 2px solid var(--hive-danger);
968
+ border-radius: 0 5px 5px 0;
969
+ background: color-mix(in srgb, var(--hive-danger) 10%, transparent);
970
+ color: color-mix(in srgb, var(--hive-danger) 82%, var(--hive-fg, #e6edf3));
971
+ font-family: var(--hive-mono);
972
+ font-size: 10.5px;
973
+ line-height: 1.5;
974
+ overflow-wrap: anywhere;
975
+ white-space: pre-wrap;
976
+ }
977
+
978
+ .hive-limits-error.is-hidden { display: none; }
979
+
980
+ .hive-status {
981
+ padding: 2px 8px;
982
+ border: 1px solid color-mix(in srgb, var(--hive-danger) 40%, var(--hive-line, #232b38));
983
+ border-radius: 999px;
984
+ background: color-mix(in srgb, var(--hive-danger) 9%, transparent);
985
+ }
986
+
987
+ .hive-field-hint {
988
+ padding: 4px 7px;
989
+ border: 1px solid color-mix(in srgb, var(--hive-line, #232b38) 70%, transparent);
990
+ border-radius: 5px;
991
+ background: var(--hive-surface);
992
+ line-height: 1.5;
993
+ }
994
+
995
+ .hive-oldest {
996
+ max-width: 100%;
997
+ overflow-wrap: anywhere;
998
+ white-space: normal;
999
+ }
1000
+
1001
+ .hive-oldest-label { min-width: 0; }
1002
+
1003
+ .hive-oldest-sep { opacity: 0.65; }
1004
+
1005
+ .hive-oldest-id {
1006
+ font-family: var(--hive-mono);
1007
+ font-size: 9.5px;
1008
+ font-weight: 400;
1009
+ overflow-wrap: anywhere;
1010
+ }
1011
+
1012
+ /* -------------------------------------------------------------------- spacing */
1013
+ .hive {
1014
+ gap: 8px;
1015
+ padding: 16px;
1016
+ line-height: 1.5;
1017
+ overflow-wrap: anywhere;
1018
+ }
1019
+
1020
+ .hive-bar { padding: 12px 16px; }
1021
+ .hive-main { gap: 8px; }
1022
+ .hive-supervisor { padding: 10px 16px; }
1023
+ .hive-freeze-banner { padding: 10px 16px; }
1024
+ .hive-agents-strip { padding: 10px 16px; }
1025
+ .hive-stage-chips { padding: 10px 16px 0; }
1026
+ .hive-lanes { gap: 10px; padding: 12px 16px; }
1027
+ .hive-lane-cards { gap: 9px; }
1028
+ .hive-card { padding: 10px 12px; }
1029
+ .hive-events-toggle { padding: 10px 16px; }
1030
+ .hive-event-list { gap: 6px; padding: 0 16px 12px; }
1031
+ .hive-event { padding: 8px 10px; }
1032
+ .hive-dialog-head { padding: 16px; }
1033
+ .hive-dialog-body { gap: 12px; padding: 16px; }
1034
+ .hive-dialog-foot { padding: 12px 16px; }
1035
+ .hive-help { padding: 16px; }
1036
+ .hive-drawer-head, .hive-drawer-body { padding: 16px; }
1037
+ .hive-plan-list { gap: 8px; }
1038
+ .hive-plan-item { padding: 10px 12px; }
1039
+ .hive-init-pane { padding: 20px; }
1040
+ .hive-init-card { padding: 20px; }
1041
+ .hive-init-description,
1042
+ .hive-help-desc,
1043
+ .hive-help-hint,
1044
+ .hive-plan-meta,
1045
+ .hive-plan-hint,
1046
+ .hive-limits-description,
1047
+ .hive-limits-hint,
1048
+ .hive-queen-text,
1049
+ .hive-queen-exit { max-width: 76ch; line-height: 1.55; }
1050
+
1051
+ .hive-empty,
1052
+ .hive-filter-empty,
1053
+ .hive-agents-empty {
1054
+ padding: 12px 14px;
1055
+ border: 1px solid var(--hive-line, #232b38);
1056
+ border-radius: 8px;
1057
+ background: var(--hive-surface);
1058
+ color: var(--hive-fg-soft);
1059
+ font-size: 10.5px;
1060
+ line-height: 1.55;
1061
+ text-align: left;
1062
+ }
1063
+
1064
+ .hive-plan-empty,
1065
+ .hive-help-hint,
1066
+ .hive-plan-hint,
1067
+ .hive-limits-hint,
1068
+ .hive-note {
1069
+ padding: 8px 10px;
1070
+ border: 1px solid color-mix(in srgb, var(--hive-line, #232b38) 80%, transparent);
1071
+ border-radius: 6px;
1072
+ background: var(--hive-surface);
1073
+ color: var(--hive-fg-soft);
1074
+ font-size: 10.5px;
1075
+ line-height: 1.55;
1076
+ }
1077
+
1078
+ .hive-init-readonly {
1079
+ padding: 8px 10px;
1080
+ border: 1px solid color-mix(in srgb, var(--hive-warn) 38%, var(--hive-line, #232b38));
1081
+ border-radius: 6px;
1082
+ background: color-mix(in srgb, var(--hive-warn) 9%, transparent);
1083
+ line-height: 1.55;
1084
+ }
1085
+
1086
+ @media (max-width: 520px) {
1087
+ .hive { gap: 6px; padding: 12px; }
1088
+ .hive-bar,
1089
+ .hive-supervisor,
1090
+ .hive-freeze-banner,
1091
+ .hive-queen-hint,
1092
+ .hive-agents-strip,
1093
+ .hive-events-toggle,
1094
+ .hive-dialog-head,
1095
+ .hive-dialog-body,
1096
+ .hive-help,
1097
+ .hive-drawer-head,
1098
+ .hive-drawer-body { padding-left: 12px; padding-right: 12px; }
1099
+ .hive-dialog-foot { padding-left: 12px; padding-right: 12px; }
1100
+ .hive-stage-chips { padding: 10px 12px 0; }
1101
+ .hive-lanes { padding: 12px; }
1102
+ .hive-event-list { padding: 0 12px 10px; }
1103
+ .hive-init-pane { padding: 12px; }
1104
+ .hive-init-card { padding: 16px; }
1105
+ .hive-dialog-scrim { padding: 8px; }
1106
+ .hive-dialog-foot { justify-content: stretch; }
1107
+ .hive-dialog-foot .hive-btn { flex: 1 1 auto; }
1108
+ .hive-help { right: 8px; width: calc(100% - 16px); max-height: 66vh; }
1109
+ .hive-toast { right: 8px; bottom: 8px; width: calc(100% - 16px); }
1110
+ }`;
1111
+
1112
+ const LANE_LABEL_KEYS = Object.freeze({
1113
+ pending: "lane.pending",
1114
+ claimed: "lane.claimed",
1115
+ done: "lane.done",
1116
+ blocked: "lane.blocked",
1117
+ failed: "lane.failed",
1118
+ });
1119
+
1120
+ /**
1121
+ * Built-in dictionaries. The panel defaults to English; hosts that own a
1122
+ * locale service should reuse these (or pass a \`t\` bound to their own copy).
1123
+ * Both dictionaries carry the same key set.
1124
+ */
1125
+ export const messages = Object.freeze({
1126
+ en: Object.freeze({
1127
+ "view.label": "Hive",
1128
+ "actions.aria": "board actions",
1129
+ "action.add": "New task",
1130
+ "action.claim": "claim",
1131
+ "action.commit": "commit",
1132
+ "action.done": "done",
1133
+ "action.fail": "fail",
1134
+ "action.freeze": "freeze",
1135
+ "action.modeTitle": "Toggle board mode",
1136
+ "action.retry": "retry",
1137
+ "action.unfreeze": "unfreeze",
1138
+ "pane.agents": "workers",
1139
+ "pane.board": "board",
1140
+ "pane.events": "events",
1141
+ "board.hint": "5 lanes",
1142
+ "board.filtersAria": "Filter by state",
1143
+ "board.all": "all",
1144
+ "board.showAll": "Show all tasks",
1145
+ "board.filterChip": "Show {lane} tasks ({count})",
1146
+ "board.emptyFilter": "No tasks in this state.",
1147
+ "lane.pending": "pending",
1148
+ "lane.claimed": "claimed",
1149
+ "lane.done": "done",
1150
+ "lane.blocked": "blocked",
1151
+ "lane.failed": "failed",
1152
+ "mode.free": "free",
1153
+ "mode.freeze": "freeze",
1154
+ "mode.free.help": "Free: anyone can claim tasks.",
1155
+ "mode.freeze.help": "Freeze: only tasks tagged fix can be claimed; use this while the pipeline is red.",
1156
+ "mode.freeze.banner": "Frozen: only tasks tagged fix can be claimed.",
1157
+ "mode.title": "mode:",
1158
+ "stats.cards": "tasks",
1159
+ "stats.oldest": "oldest",
1160
+ "stats.duration.justNow": "just now",
1161
+ "stats.duration.minute": "{count} min",
1162
+ "stats.duration.minutes": "{count} min",
1163
+ "stats.duration.hour": "{count} hr",
1164
+ "stats.duration.hours": "{count} hr",
1165
+ "stats.duration.day": "{count} day",
1166
+ "stats.duration.days": "{count} days",
1167
+ "stats.byRoleTitle": "by role: ",
1168
+ "status.actionFailed": "action failed",
1169
+ "status.disconnected": "disconnected",
1170
+ "agents.empty": "No workers in the background.",
1171
+ "agents.openAria": "Open worker",
1172
+ "agent.idle": "idle",
1173
+ "agent.task": "task",
1174
+ "agent.unknown": "unknown",
1175
+ "agent.seen": "seen",
1176
+ "card.untitled": "(untitled)",
1177
+ "card.noId": "no id",
1178
+ "card.openAria": "Open task",
1179
+ "card.role": "role",
1180
+ "card.owner": "owner",
1181
+ "drawer.close": "close",
1182
+ "drawer.closeAria": "Close details",
1183
+ "drawer.cardAria": "Task",
1184
+ "drawer.cardActions": "task actions",
1185
+ "drawer.noActions": "No actions for this state.",
1186
+ "drawer.readOnly": "Read-only: writable=false.",
1187
+ "drawer.rawJson": "raw json",
1188
+ "events.empty": "No events yet.",
1189
+ "events.showAll": "Show all events",
1190
+ "events.collapse": "Collapse events",
1191
+ "supervisor.aria": "Supervisor status",
1192
+ "supervisor.label": "supervisor",
1193
+ "supervisor.running": "running",
1194
+ "supervisor.runningCount": "running {count}",
1195
+ "supervisor.idle": "idle",
1196
+ "supervisor.backoff": "backoff",
1197
+ "supervisor.paused": "paused",
1198
+ "supervisor.resume": "resume",
1199
+ "supervisor.resumeAria": "Resume the supervisor for {repo}",
1200
+ "supervisor.resumeFailed": "Could not resume the supervisor",
1201
+ "limits.open": "Settings",
1202
+ "limits.openAria": "Configure bee counts for this repository",
1203
+ "limits.title": "Bee counts",
1204
+ "limits.aria": "Bee counts for this repository",
1205
+ "limits.description": "Concurrency limit per role. 0 pauses that role. Default 5.",
1206
+ "limits.role": "Role",
1207
+ "limits.limit": "Limit",
1208
+ "limits.inFlight": "In flight",
1209
+ "limits.queued": "Queued",
1210
+ "limits.defaultHint": "0-999, default 5",
1211
+ "limits.limitAria": "Concurrency limit for {role}",
1212
+ "limits.save": "Save",
1213
+ "limits.saveAria": "Save bee counts for {repo}",
1214
+ "limits.saving": "Saving...",
1215
+ "limits.saved": "Bee counts saved.",
1216
+ "limits.failed": "Could not save bee counts",
1217
+ "limits.invalid": "Every limit must be an integer from 0 to 999.",
1218
+ "limits.none": "No role data for this repository.",
1219
+ "limits.close": "Close",
1220
+ "limits.closeAria": "Close bee count settings",
1221
+ "event.unknown": "event",
1222
+ "prompt.newTitle": "New task title",
1223
+ "prompt.role": "Role",
1224
+ "prompt.scope": "Scope (comma separated, optional)",
1225
+ "prompt.after": "After task ids (comma separated, optional)",
1226
+ "prompt.commitMessage": "Commit message",
1227
+ "prompt.paths": "Paths (comma separated, optional)",
1228
+ "prompt.claimAgent": "Claim as worker",
1229
+ "prompt.commitSha": "Commit sha (optional)",
1230
+ "prompt.failReason": "Failure reason",
1231
+ "action.plan": "Give the Queen a goal",
1232
+ "help.open": "What these buttons do",
1233
+ "menu.open": "More actions and help",
1234
+ "help.title": "Button guide",
1235
+ "help.aria": "Action guide",
1236
+ "help.close": "close",
1237
+ "help.closeAria": "Close the button guide",
1238
+ "help.board": "board actions",
1239
+ "help.tasks": "task actions",
1240
+ "help.params": "Parameters: ",
1241
+ "help.readOnly": "The panel started read-only; add --write to show the write-action buttons.",
1242
+ "help.uninitialised": "Initialise Hive with the button in the main area before using board actions.",
1243
+ "init.repo": "repository",
1244
+ "init.title": "This repo hasn't been initialised for Hive.",
1245
+ "init.description": "Initialising writes the role files, hooks and task refs this board reads, and turns this session into the swarm: the Queen splits the goal, and the swarm keeps taking tasks until they are done — as long as the DSH process stays up.",
1246
+ "init.button": "Initialise Hive",
1247
+ "init.buttonAria": "Initialise Hive in this repository",
1248
+ "init.busy": "Initialising Hive…",
1249
+ "init.readOnly": "Read-only mode cannot initialise; enable writes on the host first.",
1250
+ "init.readOnlyAria": "Initialisation is disabled in read-only mode",
1251
+ "init.failed": "Initialisation failed",
1252
+ "init.output": "stdout",
1253
+ "init.noOutput": "(no output)",
1254
+ "init.queen": "This session's input now routes to the Queen (it splits tasks, it does not do the work).",
1255
+ "init.queenExit": "Exit from the chat window:",
1256
+ "init.queenCommand": "/queen off",
1257
+ "init.queenOutput": "Initialisation output",
1258
+ "queen.status.active": "Queen active",
1259
+ "queen.status.inactive": "Queen not active",
1260
+ "queen.source.auto": "auto",
1261
+ "queen.source.manual": "manual",
1262
+ "queen.activeTitle": "Queen mode is active ({source})",
1263
+ "queen.inactiveTitle": "The Queen has not taken over this session",
1264
+ "queen.offer": "The Queen has not taken over this session.",
1265
+ "queen.takeover": "Let the Queen take over",
1266
+ "queen.takeoverAria": "Let the Queen take over this session",
1267
+ "queen.takeoverBusy": "Taking over...",
1268
+ "help.hint": "Open a task to see the actions for that task.",
1269
+ "help.action.freeze": "Freeze: nobody can claim new tasks except tasks tagged fix.",
1270
+ "help.action.unfreeze": "Unfreeze: workers can claim pending tasks again.",
1271
+ "help.action.add": "New task: create a pending task with a role and file scope.",
1272
+ "help.action.plan": "Give the Queen a goal: split a goal into tasks, preview the plan, then write it to the board.",
1273
+ "help.action.commit": "Commit: commit the selected paths with a message.",
1274
+ "help.action.claim": "Claim: lease a pending task for a worker.",
1275
+ "help.action.done": "Done: mark a claimed task complete, optionally with a commit sha.",
1276
+ "help.action.fail": "Fail: mark a claimed task failed and record the reason.",
1277
+ "help.action.retry": "Retry: put a failed or blocked task back in the queue.",
1278
+ "help.params.mode": "mode, reason",
1279
+ "help.params.add": "title, role, scope[], after[]",
1280
+ "help.params.plan": "goal, maxCards",
1281
+ "help.params.commit": "message, set[]",
1282
+ "help.params.claim": "id, worker",
1283
+ "help.params.done": "id, sha?",
1284
+ "help.params.fail": "id, reason",
1285
+ "help.params.retry": "id",
1286
+ "plan.dialogTitle": "Give the Queen a goal",
1287
+ "plan.dialogAria": "Plan tasks from a goal",
1288
+ "plan.goal": "Goal",
1289
+ "plan.goalHint": "Describe the outcome; the Queen will split it into tasks.",
1290
+ "plan.maxCards": "Max cards",
1291
+ "plan.maxCardsHint": "1+",
1292
+ "plan.preview": "Preview plan",
1293
+ "plan.previewAria": "Ask the Queen to draft a task plan without writing it",
1294
+ "plan.previewing": "Planning…",
1295
+ "plan.write": "Write tasks",
1296
+ "plan.writing": "Writing…",
1297
+ "plan.writeAria": "Create the previewed tasks on the board",
1298
+ "plan.cancel": "Cancel",
1299
+ "plan.cancelAria": "Close without writing tasks",
1300
+ "plan.close": "close",
1301
+ "plan.closeAria": "Close the goal dialog",
1302
+ "plan.previewTitle": "Task preview",
1303
+ "plan.empty": "Describe a goal, then preview the plan.",
1304
+ "plan.emptyResult": "The planner returned no tasks.",
1305
+ "plan.raw": "Raw output",
1306
+ "plan.role": "role",
1307
+ "plan.scope": "scope",
1308
+ "plan.deps": "deps",
1309
+ "plan.none": "—",
1310
+ "plan.goalRequired": "Enter a goal first.",
1311
+ "plan.maxInvalid": "Max cards must be a positive whole number.",
1312
+ "plan.previewFirst": "Preview the plan before writing tasks.",
1313
+ "plan.previewFailed": "Could not read the plan.",
1314
+ "plan.applyHint": "The preview is read-only; writing calls plan again with apply=true.",
1315
+ "plan.stale": "The goal or max cards changed; preview the plan again.",
1316
+ "plan.error": "Plan failed",
1317
+ "toast.dismiss": "Dismiss",
1318
+ "toast.planWritten": "Tasks written",
1319
+ "toast.pickupHint": "The supervisor will pick them up automatically.",
1320
+ }),
1321
+ zh: Object.freeze({
1322
+ "view.label": "蜂群",
1323
+ "actions.aria": "看板操作",
1324
+ "action.add": "新建任务",
1325
+ "action.claim": "认领",
1326
+ "action.commit": "提交",
1327
+ "action.done": "完成",
1328
+ "action.fail": "标记失败",
1329
+ "action.freeze": "冻结",
1330
+ "action.modeTitle": "切换看板模式",
1331
+ "action.retry": "重试",
1332
+ "action.unfreeze": "解冻",
1333
+ "pane.agents": "工蜂",
1334
+ "pane.board": "任务",
1335
+ "pane.events": "事件",
1336
+ "board.hint": "5 条泳道",
1337
+ "board.filtersAria": "按状态筛选",
1338
+ "board.all": "全部",
1339
+ "board.showAll": "显示全部任务",
1340
+ "board.filterChip": "只看{lane}任务({count})",
1341
+ "board.emptyFilter": "该状态没有任务。",
1342
+ "lane.pending": "待办",
1343
+ "lane.claimed": "已认领",
1344
+ "lane.done": "已完成",
1345
+ "lane.blocked": "受阻",
1346
+ "lane.failed": "失败",
1347
+ "mode.free": "正常",
1348
+ "mode.freeze": "冻结",
1349
+ "mode.free.help": "正常:任何人都可以认领任务。",
1350
+ "mode.freeze.help": "冻结:只有带 fix 标签的任务能被认领;流水线红时使用。",
1351
+ "mode.freeze.banner": "已冻结:只有带 fix 标签的任务能被认领",
1352
+ "mode.title": "模式:",
1353
+ "stats.cards": "个任务",
1354
+ "stats.oldest": "最久待办",
1355
+ "stats.duration.justNow": "刚刚",
1356
+ "stats.duration.minute": "{count} 分钟",
1357
+ "stats.duration.minutes": "{count} 分钟",
1358
+ "stats.duration.hour": "{count} 小时",
1359
+ "stats.duration.hours": "{count} 小时",
1360
+ "stats.duration.day": "{count} 天",
1361
+ "stats.duration.days": "{count} 天",
1362
+ "stats.byRoleTitle": "按角色:",
1363
+ "status.actionFailed": "操作失败",
1364
+ "status.disconnected": "连接断开",
1365
+ "agents.empty": "后台暂无工蜂。",
1366
+ "agents.openAria": "打开工蜂",
1367
+ "agent.idle": "空闲",
1368
+ "agent.task": "任务",
1369
+ "agent.unknown": "未知",
1370
+ "agent.seen": "上次活跃",
1371
+ "card.untitled": "(无标题)",
1372
+ "card.noId": "无 ID",
1373
+ "card.openAria": "打开任务",
1374
+ "card.role": "角色",
1375
+ "card.owner": "负责人",
1376
+ "drawer.close": "关闭",
1377
+ "drawer.closeAria": "关闭详情",
1378
+ "drawer.cardAria": "任务",
1379
+ "drawer.cardActions": "任务操作",
1380
+ "drawer.noActions": "该状态没有可用操作。",
1381
+ "drawer.readOnly": "只读:writable=false。",
1382
+ "drawer.rawJson": "原始 JSON",
1383
+ "events.empty": "暂无事件。",
1384
+ "events.showAll": "展开全部事件",
1385
+ "events.collapse": "收起事件",
1386
+ "supervisor.aria": "Supervisor 状态",
1387
+ "supervisor.label": "监督器",
1388
+ "supervisor.running": "运行中",
1389
+ "supervisor.runningCount": "运行中 {count}",
1390
+ "supervisor.idle": "空闲",
1391
+ "supervisor.backoff": "退避",
1392
+ "supervisor.paused": "已暂停",
1393
+ "supervisor.resume": "恢复",
1394
+ "supervisor.resumeAria": "恢复 {repo} 的 supervisor",
1395
+ "supervisor.resumeFailed": "恢复 supervisor 失败",
1396
+ "limits.open": "设置",
1397
+ "limits.openAria": "设置这个仓库的蜂的数量",
1398
+ "limits.title": "蜂的数量",
1399
+ "limits.aria": "按仓库设置蜂的数量",
1400
+ "limits.description": "每个角色的并发上限。0 表示暂停该角色,默认 5。",
1401
+ "limits.role": "角色",
1402
+ "limits.limit": "上限",
1403
+ "limits.inFlight": "在飞",
1404
+ "limits.queued": "排队",
1405
+ "limits.defaultHint": "0–999,默认 5",
1406
+ "limits.limitAria": "{role} 的并发上限",
1407
+ "limits.save": "保存",
1408
+ "limits.saveAria": "保存 {repo} 的蜂的数量",
1409
+ "limits.saving": "正在保存…",
1410
+ "limits.saved": "蜂的数量已保存。",
1411
+ "limits.failed": "保存蜂的数量失败",
1412
+ "limits.invalid": "每个上限都必须是 0–999 的整数。",
1413
+ "limits.none": "这个仓库没有角色数据。",
1414
+ "limits.close": "关闭",
1415
+ "limits.closeAria": "关闭蜂的数量设置",
1416
+ "event.unknown": "事件",
1417
+ "prompt.newTitle": "新任务标题",
1418
+ "prompt.role": "角色",
1419
+ "prompt.scope": "范围(逗号分隔,可选)",
1420
+ "prompt.after": "排在哪些任务之后(任务 ID,逗号分隔,可选)",
1421
+ "prompt.commitMessage": "提交信息",
1422
+ "prompt.paths": "路径(逗号分隔,可选)",
1423
+ "prompt.claimAgent": "以哪个工蜂认领",
1424
+ "prompt.commitSha": "提交 SHA(可选)",
1425
+ "prompt.failReason": "失败原因",
1426
+ "action.plan": "给蜂皇下目标",
1427
+ "help.open": "这些按钮是做什么的",
1428
+ "menu.open": "更多操作与说明",
1429
+ "help.title": "按钮说明",
1430
+ "help.aria": "操作说明",
1431
+ "help.close": "关闭",
1432
+ "help.closeAria": "关闭按钮说明",
1433
+ "help.board": "看板操作",
1434
+ "help.tasks": "任务操作",
1435
+ "help.params": "参数:",
1436
+ "help.readOnly": "面板以只读启动,加 --write 才有写操作按钮。",
1437
+ "help.uninitialised": "请先用主区的按钮初始化 Hive,再使用看板操作。",
1438
+ "init.repo": "仓库",
1439
+ "init.title": "这个仓库还没初始化 Hive。",
1440
+ "init.description": "初始化后,这块看板才能读数据,同时进入蜂群模式:Hive 会写入角色文件、hooks 和任务引用,蜂皇分解任务;只要 DSH 进程不退出,蜂群会一直执行任务直到完成。",
1441
+ "init.button": "初始化 Hive",
1442
+ "init.buttonAria": "在这个仓库初始化 Hive",
1443
+ "init.busy": "正在初始化 Hive…",
1444
+ "init.readOnly": "只读模式无法初始化;请先在宿主开启写权限。",
1445
+ "init.readOnlyAria": "只读模式下不能初始化",
1446
+ "init.failed": "初始化失败",
1447
+ "init.output": "标准输出",
1448
+ "init.noOutput": "(无输出)",
1449
+ "init.queen": "本会话输入框已接入蜂皇模式(蜂皇只拆解任务,不亲自干活)。",
1450
+ "init.queenExit": "退出请在聊天窗口输入:",
1451
+ "init.queenCommand": "/queen off",
1452
+ "init.queenOutput": "初始化输出",
1453
+ "queen.status.active": "蜂皇已接管",
1454
+ "queen.status.inactive": "蜂皇未接管",
1455
+ "queen.source.auto": "自动",
1456
+ "queen.source.manual": "手动",
1457
+ "queen.activeTitle": "蜂皇模式已接管({source})",
1458
+ "queen.inactiveTitle": "蜂皇尚未接管本会话",
1459
+ "queen.offer": "蜂皇尚未接管本会话。",
1460
+ "queen.takeover": "让蜂皇接管",
1461
+ "queen.takeoverAria": "让蜂皇接管本会话",
1462
+ "queen.takeoverBusy": "正在接管…",
1463
+ "help.hint": "点开任务可查看该任务自己的操作。",
1464
+ "help.action.freeze": "冻结:除带 fix 标签的任务外,任何人都不再能认领新任务。",
1465
+ "help.action.unfreeze": "解冻:恢复认领,工蜂可以继续接取待办任务。",
1466
+ "help.action.add": "新建任务:添加一条带角色和文件范围的待办任务。",
1467
+ "help.action.plan": "给蜂皇下目标:让蜂皇把目标拆成任务计划,预览后再写入看板。",
1468
+ "help.action.commit": "提交:按提交信息提交选中的路径。",
1469
+ "help.action.claim": "认领:以某个工蜂的名义短期租下这条待办任务。",
1470
+ "help.action.done": "完成:把已认领的任务标为完成,可选填写提交 SHA。",
1471
+ "help.action.fail": "标记失败:把已认领的任务标为失败,并写明原因。",
1472
+ "help.action.retry": "重试:把失败或受阻的任务放回队列。",
1473
+ "help.params.mode": "mode、reason",
1474
+ "help.params.add": "title、role、scope[]、after[]",
1475
+ "help.params.plan": "goal、maxCards",
1476
+ "help.params.commit": "message、set[]",
1477
+ "help.params.claim": "id、工蜂",
1478
+ "help.params.done": "id、sha?",
1479
+ "help.params.fail": "id、reason",
1480
+ "help.params.retry": "id",
1481
+ "plan.dialogTitle": "给蜂皇下目标",
1482
+ "plan.dialogAria": "按目标规划任务",
1483
+ "plan.goal": "目标",
1484
+ "plan.goalHint": "描述想达成的结果,蜂皇会把它拆成任务。",
1485
+ "plan.maxCards": "最大卡数",
1486
+ "plan.maxCardsHint": "至少 1",
1487
+ "plan.preview": "预览计划",
1488
+ "plan.previewAria": "让蜂皇先给出任务计划,不写入看板",
1489
+ "plan.previewing": "规划中…",
1490
+ "plan.write": "写入任务",
1491
+ "plan.writing": "写入中…",
1492
+ "plan.writeAria": "把预览中的任务写入看板",
1493
+ "plan.cancel": "取消",
1494
+ "plan.cancelAria": "关闭对话框,不写入任务",
1495
+ "plan.close": "关闭",
1496
+ "plan.closeAria": "关闭目标对话框",
1497
+ "plan.previewTitle": "任务预览",
1498
+ "plan.empty": "先填写目标,再预览计划。",
1499
+ "plan.emptyResult": "规划器没有返回任务。",
1500
+ "plan.raw": "原始输出",
1501
+ "plan.role": "角色",
1502
+ "plan.scope": "范围",
1503
+ "plan.deps": "依赖",
1504
+ "plan.none": "—",
1505
+ "plan.goalRequired": "请先填写目标。",
1506
+ "plan.maxInvalid": "最大卡数必须是正整数。",
1507
+ "plan.previewFirst": "请先预览计划,再写入任务。",
1508
+ "plan.previewFailed": "无法解析计划。",
1509
+ "plan.applyHint": "预览不会写入;写入时会带 apply=true 再调用一次 plan。",
1510
+ "plan.stale": "目标或最大卡数已修改,请重新预览计划。",
1511
+ "plan.error": "计划失败",
1512
+ "toast.dismiss": "关闭",
1513
+ "toast.planWritten": "任务已写入",
1514
+ "toast.pickupHint": "supervisor 会自动接卡。",
1515
+ }),
1516
+ });
1517
+
1518
+ /** Alias kept for hosts that expect the plural name. */
1519
+ export const locales = messages;
1520
+
1521
+ function isRecord(value) {
1522
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1523
+ }
1524
+
1525
+ function asArray(value) {
1526
+ return Array.isArray(value) ? value : [];
1527
+ }
1528
+
1529
+ function asString(value) {
1530
+ if (value === null || value === undefined) return "";
1531
+ return typeof value === "string" ? value : String(value);
1532
+ }
1533
+
1534
+ function asCount(value, fallback = 0) {
1535
+ const number = typeof value === "number" ? value : Number(value);
1536
+ return Number.isFinite(number) ? number : fallback;
1537
+ }
1538
+
1539
+ function normalizeScope(scope) {
1540
+ if (Array.isArray(scope)) {
1541
+ return scope
1542
+ .filter((item) => item !== null && item !== undefined && String(item).trim() !== "")
1543
+ .map((item) => String(item).trim());
1544
+ }
1545
+ if (typeof scope === "string") {
1546
+ return scope.split(",").map((item) => item.trim()).filter(Boolean);
1547
+ }
1548
+ return [];
1549
+ }
1550
+
1551
+ function normalizeCard(task) {
1552
+ return {
1553
+ id: asString(task.id),
1554
+ title: asString(task.title),
1555
+ role: asString(task.role),
1556
+ owner: asString(task.owner),
1557
+ scope: normalizeScope(task.scope),
1558
+ reason: asString(task.reason),
1559
+ };
1560
+ }
1561
+
1562
+ function eventTime(event) {
1563
+ const value = event ? event.ts : null;
1564
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1565
+ if (typeof value === "string") {
1566
+ const text = value.trim();
1567
+ if (!text) return 0;
1568
+ const parsed = Date.parse(text);
1569
+ if (Number.isFinite(parsed)) return parsed;
1570
+ const numeric = Number(text);
1571
+ if (Number.isFinite(numeric)) return numeric;
1572
+ }
1573
+ return 0;
1574
+ }
1575
+
1576
+ function normalizeStats(stats, tasks) {
1577
+ const source = isRecord(stats) ? stats : {};
1578
+
1579
+ let total = asCount(source.total, Number.NaN);
1580
+ if (!Number.isFinite(total)) total = tasks.length;
1581
+
1582
+ let byState;
1583
+ if (isRecord(source.byState)) {
1584
+ byState = {};
1585
+ for (const [key, value] of Object.entries(source.byState)) {
1586
+ byState[key] = asCount(value, 0);
1587
+ }
1588
+ } else {
1589
+ byState = {};
1590
+ for (const state of LANE_ORDER) byState[state] = 0;
1591
+ for (const task of tasks) {
1592
+ const state = asString(task.state);
1593
+ if (!state) continue;
1594
+ byState[state] = (byState[state] || 0) + 1;
1595
+ }
1596
+ }
1597
+
1598
+ let byRole;
1599
+ if (isRecord(source.byRole)) {
1600
+ byRole = {};
1601
+ for (const [key, value] of Object.entries(source.byRole)) {
1602
+ byRole[key] = asCount(value, 0);
1603
+ }
1604
+ } else {
1605
+ byRole = {};
1606
+ for (const task of tasks) {
1607
+ const role = asString(task.role);
1608
+ if (!role) continue;
1609
+ byRole[role] = (byRole[role] || 0) + 1;
1610
+ }
1611
+ }
1612
+
1613
+ let oldestPending = null;
1614
+ const rawOldest = source.oldestPending;
1615
+ if (isRecord(rawOldest)) {
1616
+ const id =
1617
+ typeof rawOldest.id === "string" || typeof rawOldest.id === "number" ? String(rawOldest.id) : "";
1618
+ const createdValue =
1619
+ rawOldest.createdAt !== undefined && rawOldest.createdAt !== null
1620
+ ? rawOldest.createdAt
1621
+ : rawOldest.created !== undefined && rawOldest.created !== null
1622
+ ? rawOldest.created
1623
+ : rawOldest.at;
1624
+ const createdAt =
1625
+ typeof createdValue === "string" || typeof createdValue === "number" ? String(createdValue) : "";
1626
+ if (id || createdAt) oldestPending = { id, createdAt };
1627
+ } else if (typeof rawOldest === "string" || typeof rawOldest === "number") {
1628
+ const text = String(rawOldest);
1629
+ if (text) {
1630
+ oldestPending = parseDate(text) ? { id: "", createdAt: text } : { id: text, createdAt: "" };
1631
+ }
1632
+ }
1633
+
1634
+ return { total, byState, byRole, oldestPending };
1635
+ }
1636
+
1637
+ function normalizeAgents(board) {
1638
+ const agents = [];
1639
+ for (const rawEntry of asArray(board)) {
1640
+ const entry = isRecord(rawEntry) && isRecord(rawEntry.value) ? rawEntry.value : rawEntry;
1641
+ if (!isRecord(entry)) continue;
1642
+ agents.push({
1643
+ agent: asString(entry.agent || entry.key || entry.name),
1644
+ state: asString(entry.state),
1645
+ task: asString(entry.task),
1646
+ files: asArray(entry.files).map((file) => asString(file)).filter(Boolean),
1647
+ updatedAt: asString(entry.updatedAt),
1648
+ });
1649
+ }
1650
+ return agents;
1651
+ }
1652
+
1653
+ function normalizeEvents(events) {
1654
+ const decorated = [];
1655
+ const list = asArray(events);
1656
+ for (let index = 0; index < list.length; index += 1) {
1657
+ const event = list[index];
1658
+ if (!isRecord(event)) continue;
1659
+ decorated.push({ event, index, time: eventTime(event) });
1660
+ }
1661
+ decorated.sort((left, right) => right.time - left.time || left.index - right.index);
1662
+ return decorated.slice(0, MAX_EVENTS).map(({ event }) => ({
1663
+ ts: asString(event.ts),
1664
+ kind: asString(event.kind),
1665
+ task: asString(event.task),
1666
+ actor: asString(event.actor),
1667
+ }));
1668
+ }
1669
+
1670
+ function actionsForState(state, writable) {
1671
+ if (!writable) return [];
1672
+ const names = CARD_ACTIONS[asString(state)] || [];
1673
+ return names.map((name) => ({ name, ...ACTION_META[name] }));
1674
+ }
1675
+
1676
+ function modeAction(mode) {
1677
+ const nextMode = mode === "freeze" ? "free" : "freeze";
1678
+ const meta = mode === "freeze" ? ACTION_META.unfreeze : ACTION_META.freeze;
1679
+ return { name: "mode", ...meta, body: { mode: nextMode, reason: "panel" } };
1680
+ }
1681
+
1682
+ function toolbarActions(writable) {
1683
+ if (!writable) return [];
1684
+ return [
1685
+ { name: "add", ...ACTION_META.add },
1686
+ { name: "plan", ...ACTION_META.plan },
1687
+ { name: "commit", ...ACTION_META.commit },
1688
+ ];
1689
+ }
1690
+
1691
+ function helpGroups(mode) {
1692
+ return [
1693
+ { titleKey: "help.board", actions: [modeAction(mode), ...toolbarActions(true)] },
1694
+ {
1695
+ titleKey: "help.tasks",
1696
+ actions: ["claim", "done", "fail", "retry"].map((name) => ({ name, ...ACTION_META[name] })),
1697
+ },
1698
+ ];
1699
+ }
1700
+
1701
+ /**
1702
+ * Build a plain, testable view model from a hive-panel snapshot.
1703
+ *
1704
+ * @param {object} snapshot
1705
+ * @returns {{
1706
+ * at: string, repo: string, mode: string, initialised: boolean, writable: boolean,
1707
+ * queen: {active:boolean, source:"auto"|"manual"|null, repo:string}|null,
1708
+ * lanes: Record<string, Array<{id:string,title:string,role:string,owner:string,scope:string[],reason:string}>>,
1709
+ * laneOrder: string[],
1710
+ * stats: {total:number, byState:Record<string,number>, byRole:Record<string,number>, oldestPending:{id:string,createdAt:string}|null},
1711
+ * agents: Array<{agent:string,state:string,task:string,files:string[],updatedAt:string}>,
1712
+ * events: Array<{ts:string,kind:string,task:string,actor:string}>,
1713
+ * actions: Array<{name:string,labelKey:string,body?:object}>
1714
+ * }}
1715
+ */
1716
+ export function renderModel(snapshot) {
1717
+ const source = isRecord(snapshot) ? snapshot : {};
1718
+ const tasks = asArray(source.tasks).filter(isRecord);
1719
+
1720
+ const lanes = {};
1721
+ for (const state of LANE_ORDER) lanes[state] = [];
1722
+ for (const task of tasks) {
1723
+ const state = asString(task.state);
1724
+ if (Object.prototype.hasOwnProperty.call(lanes, state)) {
1725
+ lanes[state].push(normalizeCard(task));
1726
+ }
1727
+ }
1728
+
1729
+ const rawMode = source.mode;
1730
+ const mode =
1731
+ typeof rawMode === "string"
1732
+ ? rawMode
1733
+ : isRecord(rawMode) && typeof rawMode.mode === "string"
1734
+ ? rawMode.mode
1735
+ : "free";
1736
+ const writable = source.writable === true;
1737
+ const initialised = source.initialised !== false;
1738
+ const rawQueen = isRecord(source.queen) ? source.queen : null;
1739
+ const queenActive = rawQueen !== null && rawQueen.active === true;
1740
+ const queen =
1741
+ rawQueen === null
1742
+ ? null
1743
+ : {
1744
+ active: queenActive,
1745
+ source:
1746
+ queenActive && (rawQueen.source === "auto" || rawQueen.source === "manual")
1747
+ ? rawQueen.source
1748
+ : null,
1749
+ repo: typeof rawQueen.repo === "string" ? rawQueen.repo : "",
1750
+ };
1751
+
1752
+ return {
1753
+ at: asString(source.at),
1754
+ repo: asString(source.repo),
1755
+ mode,
1756
+ initialised,
1757
+ queen,
1758
+ writable,
1759
+ lanes,
1760
+ laneOrder: [...LANE_ORDER],
1761
+ stats: normalizeStats(source.stats, tasks),
1762
+ agents: normalizeAgents(source.board),
1763
+ events: normalizeEvents(source.events),
1764
+ actions: initialised ? toolbarActions(writable) : [],
1765
+ };
1766
+ }
1767
+
1768
+ function supervisorCount(value) {
1769
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1770
+ if (Array.isArray(value)) return value.length;
1771
+ if (typeof value === "boolean") return value ? null : 0;
1772
+ return null;
1773
+ }
1774
+
1775
+ function supervisorNumber(value) {
1776
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1777
+ if (typeof value === "string" && value.trim() !== "") {
1778
+ const number = Number(value);
1779
+ if (Number.isFinite(number)) return number;
1780
+ }
1781
+ if (Array.isArray(value)) return value.length;
1782
+ if (typeof value === "boolean") return value ? null : 0;
1783
+ return null;
1784
+ }
1785
+
1786
+ function normalizeSupervisorRoles(source) {
1787
+ if (!isRecord(source)) return [];
1788
+ const rows = new Map();
1789
+ const ensure = (role) => {
1790
+ const name = asString(role).trim();
1791
+ if (!name) return null;
1792
+ if (!rows.has(name)) rows.set(name, { role: name, limit: null, inFlight: null, queued: null });
1793
+ return rows.get(name);
1794
+ };
1795
+ const setLimit = (role, value) => {
1796
+ const row = ensure(role);
1797
+ const number = supervisorNumber(value);
1798
+ if (row && number !== null) row.limit = number;
1799
+ };
1800
+ const setCount = (role, field, value) => {
1801
+ const row = ensure(role);
1802
+ const number = supervisorNumber(value);
1803
+ if (row && number !== null) row[field] = number;
1804
+ };
1805
+ const applyEntry = (raw, fallbackRole) => {
1806
+ if (typeof raw === "number" || typeof raw === "string") {
1807
+ setLimit(fallbackRole, raw);
1808
+ return;
1809
+ }
1810
+ if (!isRecord(raw)) return;
1811
+ const role = asString(raw.role || raw.name || raw.key || raw.id || fallbackRole);
1812
+ const row = ensure(role);
1813
+ if (!row) return;
1814
+ for (const field of ["limit", "max", "concurrency", "concurrencyLimit", "maxConcurrency", "max_concurrency", "concurrency_limit", "maxInFlight", "max_in_flight", "cap", "capacity", "value", "n"]) {
1815
+ if (supervisorNumber(raw[field]) !== null) {
1816
+ row.limit = supervisorNumber(raw[field]);
1817
+ break;
1818
+ }
1819
+ }
1820
+ for (const field of ["inFlight", "inflight", "in_flight", "inFlightCount", "running", "running_count", "active", "active_count", "current", "now", "inProgress", "busy"]) {
1821
+ if (supervisorNumber(raw[field]) !== null) {
1822
+ row.inFlight = supervisorNumber(raw[field]);
1823
+ break;
1824
+ }
1825
+ }
1826
+ for (const field of ["queued", "queue", "queued_count", "pending", "pending_count", "waiting", "waiting_count", "backlog"]) {
1827
+ if (supervisorNumber(raw[field]) !== null) {
1828
+ row.queued = supervisorNumber(raw[field]);
1829
+ break;
1830
+ }
1831
+ }
1832
+ if (row.inFlight === null && supervisorNumber(raw.count) !== null) row.inFlight = supervisorNumber(raw.count);
1833
+ };
1834
+ const applyMap = (value, mode) => {
1835
+ if (!isRecord(value)) return;
1836
+ for (const [role, raw] of Object.entries(value)) {
1837
+ if (mode === "limit") {
1838
+ if (supervisorNumber(raw) !== null) setLimit(role, raw);
1839
+ else if (isRecord(raw)) applyEntry({ role, ...raw }, role);
1840
+ } else if (mode === "entry") {
1841
+ if (typeof raw === "number" || typeof raw === "string") setLimit(role, raw);
1842
+ else if (isRecord(raw)) applyEntry({ role, ...raw }, role);
1843
+ } else {
1844
+ if (supervisorNumber(raw) !== null) setCount(role, mode, raw);
1845
+ else if (isRecord(raw)) {
1846
+ const number = supervisorNumber(raw.count ?? raw.n ?? raw.value ?? raw.running ?? raw.active ?? raw.inFlight ?? raw.queued);
1847
+ if (number !== null) setCount(role, mode, number);
1848
+ else applyEntry({ role, ...raw }, role);
1849
+ }
1850
+ }
1851
+ }
1852
+ };
1853
+
1854
+ for (const key of ["roleLimits", "limits", "caps", "roleCaps", "concurrencyLimits"]) {
1855
+ if (Array.isArray(source[key])) for (const raw of source[key]) applyEntry(raw);
1856
+ else applyMap(source[key], "limit");
1857
+ }
1858
+ if (Array.isArray(source.roles)) for (const raw of source.roles) applyEntry(raw);
1859
+ else applyMap(source.roles, "entry");
1860
+ if (Array.isArray(source.bees)) for (const raw of source.bees) applyEntry(raw);
1861
+ else applyMap(source.bees, "entry");
1862
+ for (const key of ["roleStats", "roleDetails", "rolesStats", "byRole", "roleCounts"]) {
1863
+ if (Array.isArray(source[key])) for (const raw of source[key]) applyEntry(raw);
1864
+ else applyMap(source[key], "entry");
1865
+ }
1866
+ for (const key of ["inFlight", "inflight", "active", "running", "inFlightByRole", "runningByRole", "activeByRole"]) {
1867
+ applyMap(source[key], "inFlight");
1868
+ }
1869
+ for (const key of ["queued", "queue", "pending", "queuedByRole", "pendingByRole", "roleQueues", "backlog"]) {
1870
+ applyMap(source[key], "queued");
1871
+ }
1872
+ if (isRecord(source.concurrency)) applyMap(source.concurrency, "limit");
1873
+
1874
+ return [...rows.values()].sort((left, right) => left.role.localeCompare(right.role));
1875
+ }
1876
+
1877
+ function supervisorMapEntries(value) {
1878
+ if (!isRecord(value)) return [];
1879
+ const entries = Object.entries(value);
1880
+ if (entries.length === 0) return [];
1881
+ const allValues = entries.every(([, entry]) => typeof entry === "string" || isRecord(entry));
1882
+ const pathKeys = entries.some(([key]) => key.includes("/") || key.includes("\\") || key.includes(":"));
1883
+ if (!allValues || !pathKeys) return [];
1884
+ return entries.map(([repo, entry]) => (isRecord(entry) ? { repo, ...entry } : { repo, state: entry }));
1885
+ }
1886
+
1887
+ function supervisorEntriesFrom(payload, depth = 0) {
1888
+ if (Array.isArray(payload)) return payload;
1889
+ if (!isRecord(payload)) return [];
1890
+ if (payload.repo || payload.path || payload.cwd || payload.directory) return [payload];
1891
+ for (const key of ["repos", "repositories", "supervisors", "workers", "items", "list", "data", "result", "status"]) {
1892
+ if (!Object.prototype.hasOwnProperty.call(payload, key)) continue;
1893
+ const value = payload[key];
1894
+ if (Array.isArray(value)) return value;
1895
+ if (isRecord(value)) {
1896
+ if (value.repo || value.path || value.cwd) return [value];
1897
+ const mapped = supervisorMapEntries(value);
1898
+ if (mapped.length > 0) return mapped;
1899
+ if (depth < 3) {
1900
+ const nested = supervisorEntriesFrom(value, depth + 1);
1901
+ if (nested.length > 0) return nested;
1902
+ }
1903
+ }
1904
+ }
1905
+ const mapped = supervisorMapEntries(payload);
1906
+ if (mapped.length > 0) return mapped;
1907
+ if (payload.state || payload.status || payload.mode || payload.paused || payload.running) return [payload];
1908
+ return [];
1909
+ }
1910
+
1911
+ /** Normalize the supervisor status endpoint into per-repository rows. */
1912
+ function normalizeSupervisorStatus(payload) {
1913
+ const rows = new Map();
1914
+ for (const raw of supervisorEntriesFrom(payload)) {
1915
+ if (!isRecord(raw)) continue;
1916
+ const source = isRecord(raw.supervisor) ? { ...raw, ...raw.supervisor } : raw;
1917
+ const repo = asString(source.repo || source.path || source.cwd || source.directory || source.root || source.name);
1918
+ if (!repo) continue;
1919
+ const rawState = asString(source.state || source.status || source.phase || source.mode).toLowerCase();
1920
+ const paused = source.paused === true || source.suspended === true || /paus|stop|suspend/.test(rawState);
1921
+ const running =
1922
+ supervisorCount(source.running) ??
1923
+ supervisorCount(source.active) ??
1924
+ supervisorCount(source.workers) ??
1925
+ supervisorCount(source.agents) ??
1926
+ supervisorCount(source.inflight) ??
1927
+ supervisorCount(source.count);
1928
+ let state = "idle";
1929
+ if (paused) state = "paused";
1930
+ else if (source.backoff === true || /backoff|back-off|retry|delay|wait/.test(rawState)) state = "backoff";
1931
+ else if (/run|active|busy|working/.test(rawState)) state = "running";
1932
+ else if (/idle|ready|free/.test(rawState)) state = "idle";
1933
+ else if (running !== null && running > 0) state = "running";
1934
+ rows.set(repo, { repo, state, running, roles: normalizeSupervisorRoles(source) });
1935
+ }
1936
+ return [...rows.values()].sort((left, right) => left.repo.localeCompare(right.repo));
1937
+ }
1938
+
1939
+ function element(doc, tag, className, text) {
1940
+ const node = doc.createElement(tag);
1941
+ if (className) node.className = className;
1942
+ if (text !== undefined && text !== null) node.textContent = String(text);
1943
+ return node;
1944
+ }
1945
+
1946
+ function setAttr(node, name, value) {
1947
+ if (node && typeof node.setAttribute === "function") {
1948
+ node.setAttribute(name, value === null || value === undefined ? "" : String(value));
1949
+ }
1950
+ }
1951
+
1952
+ function clearNode(node) {
1953
+ node.textContent = "";
1954
+ }
1955
+
1956
+ function focusNode(node) {
1957
+ if (!node || typeof node.focus !== "function") return;
1958
+ try {
1959
+ node.focus();
1960
+ } catch {
1961
+ // Focus is a progressive enhancement; never break rendering over it.
1962
+ }
1963
+ }
1964
+
1965
+ function setStyle(node, property, value) {
1966
+ if (!node || !node.style) return;
1967
+ node.style[property] = value;
1968
+ }
1969
+
1970
+ /**
1971
+ * Inject the overlay styles once per document. They live in panel.js so the
1972
+ * standalone page and the DSH client bundle share one unchanged stylesheet.
1973
+ * @param {Document} doc
1974
+ */
1975
+ function ensurePanelStyles(doc) {
1976
+ if (!doc) return;
1977
+ const host = doc.head || doc.documentElement;
1978
+ if (!host || typeof host.appendChild !== "function") return;
1979
+ try {
1980
+ // Refresh the style element on every mount by content, not by a document
1981
+ // property alone. A long-lived host page can keep an older style tag from
1982
+ // a previous bundle alive after an update, which used to leave new blocks
1983
+ // (such as the uninitialised card) unstyled.
1984
+ const existing =
1985
+ typeof doc.querySelector === "function" ? doc.querySelector("style[data-hive-panel-overlays]") : null;
1986
+ if (existing) {
1987
+ if (existing.textContent !== PANEL_STYLES) existing.textContent = PANEL_STYLES;
1988
+ doc.__hivePanelOverlayStyles = true;
1989
+ return;
1990
+ }
1991
+ const style = doc.createElement("style");
1992
+ style.setAttribute("data-hive-panel-overlays", "");
1993
+ style.textContent = PANEL_STYLES;
1994
+ host.appendChild(style);
1995
+ doc.__hivePanelOverlayStyles = true;
1996
+ } catch {
1997
+ // Styling is optional; the panel still renders without it.
1998
+ }
1999
+ }
2000
+
2001
+ function parseDate(value) {
2002
+ if (value === null || value === undefined || value === "") return null;
2003
+ if (typeof value === "number") {
2004
+ const fromNumber = new Date(value);
2005
+ return Number.isNaN(fromNumber.getTime()) ? null : fromNumber;
2006
+ }
2007
+ const text = String(value).trim();
2008
+ if (!text) return null;
2009
+ const numeric = Number(text);
2010
+ const date = new Date(/^\d+$/.test(text) ? numeric : text);
2011
+ return Number.isNaN(date.getTime()) ? null : date;
2012
+ }
2013
+
2014
+ function formatTime(value) {
2015
+ const date = parseDate(value);
2016
+ if (!date) return asString(value);
2017
+ try {
2018
+ return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" });
2019
+ } catch {
2020
+ return date.toISOString();
2021
+ }
2022
+ }
2023
+
2024
+ function formatStamp(value) {
2025
+ const date = parseDate(value);
2026
+ if (!date) return asString(value);
2027
+ try {
2028
+ return date.toLocaleString([], {
2029
+ month: "short",
2030
+ day: "2-digit",
2031
+ hour: "2-digit",
2032
+ minute: "2-digit",
2033
+ second: "2-digit",
2034
+ });
2035
+ } catch {
2036
+ return date.toISOString();
2037
+ }
2038
+ }
2039
+
2040
+ function safeClassToken(value) {
2041
+ const token = asString(value).toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
2042
+ return token || "unknown";
2043
+ }
2044
+
2045
+ function splitList(value) {
2046
+ return asString(value)
2047
+ .split(",")
2048
+ .map((item) => item.trim())
2049
+ .filter(Boolean);
2050
+ }
2051
+
2052
+ function summarizeActionOutput(value, maxLength = 480) {
2053
+ const text = asString(value).replace(/\u001b\[[0-9;]*m/g, "").trim();
2054
+ if (!text) return "";
2055
+ const lines = text
2056
+ .split(/\r?\n/)
2057
+ .map((line) => line.trimEnd())
2058
+ .filter(Boolean);
2059
+ const joined = lines.slice(0, 4).join("\n");
2060
+ return joined.length > maxLength ? joined.slice(0, maxLength - 1) + "…" : joined;
2061
+ }
2062
+
2063
+ function actionErrorDetail(error) {
2064
+ if (!error) return "";
2065
+ return summarizeActionOutput(error.stderr || error.stdout || error.message);
2066
+ }
2067
+
2068
+ function planListFromJson(value) {
2069
+ if (Array.isArray(value)) return value;
2070
+ if (!isRecord(value)) return null;
2071
+ for (const key of ["plan", "cards", "tasks"]) {
2072
+ if (Array.isArray(value[key])) return value[key];
2073
+ }
2074
+ return null;
2075
+ }
2076
+
2077
+ function parsePlanJson(text) {
2078
+ const raw = asString(text).trim();
2079
+ if (!raw) return null;
2080
+ const candidates = [raw];
2081
+ const firstArray = raw.indexOf("[");
2082
+ const lastArray = raw.lastIndexOf("]");
2083
+ if (firstArray >= 0 && lastArray > firstArray) candidates.push(raw.slice(firstArray, lastArray + 1));
2084
+ const firstObject = raw.indexOf("{");
2085
+ const lastObject = raw.lastIndexOf("}");
2086
+ if (firstObject >= 0 && lastObject > firstObject) candidates.push(raw.slice(firstObject, lastObject + 1));
2087
+ for (const candidate of candidates) {
2088
+ try {
2089
+ const list = planListFromJson(JSON.parse(candidate));
2090
+ if (list) return list;
2091
+ } catch {
2092
+ // Try the next candidate.
2093
+ }
2094
+ }
2095
+ return null;
2096
+ }
2097
+
2098
+ function normalizePlanCards(value) {
2099
+ const cards = [];
2100
+ for (const entry of asArray(value)) {
2101
+ if (!isRecord(entry)) continue;
2102
+ const afterValue = entry.after !== undefined ? entry.after : entry.deps !== undefined ? entry.deps : entry.dependsOn;
2103
+ cards.push({
2104
+ key: asString(entry.key),
2105
+ title: asString(entry.title || entry.goal || entry.summary),
2106
+ role: asString(entry.role),
2107
+ scope: normalizeScope(entry.scope),
2108
+ after: normalizeScope(afterValue),
2109
+ });
2110
+ }
2111
+ return cards;
2112
+ }
2113
+
2114
+ function parsePlanText(text) {
2115
+ const cards = [];
2116
+ for (const line of asString(text).split(/\r?\n/)) {
2117
+ const trimmed = line.trim();
2118
+ if (!trimmed || /^plan has\b/i.test(trimmed)) continue;
2119
+ const match = /^\s*(\S+)\s+(\S+)\s+(.+)$/.exec(line);
2120
+ if (!match) continue;
2121
+ cards.push({ key: match[1], title: match[3].trim(), role: match[2], scope: [], after: [] });
2122
+ }
2123
+ return cards;
2124
+ }
2125
+
2126
+ function extractPlan(payload) {
2127
+ const stdout = asString(payload && payload.stdout)
2128
+ .replace(/\u001b\[[0-9;]*m/g, "")
2129
+ .trim();
2130
+ const direct = payload && (Array.isArray(payload) ? payload : payload.plan || payload.cards || payload.tasks);
2131
+ const jsonList = (Array.isArray(direct) ? direct : null) || parsePlanJson(stdout);
2132
+ if (jsonList) {
2133
+ return { cards: normalizePlanCards(jsonList), raw: stdout, structured: true };
2134
+ }
2135
+ // hive-run's dry run prints a short human summary followed by key/role/title
2136
+ // lines. Keep that fallback narrow so unrelated stdout is never mistaken for a plan.
2137
+ const textCards = /^\s*plan has\b/im.test(stdout) ? parsePlanText(stdout) : [];
2138
+ return { cards: textCards, raw: stdout, structured: false };
2139
+ }
2140
+
2141
+ /**
2142
+ * Mount the panel into a host element.
2143
+ *
2144
+ * @param {HTMLElement} root
2145
+ * @param {{
2146
+ * snapshotUrl?: string,
2147
+ * actionsUrl?: string,
2148
+ * supervisorUrl?: string,
2149
+ * intervalMs?: number,
2150
+ * onError?: (error: Error) => void,
2151
+ * fetch?: typeof fetch,
2152
+ * t?: (key: string) => string,
2153
+ * subscribeLocale?: (listener: () => void) => (() => void)
2154
+ * }} [options]
2155
+ * @returns {{
2156
+ * setSnapshot: (snapshot: object) => object|null,
2157
+ * destroy: () => void,
2158
+ * refresh: () => Promise<void>,
2159
+ * rerender: () => void
2160
+ * }}
2161
+ */
2162
+ export function mount(root, options = {}) {
2163
+ if (!root || typeof root.appendChild !== "function") {
2164
+ throw new TypeError("hive mount: root must be a DOM element");
2165
+ }
2166
+ const doc = root.ownerDocument || globalThis.document;
2167
+ if (!doc || typeof doc.createElement !== "function") {
2168
+ throw new TypeError("hive mount: no document available");
2169
+ }
2170
+ if (root.classList && typeof root.classList.add === "function") {
2171
+ root.classList.add("hive-viewport");
2172
+ } else {
2173
+ root.className = (root.className ? root.className + " " : "") + "hive-viewport";
2174
+ }
2175
+ ensurePanelStyles(doc);
2176
+
2177
+ const opts = isRecord(options) ? options : {};
2178
+ const view = doc.defaultView || globalThis;
2179
+ const snapshotUrl = asString(opts.snapshotUrl) || DEFAULT_SNAPSHOT_URL;
2180
+ const supervisorUrl = asString(opts.supervisorUrl) || DEFAULT_SUPERVISOR_URL;
2181
+ const actionsUrl = (asString(opts.actionsUrl) || DEFAULT_ACTIONS_URL).replace(/\/+$/, "");
2182
+
2183
+ const requestedInterval = Number(opts.intervalMs);
2184
+ const intervalMs =
2185
+ Number.isFinite(requestedInterval) && requestedInterval > 0
2186
+ ? Math.max(1, Math.floor(requestedInterval))
2187
+ : DEFAULT_INTERVAL_MS;
2188
+
2189
+ const fetchImpl =
2190
+ typeof opts.fetch === "function"
2191
+ ? opts.fetch
2192
+ : typeof view.fetch === "function"
2193
+ ? view.fetch.bind(view)
2194
+ : typeof globalThis.fetch === "function"
2195
+ ? globalThis.fetch.bind(globalThis)
2196
+ : null;
2197
+
2198
+ const promptImpl =
2199
+ typeof view.prompt === "function"
2200
+ ? view.prompt.bind(view)
2201
+ : typeof globalThis.prompt === "function"
2202
+ ? globalThis.prompt.bind(globalThis)
2203
+ : null;
2204
+
2205
+ const schedule =
2206
+ typeof view.setInterval === "function" ? view.setInterval.bind(view) : globalThis.setInterval.bind(globalThis);
2207
+ const unschedule =
2208
+ typeof view.clearInterval === "function" ? view.clearInterval.bind(view) : globalThis.clearInterval.bind(globalThis);
2209
+
2210
+ const translator = typeof opts.t === "function" ? opts.t : null;
2211
+
2212
+ /**
2213
+ * Resolve one dictionary key. The host translator wins; English and the raw
2214
+ * key are the fallbacks so a broken or partial translator cannot blank the UI.
2215
+ * @param {string} key - dictionary key.
2216
+ * @returns {string}
2217
+ */
2218
+ function translate(key) {
2219
+ if (translator) {
2220
+ try {
2221
+ const value = translator(key);
2222
+ if (typeof value === "string" && value !== "") return value;
2223
+ } catch {
2224
+ // A throwing translator must not break polling or rendering.
2225
+ }
2226
+ }
2227
+ return Object.prototype.hasOwnProperty.call(messages.en, key) ? messages.en[key] : key;
2228
+ }
2229
+
2230
+ /** @param {string} lane - raw lane id. @returns {string} */
2231
+ function laneLabel(lane) {
2232
+ return translate(LANE_LABEL_KEYS[lane] || lane);
2233
+ }
2234
+
2235
+ let destroyed = false;
2236
+ let timer = null;
2237
+ let refreshPromise = null;
2238
+ let lastSnapshot = null;
2239
+ let lastModel = null;
2240
+ let drawerNode = null;
2241
+ let drawerState = null;
2242
+ let unsubscribeLocale = null;
2243
+ let statusKey = null;
2244
+ let statusKind = "info";
2245
+ let helpNode = null;
2246
+ let helpScrim = null;
2247
+ let helpOpen = false;
2248
+ let helpSignature = "";
2249
+ let planOverlay = null;
2250
+ let planDialogNode = null;
2251
+ let planState = null;
2252
+ let planTriggerButton = null;
2253
+ let planFocusables = [];
2254
+ let toastNode = null;
2255
+ let stageFilter = "all";
2256
+ let stageChipEntries = [];
2257
+ let eventsExpanded = false;
2258
+ let initBusy = false;
2259
+ let initOutput = null;
2260
+ let initErrorMessage = "";
2261
+ let initRequestSeq = 0;
2262
+ let queenNotice = false;
2263
+ let queenBusy = false;
2264
+ let supervisorData = [];
2265
+ let supervisorRequest = null;
2266
+ let limitsOverlay = null;
2267
+ let limitsDialogNode = null;
2268
+ let limitsState = null;
2269
+ let limitsTriggerButton = null;
2270
+ let limitsFocusables = [];
2271
+
2272
+ // --- shell ---------------------------------------------------------------
2273
+
2274
+ const frame = element(doc, "div", "hive");
2275
+ const bar = element(doc, "header", "hive-bar");
2276
+
2277
+ const ident = element(doc, "div", "hive-ident");
2278
+ ident.appendChild(element(doc, "span", "hive-brand", "hive"));
2279
+ const repoNode = element(doc, "span", "hive-repo", "—");
2280
+ ident.appendChild(repoNode);
2281
+ bar.appendChild(ident);
2282
+
2283
+ const timeNode = element(doc, "time", "hive-time", "");
2284
+ bar.appendChild(timeNode);
2285
+
2286
+ const statsNode = element(doc, "div", "hive-stats");
2287
+ bar.appendChild(statsNode);
2288
+
2289
+ const queenBadge = element(doc, "span", "hive-queen-badge is-hidden", "");
2290
+ bar.appendChild(queenBadge);
2291
+
2292
+ const statusNode = element(doc, "span", "hive-status", "");
2293
+ bar.appendChild(statusNode);
2294
+
2295
+ const actionGroup = element(doc, "div", "hive-action-group");
2296
+ const actionsNode = element(doc, "div", "hive-actions");
2297
+ actionGroup.appendChild(actionsNode);
2298
+
2299
+ const helpButton = element(doc, "button", "hive-btn hive-help-trigger hive-menu-trigger", "⋯");
2300
+ setAttr(helpButton, "type", "button");
2301
+ setAttr(helpButton, "aria-haspopup", "dialog");
2302
+ setAttr(helpButton, "aria-expanded", "false");
2303
+ setAttr(helpButton, "title", translate("menu.open"));
2304
+ setAttr(helpButton, "aria-label", translate("menu.open"));
2305
+ helpButton.addEventListener("click", () => {
2306
+ toggleHelp();
2307
+ });
2308
+ actionGroup.appendChild(helpButton);
2309
+ bar.appendChild(actionGroup);
2310
+
2311
+ const supervisorBar = element(doc, "section", "hive-supervisor is-hidden");
2312
+ setAttr(supervisorBar, "aria-label", translate("supervisor.aria"));
2313
+ const supervisorLabel = element(doc, "span", "hive-supervisor-label", "");
2314
+ const supervisorRepos = element(doc, "div", "hive-supervisor-repos");
2315
+ const supervisorLimitsButton = element(doc, "button", "hive-btn hive-btn-ghost hive-supervisor-limits is-hidden", translate("limits.open"));
2316
+ setAttr(supervisorLimitsButton, "type", "button");
2317
+ setAttr(supervisorLimitsButton, "title", translate("limits.openAria"));
2318
+ setAttr(supervisorLimitsButton, "aria-label", translate("limits.openAria"));
2319
+ supervisorLimitsButton.addEventListener("click", () => {
2320
+ openLimitsDialog(supervisorLimitsButton);
2321
+ });
2322
+ supervisorBar.appendChild(supervisorLabel);
2323
+ supervisorBar.appendChild(supervisorRepos);
2324
+ supervisorBar.appendChild(supervisorLimitsButton);
2325
+
2326
+ const freezeSlot = element(doc, "div", "hive-freeze-slot");
2327
+
2328
+ // Queen-mode notice, shown only after a successful init in this mount.
2329
+ const queenHint = element(doc, "section", "hive-queen-hint");
2330
+ setAttr(queenHint, "role", "status");
2331
+ const queenHintText = element(doc, "div", "hive-queen-text", "");
2332
+ const queenExit = element(doc, "div", "hive-queen-exit");
2333
+ const queenExitText = element(doc, "span", "hive-queen-exit-text", "");
2334
+ const queenCommand = element(doc, "code", "hive-queen-command", "");
2335
+ queenExit.appendChild(queenExitText);
2336
+ queenExit.appendChild(queenCommand);
2337
+ const queenOffer = element(doc, "div", "hive-queen-offer is-hidden");
2338
+ const queenTakeoverButton = element(doc, "button", "hive-btn hive-queen-takeover", translate("queen.takeover"));
2339
+ setAttr(queenTakeoverButton, "type", "button");
2340
+ setAttr(queenTakeoverButton, "title", translate("queen.takeoverAria"));
2341
+ setAttr(queenTakeoverButton, "aria-label", translate("queen.takeoverAria"));
2342
+ queenTakeoverButton.addEventListener("click", () => {
2343
+ void runQueenOn(queenTakeoverButton);
2344
+ });
2345
+ queenOffer.appendChild(queenTakeoverButton);
2346
+ const queenOutputDetails = element(doc, "details", "hive-init-output hive-queen-output is-hidden");
2347
+ const queenOutputSummary = element(doc, "summary", "hive-output-summary", "");
2348
+ const queenOutputPre = element(doc, "pre", "hive-output-pre", "");
2349
+ queenOutputDetails.appendChild(queenOutputSummary);
2350
+ queenOutputDetails.appendChild(queenOutputPre);
2351
+ queenHint.appendChild(queenHintText);
2352
+ queenHint.appendChild(queenOffer);
2353
+ queenHint.appendChild(queenExit);
2354
+ queenHint.appendChild(queenOutputDetails);
2355
+
2356
+ const main = element(doc, "main", "hive-main");
2357
+
2358
+ // Uninitialised repository card, hidden unless snapshot.initialised === false.
2359
+ const initPane = element(doc, "section", "hive-init-pane");
2360
+ const initCard = element(doc, "div", "hive-init-card");
2361
+ const initRepoRow = element(doc, "div", "hive-init-repo-row");
2362
+ const initRepoLabel = element(doc, "span", "hive-init-repo-label", "");
2363
+ const initRepo = element(doc, "code", "hive-init-repo", "");
2364
+ initRepoRow.appendChild(initRepoLabel);
2365
+ initRepoRow.appendChild(initRepo);
2366
+ initCard.appendChild(initRepoRow);
2367
+ const initTitle = element(doc, "h2", "hive-init-title", "");
2368
+ initCard.appendChild(initTitle);
2369
+ const initDescription = element(doc, "p", "hive-init-description", "");
2370
+ initCard.appendChild(initDescription);
2371
+ const initButton = element(doc, "button", "hive-btn hive-init-button", "");
2372
+ setAttr(initButton, "type", "button");
2373
+ initButton.addEventListener("click", () => {
2374
+ void runInitialise();
2375
+ });
2376
+ initCard.appendChild(initButton);
2377
+ const initReadOnly = element(doc, "div", "hive-init-readonly", "");
2378
+ initCard.appendChild(initReadOnly);
2379
+ const initProgress = element(doc, "div", "hive-init-progress is-hidden");
2380
+ setAttr(initProgress, "role", "status");
2381
+ setAttr(initProgress, "aria-live", "polite");
2382
+ initProgress.appendChild(element(doc, "span", "hive-spinner", ""));
2383
+ const initProgressText = element(doc, "span", "hive-init-progress-text", "");
2384
+ initProgress.appendChild(initProgressText);
2385
+ initCard.appendChild(initProgress);
2386
+ const initError = element(doc, "div", "hive-init-error", "");
2387
+ initCard.appendChild(initError);
2388
+ const initOutputDetails = element(doc, "details", "hive-init-output");
2389
+ const initOutputSummary = element(doc, "summary", "hive-output-summary", "");
2390
+ const initOutputPre = element(doc, "pre", "hive-output-pre", "");
2391
+ initOutputDetails.appendChild(initOutputSummary);
2392
+ initOutputDetails.appendChild(initOutputPre);
2393
+ initCard.appendChild(initOutputDetails);
2394
+ initPane.appendChild(initCard);
2395
+ main.appendChild(initPane);
2396
+
2397
+ // Agents strip.
2398
+ const agentsStrip = element(doc, "section", "hive-agents-strip");
2399
+ setAttr(agentsStrip, "aria-label", translate("pane.agents"));
2400
+ const agentsLabel = element(doc, "span", "hive-strip-label", "");
2401
+ agentsStrip.appendChild(agentsLabel);
2402
+ const agentsCount = element(doc, "span", "hive-count", "0");
2403
+ agentsStrip.appendChild(agentsCount);
2404
+ const agentPills = element(doc, "div", "hive-agent-pills");
2405
+ agentsStrip.appendChild(agentPills);
2406
+
2407
+ // Board pane.
2408
+ const boardPane = element(doc, "section", "hive-pane hive-board");
2409
+ const boardHead = element(doc, "div", "hive-pane-head");
2410
+ const boardLabel = element(doc, "span", null, "");
2411
+ boardHead.appendChild(boardLabel);
2412
+ const boardHint = element(doc, "span", "hive-hint", "");
2413
+ boardHead.appendChild(boardHint);
2414
+ const boardCount = element(doc, "span", "hive-count", "0");
2415
+ boardHead.appendChild(boardCount);
2416
+ const stage = element(doc, "div", "hive-stage");
2417
+ const stageChips = element(doc, "div", "hive-stage-chips");
2418
+ setAttr(stageChips, "aria-label", translate("board.filtersAria"));
2419
+ const lanesNode = element(doc, "div", "hive-lanes");
2420
+ const filterEmpty = element(doc, "div", "hive-filter-empty", "");
2421
+ stage.appendChild(stageChips);
2422
+ stage.appendChild(filterEmpty);
2423
+ stage.appendChild(lanesNode);
2424
+ boardPane.appendChild(boardHead);
2425
+ boardPane.appendChild(stage);
2426
+ main.appendChild(boardPane);
2427
+
2428
+ // Bottom events drawer.
2429
+ const eventsDrawer = element(doc, "section", "hive-events-drawer");
2430
+ const eventsToggle = element(doc, "button", "hive-events-toggle");
2431
+ setAttr(eventsToggle, "type", "button");
2432
+ setAttr(eventsToggle, "aria-expanded", "false");
2433
+ const eventsLabel = element(doc, "span", "hive-events-title", "");
2434
+ const eventsCount = element(doc, "span", "hive-events-count", "0");
2435
+ const eventsCaret = element(doc, "span", "hive-events-caret", "▸");
2436
+ setAttr(eventsCaret, "aria-hidden", "true");
2437
+ eventsToggle.appendChild(eventsLabel);
2438
+ eventsToggle.appendChild(eventsCount);
2439
+ eventsToggle.appendChild(eventsCaret);
2440
+ const eventsList = element(doc, "div", "hive-scroll hive-event-list");
2441
+ eventsDrawer.appendChild(eventsToggle);
2442
+ eventsDrawer.appendChild(eventsList);
2443
+ eventsToggle.addEventListener("click", () => {
2444
+ eventsExpanded = !eventsExpanded;
2445
+ if (lastModel) renderEvents(lastModel);
2446
+ });
2447
+
2448
+ frame.appendChild(bar);
2449
+ frame.appendChild(supervisorBar);
2450
+ frame.appendChild(freezeSlot);
2451
+ frame.appendChild(queenHint);
2452
+ frame.appendChild(agentsStrip);
2453
+ frame.appendChild(main);
2454
+ frame.appendChild(eventsDrawer);
2455
+
2456
+ root.textContent = "";
2457
+ root.appendChild(frame);
2458
+
2459
+ // --- helpers -------------------------------------------------------------
2460
+
2461
+ function reportError(error) {
2462
+ if (typeof opts.onError !== "function") return;
2463
+ try {
2464
+ opts.onError(error instanceof Error ? error : new Error(asString(error)));
2465
+ } catch {
2466
+ // A throwing error handler must not break polling.
2467
+ }
2468
+ }
2469
+
2470
+ /**
2471
+ * Record one status line and resolve its copy through the active dictionary.
2472
+ * @param {string|null} key - dictionary key, or null to clear.
2473
+ * @param {string} [kind] - visual kind (info/error).
2474
+ */
2475
+ function setStatus(key, kind) {
2476
+ statusKey = key || null;
2477
+ statusKind = kind || "info";
2478
+ const text = statusKey ? translate(statusKey) : "";
2479
+ statusNode.textContent = text;
2480
+ statusNode.className = "hive-status" + (text ? " is-" + statusKind : "");
2481
+ }
2482
+
2483
+ /** Re-resolve every piece of static shell copy (called on locale changes). */
2484
+ function applyChrome() {
2485
+ setAttr(actionsNode, "aria-label", translate("actions.aria"));
2486
+ setAttr(helpButton, "title", translate("menu.open"));
2487
+ setAttr(helpButton, "aria-label", translate("menu.open"));
2488
+ setAttr(agentsStrip, "aria-label", translate("pane.agents"));
2489
+ setAttr(stageChips, "aria-label", translate("board.filtersAria"));
2490
+ agentsLabel.textContent = translate("pane.agents");
2491
+ boardLabel.textContent = translate("pane.board");
2492
+ boardHint.textContent = translate("board.hint");
2493
+ eventsLabel.textContent = translate("pane.events");
2494
+ const eventsToggleLabel = eventsExpanded ? translate("events.collapse") : translate("events.showAll");
2495
+ setAttr(eventsToggle, "title", eventsToggleLabel);
2496
+ setAttr(eventsToggle, "aria-label", eventsToggleLabel);
2497
+ if (statusKey) statusNode.textContent = translate(statusKey);
2498
+ }
2499
+
2500
+ function ask(message, initial) {
2501
+ if (!promptImpl) return null;
2502
+ const answer = promptImpl(message, initial === undefined ? "" : initial);
2503
+ return answer === null || answer === undefined ? null : String(answer);
2504
+ }
2505
+
2506
+ function emptyState(text) {
2507
+ return element(doc, "div", "hive-empty", text);
2508
+ }
2509
+
2510
+ function findRawTask(card) {
2511
+ const tasks = lastSnapshot && Array.isArray(lastSnapshot.tasks) ? lastSnapshot.tasks : [];
2512
+ for (const task of tasks) {
2513
+ if (isRecord(task) && asString(task.id) === card.id) return task;
2514
+ }
2515
+ return null;
2516
+ }
2517
+
2518
+ function findRawAgent(agent) {
2519
+ const board = lastSnapshot && Array.isArray(lastSnapshot.board) ? lastSnapshot.board : [];
2520
+ for (const rawEntry of board) {
2521
+ const entry = isRecord(rawEntry) && isRecord(rawEntry.value) ? rawEntry.value : rawEntry;
2522
+ if (!isRecord(entry)) continue;
2523
+ if (asString(entry.agent || entry.key || entry.name) === agent.agent) return entry;
2524
+ }
2525
+ return null;
2526
+ }
2527
+
2528
+ // --- help popover --------------------------------------------------------
2529
+
2530
+ function helpSignatureOf(model) {
2531
+ if (!model) return "none";
2532
+ return (
2533
+ (model.writable ? "write" : "read") +
2534
+ ":" +
2535
+ model.mode +
2536
+ ":" +
2537
+ (model.initialised === false ? "uninitialised" : "ready")
2538
+ );
2539
+ }
2540
+
2541
+ function onHelpKeydown(event) {
2542
+ if (event && (event.key === "Escape" || event.key === "Esc")) closeHelp();
2543
+ }
2544
+
2545
+ function onHelpResize() {
2546
+ closeHelp(false);
2547
+ }
2548
+
2549
+ function closeHelp(restoreFocus = true) {
2550
+ if (helpScrim && helpScrim.parentNode) helpScrim.parentNode.removeChild(helpScrim);
2551
+ if (helpNode && helpNode.parentNode) helpNode.parentNode.removeChild(helpNode);
2552
+ helpScrim = null;
2553
+ helpNode = null;
2554
+ helpOpen = false;
2555
+ helpSignature = "";
2556
+ setAttr(helpButton, "aria-expanded", "false");
2557
+ if (typeof doc.removeEventListener === "function") {
2558
+ doc.removeEventListener("keydown", onHelpKeydown);
2559
+ }
2560
+ if (typeof view.removeEventListener === "function") {
2561
+ view.removeEventListener("resize", onHelpResize);
2562
+ }
2563
+ if (restoreFocus && !destroyed) focusNode(helpButton);
2564
+ }
2565
+
2566
+ function renderHelpContent(body, model) {
2567
+ if (model && model.initialised === false) {
2568
+ body.appendChild(element(doc, "div", "hive-help-note", translate("help.uninitialised")));
2569
+ }
2570
+ if (!model || !model.writable) {
2571
+ body.appendChild(element(doc, "div", "hive-help-note", translate("help.readOnly")));
2572
+ }
2573
+ const groups = helpGroups(model ? model.mode : "free");
2574
+ for (const group of groups) {
2575
+ body.appendChild(element(doc, "div", "hive-help-section", translate(group.titleKey)));
2576
+ for (const action of group.actions) {
2577
+ const item = element(doc, "div", "hive-help-action");
2578
+ item.appendChild(element(doc, "div", "hive-help-name", translate(action.labelKey)));
2579
+ item.appendChild(element(doc, "div", "hive-help-desc", translate(action.helpKey)));
2580
+ const params = action.paramsKey ? translate(action.paramsKey) : "";
2581
+ if (params) {
2582
+ item.appendChild(element(doc, "div", "hive-help-params", translate("help.params") + params));
2583
+ }
2584
+ if (action.name === "mode" && model && model.writable && model.initialised !== false) {
2585
+ const row = element(doc, "div", "hive-help-actionrow");
2586
+ const button = element(doc, "button", "hive-btn hive-help-mode-action", translate(action.labelKey));
2587
+ setAttr(button, "type", "button");
2588
+ setAttr(button, "title", translate(action.helpKey));
2589
+ setAttr(button, "aria-label", translate(action.helpKey));
2590
+ button.addEventListener("click", () => {
2591
+ closeHelp();
2592
+ void postAction("mode", action.body || { mode: "freeze", reason: "panel" });
2593
+ });
2594
+ row.appendChild(button);
2595
+ item.appendChild(row);
2596
+ }
2597
+ body.appendChild(item);
2598
+ }
2599
+ }
2600
+ body.appendChild(element(doc, "div", "hive-help-hint", translate("help.hint")));
2601
+ }
2602
+
2603
+ function positionHelp(panel) {
2604
+ if (
2605
+ typeof frame.getBoundingClientRect !== "function" ||
2606
+ typeof helpButton.getBoundingClientRect !== "function"
2607
+ ) {
2608
+ return;
2609
+ }
2610
+ try {
2611
+ const frameRect = frame.getBoundingClientRect();
2612
+ const buttonRect = helpButton.getBoundingClientRect();
2613
+ const panelRect = panel.getBoundingClientRect();
2614
+ const top = Math.max(8, Math.round(buttonRect.bottom - frameRect.top + 6));
2615
+ const available = Math.max(160, Math.round(frameRect.width - 16));
2616
+ const width = Math.min(panelRect.width || 360, available);
2617
+ let left = Math.round(buttonRect.left - frameRect.left);
2618
+ left = Math.max(8, Math.min(left, Math.round(frameRect.width - width - 8)));
2619
+ setStyle(panel, "top", top + "px");
2620
+ setStyle(panel, "left", left + "px");
2621
+ setStyle(panel, "right", "auto");
2622
+ if (frameRect.height > 0) {
2623
+ setStyle(panel, "maxHeight", Math.max(160, Math.min(560, Math.round(frameRect.height - top - 12))) + "px");
2624
+ }
2625
+ } catch {
2626
+ // Keep the CSS fallback position.
2627
+ }
2628
+ }
2629
+
2630
+ function openHelp() {
2631
+ if (destroyed || helpOpen) return;
2632
+ closePlanDialog(false);
2633
+ closeDrawer();
2634
+
2635
+ const scrim = element(doc, "div", "hive-overlay hive-help-scrim");
2636
+ scrim.addEventListener("click", () => {
2637
+ closeHelp();
2638
+ });
2639
+
2640
+ const panel = element(doc, "div", "hive-help hive-menu");
2641
+ setAttr(panel, "role", "dialog");
2642
+ setAttr(panel, "aria-modal", "false");
2643
+ setAttr(panel, "aria-label", translate("help.aria"));
2644
+
2645
+ const head = element(doc, "div", "hive-help-head");
2646
+ head.appendChild(element(doc, "div", "hive-help-title", translate("help.title")));
2647
+ const closeButton = element(doc, "button", "hive-btn hive-btn-ghost", translate("help.close"));
2648
+ setAttr(closeButton, "type", "button");
2649
+ setAttr(closeButton, "title", translate("help.closeAria"));
2650
+ setAttr(closeButton, "aria-label", translate("help.closeAria"));
2651
+ closeButton.addEventListener("click", () => {
2652
+ closeHelp();
2653
+ });
2654
+ head.appendChild(closeButton);
2655
+ panel.appendChild(head);
2656
+
2657
+ const body = element(doc, "div", "hive-help-body");
2658
+ renderHelpContent(body, lastModel);
2659
+ panel.appendChild(body);
2660
+
2661
+ frame.appendChild(scrim);
2662
+ frame.appendChild(panel);
2663
+ helpScrim = scrim;
2664
+ helpNode = panel;
2665
+ helpOpen = true;
2666
+ helpSignature = helpSignatureOf(lastModel);
2667
+ setAttr(helpButton, "aria-expanded", "true");
2668
+ positionHelp(panel);
2669
+ if (typeof doc.addEventListener === "function") {
2670
+ doc.addEventListener("keydown", onHelpKeydown);
2671
+ }
2672
+ if (typeof view.addEventListener === "function") {
2673
+ view.addEventListener("resize", onHelpResize);
2674
+ }
2675
+ focusNode(closeButton);
2676
+ }
2677
+
2678
+ function toggleHelp() {
2679
+ if (helpOpen) closeHelp();
2680
+ else openHelp();
2681
+ }
2682
+
2683
+ // --- toast ---------------------------------------------------------------
2684
+
2685
+ function closeToast() {
2686
+ if (toastNode && toastNode.parentNode) toastNode.parentNode.removeChild(toastNode);
2687
+ toastNode = null;
2688
+ }
2689
+
2690
+ function showToast(kind, title, detail) {
2691
+ closeToast();
2692
+ const node = element(doc, "div", "hive-toast " + (kind === "success" ? "is-success" : "is-error"));
2693
+ setAttr(node, "role", "alert");
2694
+ setAttr(node, "aria-live", "assertive");
2695
+
2696
+ const head = element(doc, "div", "hive-toast-head");
2697
+ head.appendChild(
2698
+ element(doc, "div", "hive-toast-title " + (kind === "success" ? "is-success" : "is-error"), title),
2699
+ );
2700
+ const closeButton = element(doc, "button", "hive-btn hive-btn-ghost", "×");
2701
+ setAttr(closeButton, "type", "button");
2702
+ setAttr(closeButton, "title", translate("toast.dismiss"));
2703
+ setAttr(closeButton, "aria-label", translate("toast.dismiss"));
2704
+ closeButton.addEventListener("click", closeToast);
2705
+ head.appendChild(closeButton);
2706
+ node.appendChild(head);
2707
+
2708
+ if (detail) node.appendChild(element(doc, "div", "hive-toast-detail", detail));
2709
+ frame.appendChild(node);
2710
+ toastNode = node;
2711
+ }
2712
+
2713
+ // --- plan dialog ---------------------------------------------------------
2714
+
2715
+ function fieldValue(node) {
2716
+ if (!node) return "";
2717
+ return node.value === null || node.value === undefined ? "" : String(node.value);
2718
+ }
2719
+
2720
+ function setPlanError(state, message) {
2721
+ if (!state) return;
2722
+ state.nodes.error.textContent = message || "";
2723
+ }
2724
+
2725
+ function clearPlanError(state) {
2726
+ setPlanError(state, "");
2727
+ }
2728
+
2729
+ function setButtonCopy(button, label, aria) {
2730
+ if (!button) return;
2731
+ button.textContent = label;
2732
+ setAttr(button, "title", aria || label);
2733
+ setAttr(button, "aria-label", aria || label);
2734
+ }
2735
+
2736
+ function updatePlanApply(state) {
2737
+ if (!state) return;
2738
+ const disabled = state.busy || !state.previewed || state.cards.length === 0;
2739
+ state.nodes.apply.disabled = disabled;
2740
+ if (!state.busy) setButtonCopy(state.nodes.apply, translate("plan.write"), translate("plan.writeAria"));
2741
+ }
2742
+
2743
+ function setPlanBusy(state, busy, mode) {
2744
+ if (!state) return;
2745
+ state.busy = busy;
2746
+ state.nodes.goal.disabled = busy;
2747
+ state.nodes.maxCards.disabled = busy;
2748
+ state.nodes.preview.disabled = busy;
2749
+ if (busy && mode === "preview") {
2750
+ setButtonCopy(state.nodes.preview, translate("plan.previewing"), translate("plan.previewing"));
2751
+ state.nodes.apply.disabled = true;
2752
+ } else {
2753
+ setButtonCopy(state.nodes.preview, translate("plan.preview"), translate("plan.previewAria"));
2754
+ }
2755
+ if (busy && mode === "apply") {
2756
+ setButtonCopy(state.nodes.apply, translate("plan.writing"), translate("plan.writing"));
2757
+ } else if (!busy) {
2758
+ setButtonCopy(state.nodes.apply, translate("plan.write"), translate("plan.writeAria"));
2759
+ }
2760
+ if (!busy) updatePlanApply(state);
2761
+ }
2762
+
2763
+ function renderPlanPreview(state) {
2764
+ if (!state) return;
2765
+ clearNode(state.nodes.list);
2766
+ state.nodes.count.textContent = "";
2767
+ if (!state.previewed) {
2768
+ state.nodes.list.appendChild(element(doc, "div", "hive-plan-empty", translate("plan.empty")));
2769
+ return;
2770
+ }
2771
+ if (state.cards.length === 0) {
2772
+ state.nodes.list.appendChild(element(doc, "div", "hive-plan-empty", translate("plan.emptyResult")));
2773
+ return;
2774
+ }
2775
+ state.nodes.count.textContent = String(state.cards.length);
2776
+ for (const card of state.cards) {
2777
+ const item = element(doc, "div", "hive-plan-item");
2778
+ const titleRow = element(doc, "div", "hive-plan-item-title");
2779
+ titleRow.appendChild(element(doc, "span", null, card.title || translate("card.untitled")));
2780
+ if (card.key) titleRow.appendChild(element(doc, "span", "hive-plan-key", card.key));
2781
+ item.appendChild(titleRow);
2782
+ item.appendChild(
2783
+ element(doc, "div", "hive-plan-meta", translate("plan.role") + " " + (card.role || translate("plan.none"))),
2784
+ );
2785
+ item.appendChild(
2786
+ element(
2787
+ doc,
2788
+ "div",
2789
+ "hive-plan-meta",
2790
+ translate("plan.scope") +
2791
+ " " +
2792
+ (card.scope.length ? card.scope.join(", ") : translate("plan.none")),
2793
+ ),
2794
+ );
2795
+ item.appendChild(
2796
+ element(
2797
+ doc,
2798
+ "div",
2799
+ "hive-plan-meta",
2800
+ translate("plan.deps") + " " + (card.after.length ? card.after.join(", ") : translate("plan.none")),
2801
+ ),
2802
+ );
2803
+ state.nodes.list.appendChild(item);
2804
+ }
2805
+ }
2806
+
2807
+ function onPlanKeydown(event) {
2808
+ if (!event) return;
2809
+ if (event.key === "Escape" || event.key === "Esc") {
2810
+ closePlanDialog();
2811
+ return;
2812
+ }
2813
+ if (event.key !== "Tab") return;
2814
+ const items = planFocusables.filter((node) => node && !node.disabled);
2815
+ if (items.length === 0) return;
2816
+ const active = doc.activeElement;
2817
+ let index = items.indexOf(active);
2818
+ if (index < 0) {
2819
+ if (typeof event.preventDefault === "function") event.preventDefault();
2820
+ focusNode(items[event.shiftKey ? items.length - 1 : 0]);
2821
+ return;
2822
+ }
2823
+ if (!event.shiftKey && index === items.length - 1) {
2824
+ if (typeof event.preventDefault === "function") event.preventDefault();
2825
+ focusNode(items[0]);
2826
+ } else if (event.shiftKey && index === 0) {
2827
+ if (typeof event.preventDefault === "function") event.preventDefault();
2828
+ focusNode(items[items.length - 1]);
2829
+ }
2830
+ }
2831
+
2832
+ function closePlanDialog(restoreFocus = true) {
2833
+ if (planOverlay && planOverlay.parentNode) planOverlay.parentNode.removeChild(planOverlay);
2834
+ planOverlay = null;
2835
+ planDialogNode = null;
2836
+ planState = null;
2837
+ planFocusables = [];
2838
+ if (typeof doc.removeEventListener === "function") {
2839
+ doc.removeEventListener("keydown", onPlanKeydown);
2840
+ }
2841
+ if (restoreFocus && !destroyed) focusNode(planTriggerButton);
2842
+ }
2843
+
2844
+ function openPlanDialog(trigger) {
2845
+ if (destroyed || !lastModel || !lastModel.writable) return;
2846
+ closeHelp(false);
2847
+ closeDrawer();
2848
+ planTriggerButton = trigger || planTriggerButton || null;
2849
+
2850
+ const overlay = element(doc, "div", "hive-overlay hive-dialog-scrim");
2851
+ overlay.addEventListener("click", (event) => {
2852
+ if (!event || !event.target || event.target === overlay) closePlanDialog();
2853
+ });
2854
+
2855
+ const dialog = element(doc, "div", "hive-dialog");
2856
+ setAttr(dialog, "role", "dialog");
2857
+ setAttr(dialog, "aria-modal", "true");
2858
+ setAttr(dialog, "aria-label", translate("plan.dialogAria"));
2859
+
2860
+ const head = element(doc, "div", "hive-dialog-head");
2861
+ const titleBox = element(doc, "div", "hive-dialog-head-title");
2862
+ titleBox.appendChild(element(doc, "h2", "hive-dialog-title", translate("plan.dialogTitle")));
2863
+ head.appendChild(titleBox);
2864
+
2865
+ const closeButton = element(doc, "button", "hive-btn hive-btn-ghost", translate("plan.close"));
2866
+ setAttr(closeButton, "type", "button");
2867
+ setAttr(closeButton, "title", translate("plan.closeAria"));
2868
+ setAttr(closeButton, "aria-label", translate("plan.closeAria"));
2869
+ closeButton.addEventListener("click", () => {
2870
+ closePlanDialog();
2871
+ });
2872
+ head.appendChild(closeButton);
2873
+ dialog.appendChild(head);
2874
+
2875
+ const body = element(doc, "div", "hive-dialog-body");
2876
+
2877
+ const goalField = element(doc, "label", "hive-field");
2878
+ goalField.appendChild(element(doc, "span", "hive-field-label", translate("plan.goal")));
2879
+ const goalInput = element(doc, "textarea", "hive-textarea");
2880
+ goalInput.value = "";
2881
+ setAttr(goalInput, "placeholder", translate("plan.goalHint"));
2882
+ setAttr(goalInput, "aria-label", translate("plan.goal"));
2883
+ goalField.appendChild(goalInput);
2884
+ goalField.appendChild(element(doc, "span", "hive-field-hint", translate("plan.goalHint")));
2885
+ body.appendChild(goalField);
2886
+
2887
+ const row = element(doc, "div", "hive-field-row");
2888
+ const maxField = element(doc, "label", "hive-field is-narrow");
2889
+ maxField.appendChild(element(doc, "span", "hive-field-label", translate("plan.maxCards")));
2890
+ const maxInput = element(doc, "input", "hive-input");
2891
+ setAttr(maxInput, "type", "number");
2892
+ setAttr(maxInput, "min", String(MIN_PLAN_CARDS));
2893
+ setAttr(maxInput, "step", "1");
2894
+ setAttr(maxInput, "aria-label", translate("plan.maxCards"));
2895
+ maxInput.value = "8";
2896
+ maxField.appendChild(maxInput);
2897
+ maxField.appendChild(element(doc, "span", "hive-field-hint", translate("plan.maxCardsHint")));
2898
+ row.appendChild(maxField);
2899
+
2900
+ const previewButton = element(doc, "button", "hive-btn", translate("plan.preview"));
2901
+ setAttr(previewButton, "type", "button");
2902
+ setButtonCopy(previewButton, translate("plan.preview"), translate("plan.previewAria"));
2903
+ previewButton.addEventListener("click", () => {
2904
+ void previewPlan();
2905
+ });
2906
+ row.appendChild(previewButton);
2907
+ body.appendChild(row);
2908
+
2909
+ const previewHead = element(doc, "div", "hive-plan-preview-head");
2910
+ previewHead.appendChild(element(doc, "span", null, translate("plan.previewTitle")));
2911
+ const countNode = element(doc, "span", "hive-plan-count", "");
2912
+ previewHead.appendChild(countNode);
2913
+ body.appendChild(previewHead);
2914
+
2915
+ const listNode = element(doc, "div", "hive-plan-list");
2916
+ listNode.appendChild(element(doc, "div", "hive-plan-empty", translate("plan.empty")));
2917
+ body.appendChild(listNode);
2918
+ const hint = element(doc, "div", "hive-plan-hint", translate("plan.applyHint"));
2919
+ body.appendChild(hint);
2920
+
2921
+ const errorNode = element(doc, "div", "hive-plan-error", "");
2922
+ body.appendChild(errorNode);
2923
+ dialog.appendChild(body);
2924
+
2925
+ const foot = element(doc, "div", "hive-dialog-foot");
2926
+ const cancelButton = element(doc, "button", "hive-btn hive-btn-ghost", translate("plan.cancel"));
2927
+ setAttr(cancelButton, "type", "button");
2928
+ setAttr(cancelButton, "title", translate("plan.cancelAria"));
2929
+ setAttr(cancelButton, "aria-label", translate("plan.cancelAria"));
2930
+ cancelButton.addEventListener("click", () => {
2931
+ closePlanDialog();
2932
+ });
2933
+ foot.appendChild(cancelButton);
2934
+
2935
+ const applyButton = element(doc, "button", "hive-btn", translate("plan.write"));
2936
+ setAttr(applyButton, "type", "button");
2937
+ setButtonCopy(applyButton, translate("plan.write"), translate("plan.writeAria"));
2938
+ applyButton.disabled = true;
2939
+ applyButton.addEventListener("click", () => {
2940
+ void applyPlan();
2941
+ });
2942
+ foot.appendChild(applyButton);
2943
+ dialog.appendChild(foot);
2944
+
2945
+ overlay.appendChild(dialog);
2946
+ frame.appendChild(overlay);
2947
+ planOverlay = overlay;
2948
+ planDialogNode = dialog;
2949
+ planFocusables = [closeButton, goalInput, maxInput, previewButton, cancelButton, applyButton];
2950
+ planState = {
2951
+ cards: [],
2952
+ previewed: false,
2953
+ goal: "",
2954
+ maxCards: 8,
2955
+ token: 0,
2956
+ busy: false,
2957
+ nodes: {
2958
+ goal: goalInput,
2959
+ maxCards: maxInput,
2960
+ preview: previewButton,
2961
+ apply: applyButton,
2962
+ error: errorNode,
2963
+ list: listNode,
2964
+ count: countNode,
2965
+ },
2966
+ };
2967
+ if (typeof doc.addEventListener === "function") {
2968
+ doc.addEventListener("keydown", onPlanKeydown);
2969
+ }
2970
+ focusNode(goalInput);
2971
+ }
2972
+
2973
+ // --- bee count settings -------------------------------------------------
2974
+
2975
+ function currentSupervisorRow() {
2976
+ if (!lastModel) return null;
2977
+ return supervisorData.find((row) => row.repo === lastModel.repo) || null;
2978
+ }
2979
+
2980
+ function roleRowsForCurrentRepo(row) {
2981
+ const roles = new Map();
2982
+ if (row && Array.isArray(row.roles)) {
2983
+ for (const role of row.roles) {
2984
+ if (!isRecord(role)) continue;
2985
+ const name = asString(role.role);
2986
+ if (name) roles.set(name, { ...role, role: name });
2987
+ }
2988
+ }
2989
+ if (roles.size === 0 && lastModel) {
2990
+ for (const cards of Object.values(lastModel.lanes)) {
2991
+ for (const card of cards) {
2992
+ const name = asString(card.role);
2993
+ if (name && !roles.has(name)) roles.set(name, { role: name, limit: null, inFlight: null, queued: null });
2994
+ }
2995
+ }
2996
+ for (const name of Object.keys(lastModel.stats.byRole || {})) {
2997
+ if (name && !roles.has(name)) roles.set(name, { role: name, limit: null, inFlight: null, queued: null });
2998
+ }
2999
+ }
3000
+ return [...roles.values()].sort((left, right) => left.role.localeCompare(right.role));
3001
+ }
3002
+
3003
+ function limitsNumberText(value) {
3004
+ return supervisorNumber(value) === null ? "—" : String(supervisorNumber(value));
3005
+ }
3006
+
3007
+ function setLimitsError(message) {
3008
+ if (!limitsState) return;
3009
+ limitsState.errorNode.textContent = message || "";
3010
+ limitsState.errorNode.className = "hive-limits-error" + (message ? "" : " is-hidden");
3011
+ }
3012
+
3013
+ function limitsFocusableNodes() {
3014
+ return limitsFocusables.filter((node) => node && !node.disabled);
3015
+ }
3016
+
3017
+ function onLimitsKeydown(event) {
3018
+ if (!event) return;
3019
+ if (event.key === "Escape" || event.key === "Esc") {
3020
+ closeLimitsDialog();
3021
+ return;
3022
+ }
3023
+ if (event.key !== "Tab") return;
3024
+ const items = limitsFocusableNodes();
3025
+ if (items.length === 0) return;
3026
+ const active = doc.activeElement;
3027
+ let index = items.indexOf(active);
3028
+ if (index < 0) {
3029
+ if (typeof event.preventDefault === "function") event.preventDefault();
3030
+ focusNode(items[event.shiftKey ? items.length - 1 : 0]);
3031
+ return;
3032
+ }
3033
+ if (!event.shiftKey && index === items.length - 1) {
3034
+ if (typeof event.preventDefault === "function") event.preventDefault();
3035
+ focusNode(items[0]);
3036
+ } else if (event.shiftKey && index === 0) {
3037
+ if (typeof event.preventDefault === "function") event.preventDefault();
3038
+ focusNode(items[items.length - 1]);
3039
+ }
3040
+ }
3041
+
3042
+ function closeLimitsDialog(restoreFocus = true) {
3043
+ if (limitsOverlay && limitsOverlay.parentNode) limitsOverlay.parentNode.removeChild(limitsOverlay);
3044
+ limitsOverlay = null;
3045
+ limitsDialogNode = null;
3046
+ limitsState = null;
3047
+ limitsFocusables = [];
3048
+ if (typeof doc.removeEventListener === "function") {
3049
+ doc.removeEventListener("keydown", onLimitsKeydown);
3050
+ }
3051
+ if (restoreFocus && !destroyed) focusNode(limitsTriggerButton);
3052
+ }
3053
+
3054
+ function openLimitsDialog(trigger) {
3055
+ if (destroyed || !lastModel || !lastModel.writable || supervisorData.length === 0) return;
3056
+ closeHelp(false);
3057
+ closePlanDialog(false);
3058
+ closeDrawer();
3059
+ closeToast();
3060
+ if (limitsDialogNode) closeLimitsDialog(false);
3061
+ limitsTriggerButton = trigger || supervisorLimitsButton;
3062
+
3063
+ const repo = lastModel.repo || "";
3064
+ const rows = roleRowsForCurrentRepo(currentSupervisorRow());
3065
+ const overlay = element(doc, "div", "hive-overlay hive-dialog-scrim");
3066
+ overlay.addEventListener("click", (event) => {
3067
+ if (!event || !event.target || event.target === overlay) closeLimitsDialog();
3068
+ });
3069
+
3070
+ const dialog = element(doc, "div", "hive-dialog");
3071
+ setAttr(dialog, "role", "dialog");
3072
+ setAttr(dialog, "aria-modal", "true");
3073
+ setAttr(dialog, "aria-label", translate("limits.aria"));
3074
+
3075
+ const head = element(doc, "div", "hive-dialog-head");
3076
+ const titleBox = element(doc, "div", "hive-dialog-head-title");
3077
+ titleBox.appendChild(element(doc, "h2", "hive-dialog-title", translate("limits.title")));
3078
+ head.appendChild(titleBox);
3079
+ const closeButton = element(doc, "button", "hive-btn hive-btn-ghost", translate("limits.close"));
3080
+ setAttr(closeButton, "type", "button");
3081
+ setAttr(closeButton, "title", translate("limits.closeAria"));
3082
+ setAttr(closeButton, "aria-label", translate("limits.closeAria"));
3083
+ closeButton.addEventListener("click", () => {
3084
+ closeLimitsDialog();
3085
+ });
3086
+ head.appendChild(closeButton);
3087
+ dialog.appendChild(head);
3088
+
3089
+ const body = element(doc, "div", "hive-dialog-body");
3090
+ const repoLine = element(doc, "div", "hive-limits-repo");
3091
+ repoLine.appendChild(element(doc, "span", "hive-limits-repo-label", translate("init.repo")));
3092
+ const repoPath = element(doc, "code", "hive-limits-repo-path", repo);
3093
+ setAttr(repoPath, "title", repo);
3094
+ repoLine.appendChild(repoPath);
3095
+ body.appendChild(repoLine);
3096
+ body.appendChild(element(doc, "div", "hive-limits-description", translate("limits.description")));
3097
+
3098
+ const rowNodes = [];
3099
+ if (rows.length === 0) {
3100
+ body.appendChild(element(doc, "div", "hive-limits-empty", translate("limits.none")));
3101
+ } else {
3102
+ const table = element(doc, "div", "hive-limits-table");
3103
+ const header = element(doc, "div", "hive-limits-row is-head");
3104
+ header.appendChild(element(doc, "span", "hive-limits-cell", translate("limits.role")));
3105
+ header.appendChild(element(doc, "span", "hive-limits-cell is-number", translate("limits.limit")));
3106
+ header.appendChild(element(doc, "span", "hive-limits-cell is-number", translate("limits.inFlight")));
3107
+ header.appendChild(element(doc, "span", "hive-limits-cell is-number", translate("limits.queued")));
3108
+ table.appendChild(header);
3109
+
3110
+ for (const role of rows) {
3111
+ const roleRow = element(doc, "div", "hive-limits-row");
3112
+ roleRow.appendChild(element(doc, "span", "hive-limits-role", role.role));
3113
+ const input = element(doc, "input", "hive-input hive-limits-input");
3114
+ setAttr(input, "type", "number");
3115
+ setAttr(input, "min", "0");
3116
+ setAttr(input, "max", "999");
3117
+ setAttr(input, "step", "1");
3118
+ setAttr(input, "inputmode", "numeric");
3119
+ setAttr(input, "aria-label", translate("limits.limitAria").replace("{role}", role.role));
3120
+ input.value = supervisorNumber(role.limit) === null ? "5" : String(supervisorNumber(role.limit));
3121
+ roleRow.appendChild(input);
3122
+ roleRow.appendChild(element(doc, "span", "hive-limits-cell is-number", limitsNumberText(role.inFlight)));
3123
+ roleRow.appendChild(element(doc, "span", "hive-limits-cell is-number", limitsNumberText(role.queued)));
3124
+ table.appendChild(roleRow);
3125
+ rowNodes.push({ role: role.role, input });
3126
+ }
3127
+ body.appendChild(table);
3128
+ body.appendChild(element(doc, "div", "hive-limits-hint", translate("limits.defaultHint")));
3129
+ }
3130
+
3131
+ const errorNode = element(doc, "div", "hive-limits-error is-hidden", "");
3132
+ body.appendChild(errorNode);
3133
+ dialog.appendChild(body);
3134
+
3135
+ const foot = element(doc, "div", "hive-dialog-foot");
3136
+ const saveButton = element(doc, "button", "hive-btn", translate("limits.save"));
3137
+ setAttr(saveButton, "type", "button");
3138
+ setAttr(saveButton, "title", translate("limits.saveAria").replace("{repo}", repo));
3139
+ setAttr(saveButton, "aria-label", translate("limits.saveAria").replace("{repo}", repo));
3140
+ saveButton.disabled = rows.length === 0;
3141
+ saveButton.addEventListener("click", () => {
3142
+ void saveBeeCounts();
3143
+ });
3144
+ foot.appendChild(saveButton);
3145
+ dialog.appendChild(foot);
3146
+
3147
+ overlay.appendChild(dialog);
3148
+ frame.appendChild(overlay);
3149
+ limitsOverlay = overlay;
3150
+ limitsDialogNode = dialog;
3151
+ limitsState = {
3152
+ repo,
3153
+ rows: rowNodes,
3154
+ errorNode,
3155
+ saveButton,
3156
+ busy: false,
3157
+ };
3158
+ limitsFocusables = [closeButton, ...rowNodes.map((entry) => entry.input), saveButton];
3159
+ if (typeof doc.addEventListener === "function") {
3160
+ doc.addEventListener("keydown", onLimitsKeydown);
3161
+ }
3162
+ focusNode(rowNodes[0] ? rowNodes[0].input : closeButton);
3163
+ }
3164
+
3165
+ async function saveBeeCounts() {
3166
+ const state = limitsState;
3167
+ if (!state || state.busy) return;
3168
+ const roleLimits = {};
3169
+ let invalid = false;
3170
+ for (const entry of state.rows) {
3171
+ const raw = String(entry.input.value === null || entry.input.value === undefined ? "" : entry.input.value).trim();
3172
+ const number = Number(raw);
3173
+ if (!/^\d+$/.test(raw) || !Number.isInteger(number) || number < 0 || number > 999) {
3174
+ invalid = true;
3175
+ focusNode(entry.input);
3176
+ break;
3177
+ }
3178
+ roleLimits[entry.role] = number;
3179
+ }
3180
+ if (invalid) {
3181
+ setLimitsError(translate("limits.invalid"));
3182
+ return;
3183
+ }
3184
+ if (Object.keys(roleLimits).length === 0) {
3185
+ setLimitsError(translate("limits.none"));
3186
+ return;
3187
+ }
3188
+ if (!fetchImpl) {
3189
+ setLimitsError(translate("limits.failed"));
3190
+ return;
3191
+ }
3192
+
3193
+ state.busy = true;
3194
+ state.saveButton.disabled = true;
3195
+ state.saveButton.textContent = translate("limits.saving");
3196
+ for (const entry of state.rows) entry.input.disabled = true;
3197
+ setLimitsError("");
3198
+
3199
+ try {
3200
+ const response = await fetchImpl(supervisorEndpoint("limits"), {
3201
+ method: "POST",
3202
+ headers: { "content-type": "application/json", accept: "application/json" },
3203
+ body: JSON.stringify({ repo: state.repo, roleLimits }),
3204
+ });
3205
+ let payload = null;
3206
+ try {
3207
+ payload = response && typeof response.json === "function" ? await response.json() : null;
3208
+ } catch {
3209
+ payload = null;
3210
+ }
3211
+ if (!response || response.ok === false || (payload && payload.ok === false)) {
3212
+ const error = new Error("supervisor limits failed");
3213
+ error.stderr = asString(payload && (payload.stderr || payload.message));
3214
+ throw error;
3215
+ }
3216
+ if (destroyed) return;
3217
+ closeLimitsDialog(false);
3218
+ showToast("success", translate("limits.saved"), state.repo);
3219
+ await refreshSupervisor(true);
3220
+ } catch (error) {
3221
+ if (destroyed) return;
3222
+ state.busy = false;
3223
+ state.saveButton.disabled = false;
3224
+ state.saveButton.textContent = translate("limits.save");
3225
+ for (const entry of state.rows) entry.input.disabled = false;
3226
+ setLimitsError(actionErrorDetail(error) || translate("limits.failed"));
3227
+ }
3228
+ }
3229
+
3230
+ async function previewPlan() {
3231
+ const state = planState;
3232
+ if (!state || state.busy) return;
3233
+ const goal = fieldValue(state.nodes.goal).trim();
3234
+ const maxCards = Number(fieldValue(state.nodes.maxCards));
3235
+ if (!goal) {
3236
+ setPlanError(state, translate("plan.goalRequired"));
3237
+ focusNode(state.nodes.goal);
3238
+ return;
3239
+ }
3240
+ if (!Number.isInteger(maxCards) || maxCards < MIN_PLAN_CARDS) {
3241
+ setPlanError(state, translate("plan.maxInvalid"));
3242
+ focusNode(state.nodes.maxCards);
3243
+ return;
3244
+ }
3245
+
3246
+ state.token += 1;
3247
+ const token = state.token;
3248
+ state.cards = [];
3249
+ state.previewed = false;
3250
+ state.goal = "";
3251
+ state.maxCards = 0;
3252
+ renderPlanPreview(state);
3253
+ clearPlanError(state);
3254
+ updatePlanApply(state);
3255
+ setPlanBusy(state, true, "preview");
3256
+
3257
+ const result = await requestAction("plan", { goal, maxCards });
3258
+ if (destroyed || planState !== state || state.token !== token) return;
3259
+ setPlanBusy(state, false);
3260
+ if (!result.ok) {
3261
+ setPlanError(state, actionErrorDetail(result.error) || translate("plan.error"));
3262
+ reportError(result.error);
3263
+ return;
3264
+ }
3265
+ const plan = extractPlan(result.payload);
3266
+ state.cards = plan.cards;
3267
+ state.previewed = true;
3268
+ state.goal = goal;
3269
+ state.maxCards = maxCards;
3270
+ state.structured = plan.structured;
3271
+ renderPlanPreview(state);
3272
+ clearPlanError(state);
3273
+ updatePlanApply(state);
3274
+ if (plan.cards.length === 0 && !plan.structured && plan.raw) {
3275
+ setPlanError(state, translate("plan.previewFailed") + "\n" + summarizeActionOutput(plan.raw, 500));
3276
+ }
3277
+ }
3278
+
3279
+ async function applyPlan() {
3280
+ const state = planState;
3281
+ if (!state || state.busy) return;
3282
+ const goal = fieldValue(state.nodes.goal).trim();
3283
+ const maxCards = Number(fieldValue(state.nodes.maxCards));
3284
+ if (!state.previewed || state.cards.length === 0) {
3285
+ setPlanError(state, translate("plan.previewFirst"));
3286
+ return;
3287
+ }
3288
+ if (!Number.isInteger(maxCards) || maxCards < MIN_PLAN_CARDS) {
3289
+ setPlanError(state, translate("plan.maxInvalid"));
3290
+ return;
3291
+ }
3292
+ if (goal !== state.goal || maxCards !== state.maxCards) {
3293
+ setPlanError(state, translate("plan.stale"));
3294
+ return;
3295
+ }
3296
+
3297
+ state.token += 1;
3298
+ const token = state.token;
3299
+ clearPlanError(state);
3300
+ setPlanBusy(state, true, "apply");
3301
+ const result = await requestAction("plan", { goal, maxCards, apply: true });
3302
+ if (destroyed || planState !== state || state.token !== token) return;
3303
+ if (!result.ok) {
3304
+ setPlanBusy(state, false);
3305
+ setPlanError(state, actionErrorDetail(result.error) || translate("plan.error"));
3306
+ reportError(result.error);
3307
+ return;
3308
+ }
3309
+ closePlanDialog();
3310
+ if (!destroyed) await refresh();
3311
+ if (!destroyed) showToast("success", translate("toast.planWritten"), translate("toast.pickupHint"));
3312
+ }
3313
+
3314
+ // --- drawer --------------------------------------------------------------
3315
+
3316
+ function onDrawerKeydown(event) {
3317
+ if (event && (event.key === "Escape" || event.key === "Esc")) closeDrawer();
3318
+ }
3319
+
3320
+ function closeDrawer() {
3321
+ if (drawerNode && drawerNode.parentNode) drawerNode.parentNode.removeChild(drawerNode);
3322
+ drawerNode = null;
3323
+ drawerState = null;
3324
+ if (typeof doc.removeEventListener === "function") {
3325
+ doc.removeEventListener("keydown", onDrawerKeydown);
3326
+ }
3327
+ }
3328
+
3329
+ function mountDrawer(eyebrow, title, ariaLabel) {
3330
+ closeHelp(false);
3331
+ closePlanDialog(false);
3332
+ closeDrawer();
3333
+
3334
+ const panel = element(doc, "aside", "hive-drawer");
3335
+ setAttr(panel, "role", "dialog");
3336
+ setAttr(panel, "aria-label", ariaLabel || title);
3337
+
3338
+ const head = element(doc, "div", "hive-drawer-head");
3339
+ const titleBox = element(doc, "div", "hive-drawer-titlebox");
3340
+ titleBox.appendChild(element(doc, "div", "hive-drawer-eyebrow", eyebrow));
3341
+ titleBox.appendChild(element(doc, "h2", "hive-drawer-title", title));
3342
+ head.appendChild(titleBox);
3343
+
3344
+ const closeButton = element(doc, "button", "hive-btn hive-btn-ghost", translate("drawer.close"));
3345
+ setAttr(closeButton, "type", "button");
3346
+ setAttr(closeButton, "title", translate("drawer.closeAria"));
3347
+ setAttr(closeButton, "aria-label", translate("drawer.closeAria"));
3348
+ closeButton.addEventListener("click", closeDrawer);
3349
+ head.appendChild(closeButton);
3350
+ panel.appendChild(head);
3351
+
3352
+ const body = element(doc, "div", "hive-drawer-body");
3353
+ panel.appendChild(body);
3354
+
3355
+ // Keep the drawer inside the themed frame so it inherits host variable overrides.
3356
+ frame.appendChild(panel);
3357
+ drawerNode = panel;
3358
+ if (typeof doc.addEventListener === "function") {
3359
+ doc.addEventListener("keydown", onDrawerKeydown);
3360
+ }
3361
+ return body;
3362
+ }
3363
+
3364
+ function openAgentDrawer(agent) {
3365
+ const raw = findRawAgent(agent) || { ...agent };
3366
+ const title = agent.agent || translate("agent.unknown");
3367
+ const body = mountDrawer(
3368
+ agent.state || translate("agent.idle"),
3369
+ title,
3370
+ translate("agents.openAria") + " " + title,
3371
+ );
3372
+ drawerState = { kind: "agent", agent };
3373
+ body.appendChild(element(doc, "div", "hive-section-label", translate("drawer.rawJson")));
3374
+ body.appendChild(element(doc, "pre", "hive-json", JSON.stringify(raw, null, 2)));
3375
+ }
3376
+
3377
+ function openDrawer(card, lane) {
3378
+ const raw = findRawTask(card) || { ...card, state: lane };
3379
+ const title = card.title || translate("card.untitled");
3380
+ const body = mountDrawer(
3381
+ laneLabel(lane) + " · " + (card.id || translate("card.noId")),
3382
+ title,
3383
+ translate("drawer.cardAria") + " " + (card.title || card.id || translate("card.untitled")),
3384
+ );
3385
+ drawerState = { kind: "card", card, lane };
3386
+ const actions = actionsForState(lane, lastModel ? lastModel.writable : false);
3387
+
3388
+ if (actions.length > 0) {
3389
+ const actionRow = element(doc, "div", "hive-actions-row");
3390
+ setAttr(actionRow, "aria-label", translate("drawer.cardActions"));
3391
+ for (const action of actions) {
3392
+ const button = element(doc, "button", "hive-btn", translate(action.labelKey));
3393
+ setAttr(button, "type", "button");
3394
+ setAttr(button, "title", translate(action.helpKey));
3395
+ setAttr(button, "aria-label", translate(action.helpKey));
3396
+ button.addEventListener("click", () => {
3397
+ void runCardAction(action.name, card, lane);
3398
+ });
3399
+ actionRow.appendChild(button);
3400
+ }
3401
+ body.appendChild(actionRow);
3402
+ } else {
3403
+ const note = element(
3404
+ doc,
3405
+ "div",
3406
+ "hive-note",
3407
+ lastModel && lastModel.writable ? translate("drawer.noActions") : translate("drawer.readOnly"),
3408
+ );
3409
+ body.appendChild(note);
3410
+ }
3411
+
3412
+ const label = element(doc, "div", "hive-section-label", translate("drawer.rawJson"));
3413
+ body.appendChild(label);
3414
+ const pre = element(doc, "pre", "hive-json", JSON.stringify(raw, null, 2));
3415
+ body.appendChild(pre);
3416
+ }
3417
+
3418
+ // --- actions -------------------------------------------------------------
3419
+
3420
+ function makeActionFailure(name, payload, status) {
3421
+ const stderr = asString(payload && payload.stderr).trim();
3422
+ const stdout = asString(payload && payload.stdout).trim();
3423
+ const detail = stderr || stdout;
3424
+ const error = new Error(
3425
+ "hive action " +
3426
+ name +
3427
+ " failed" +
3428
+ (status ? " (HTTP " + status + ")" : "") +
3429
+ (detail ? ": " + summarizeActionOutput(detail) : ""),
3430
+ );
3431
+ error.action = name;
3432
+ error.stderr = stderr;
3433
+ error.stdout = stdout;
3434
+ error.code = payload && payload.code;
3435
+ return error;
3436
+ }
3437
+
3438
+ async function requestAction(name, body) {
3439
+ if (!fetchImpl) return { ok: false, error: new Error("hive: fetch is not available") };
3440
+ // The DSH host half advertises actionsUrl as
3441
+ // "/api/hive?op=action&name={name}&sessionId=..."; the standalone page keeps
3442
+ // the historical "/api/actions/<name>" shape.
3443
+ const url = actionsUrl.indexOf("{name}") >= 0
3444
+ ? actionsUrl.replace("{name}", encodeURIComponent(name))
3445
+ : actionsUrl + "/" + encodeURIComponent(name);
3446
+ let response;
3447
+ try {
3448
+ response = await fetchImpl(url, {
3449
+ method: "POST",
3450
+ headers: { "content-type": "application/json" },
3451
+ body: JSON.stringify(body || {}),
3452
+ });
3453
+ } catch (error) {
3454
+ return { ok: false, error };
3455
+ }
3456
+ let payload = null;
3457
+ try {
3458
+ payload = await response.json();
3459
+ } catch {
3460
+ payload = null;
3461
+ }
3462
+ if (!response || response.ok === false) {
3463
+ return { ok: false, error: makeActionFailure(name, payload, response ? response.status : 0) };
3464
+ }
3465
+ if (payload && payload.ok === false) {
3466
+ return { ok: false, error: makeActionFailure(name, payload, response.status) };
3467
+ }
3468
+ return { ok: true, payload: payload && typeof payload === "object" ? payload : {} };
3469
+ }
3470
+
3471
+ async function postAction(name, body) {
3472
+ if (destroyed) return false;
3473
+ const result = await requestAction(name, body);
3474
+ if (!result.ok) {
3475
+ if (!destroyed) {
3476
+ setStatus("status.actionFailed", "error");
3477
+ reportError(result.error);
3478
+ showToast("error", translate("status.actionFailed"), actionErrorDetail(result.error));
3479
+ }
3480
+ return false;
3481
+ }
3482
+ if (!destroyed) {
3483
+ closeToast();
3484
+ await refresh();
3485
+ }
3486
+ return result.payload;
3487
+ }
3488
+
3489
+ async function runQueenOn(button) {
3490
+ if (destroyed || queenBusy) return;
3491
+ const model = lastModel;
3492
+ if (!model || model.initialised === false || (model.queen && model.queen.active)) return;
3493
+ queenBusy = true;
3494
+ renderQueenHint(model);
3495
+ try {
3496
+ await postAction("queen-on", {});
3497
+ } finally {
3498
+ queenBusy = false;
3499
+ if (!destroyed && lastModel) renderQueenHint(lastModel);
3500
+ else if (button && typeof button.focus === "function") button.focus();
3501
+ }
3502
+ }
3503
+
3504
+ async function runInitialise() {
3505
+ if (destroyed || initBusy) return;
3506
+ const model = lastModel;
3507
+ if (!model || model.initialised !== false || !model.writable) return;
3508
+
3509
+ initBusy = true;
3510
+ initOutput = null;
3511
+ initErrorMessage = "";
3512
+ initRequestSeq += 1;
3513
+ const requestId = initRequestSeq;
3514
+ renderInit(model);
3515
+ renderQueenHint(model);
3516
+
3517
+ let result;
3518
+ try {
3519
+ result = await requestAction("init", {});
3520
+ } catch (error) {
3521
+ if (destroyed || requestId !== initRequestSeq) return;
3522
+ initBusy = false;
3523
+ initErrorMessage = actionErrorDetail(error) || translate("init.failed");
3524
+ reportError(error);
3525
+ if (lastModel) {
3526
+ renderInit(lastModel);
3527
+ renderQueenHint(lastModel);
3528
+ }
3529
+ return;
3530
+ }
3531
+ if (destroyed || requestId !== initRequestSeq) return;
3532
+
3533
+ initBusy = false;
3534
+ const payload = result.ok ? result.payload : null;
3535
+ const stdout = asString(payload && payload.stdout) || asString(result.error && result.error.stdout);
3536
+ const stderr = asString(payload && payload.stderr) || asString(result.error && result.error.stderr);
3537
+ initOutput = { ok: result.ok, stdout, stderr };
3538
+
3539
+ if (!result.ok) {
3540
+ initErrorMessage = actionErrorDetail(result.error) || translate("init.failed");
3541
+ reportError(result.error);
3542
+ if (lastModel) {
3543
+ renderInit(lastModel);
3544
+ renderQueenHint(lastModel);
3545
+ }
3546
+ return;
3547
+ }
3548
+
3549
+ queenNotice = true;
3550
+ initErrorMessage = "";
3551
+ if (lastModel) {
3552
+ renderInit(lastModel);
3553
+ renderQueenHint(lastModel);
3554
+ }
3555
+ await forceRefresh();
3556
+ }
3557
+
3558
+ async function runToolbarAction(action, triggerButton) {
3559
+ if (destroyed || !action) return;
3560
+ switch (action.name) {
3561
+ case "mode":
3562
+ await postAction("mode", action.body || { mode: "free", reason: "panel" });
3563
+ break;
3564
+ case "add": {
3565
+ const title = ask(translate("prompt.newTitle"), "");
3566
+ if (title === null || !title.trim()) return;
3567
+ const role = ask(translate("prompt.role"), "coder");
3568
+ if (role === null) return;
3569
+ const scope = ask(translate("prompt.scope"), "");
3570
+ if (scope === null) return;
3571
+ const after = ask(translate("prompt.after"), "");
3572
+ if (after === null) return;
3573
+ await postAction("add", {
3574
+ title: title.trim(),
3575
+ role: role.trim() || "coder",
3576
+ scope: splitList(scope),
3577
+ after: splitList(after),
3578
+ });
3579
+ break;
3580
+ }
3581
+ case "plan":
3582
+ openPlanDialog(triggerButton);
3583
+ break;
3584
+ case "commit": {
3585
+ const message = ask(translate("prompt.commitMessage"), "panel commit");
3586
+ if (message === null) return;
3587
+ const paths = ask(translate("prompt.paths"), "");
3588
+ if (paths === null) return;
3589
+ await postAction("commit", { message: message.trim() || "panel commit", set: splitList(paths) });
3590
+ break;
3591
+ }
3592
+ default:
3593
+ break;
3594
+ }
3595
+ }
3596
+
3597
+ async function runCardAction(name, card, lane) {
3598
+ if (destroyed) return;
3599
+ let ok = false;
3600
+ switch (name) {
3601
+ case "claim": {
3602
+ const agent = ask(translate("prompt.claimAgent"), "panel");
3603
+ if (agent === null) return;
3604
+ ok = await postAction("claim", { id: card.id, agent: agent.trim() || "panel" });
3605
+ break;
3606
+ }
3607
+ case "done": {
3608
+ const sha = ask(translate("prompt.commitSha"), "");
3609
+ if (sha === null) return;
3610
+ const body = { id: card.id };
3611
+ if (sha.trim()) body.sha = sha.trim();
3612
+ ok = await postAction("done", body);
3613
+ break;
3614
+ }
3615
+ case "fail": {
3616
+ const reason = ask(translate("prompt.failReason"), "");
3617
+ if (reason === null || !reason.trim()) return;
3618
+ ok = await postAction("fail", { id: card.id, reason: reason.trim() });
3619
+ break;
3620
+ }
3621
+ case "retry":
3622
+ ok = await postAction("retry", { id: card.id });
3623
+ break;
3624
+ default:
3625
+ break;
3626
+ }
3627
+ if (ok && !destroyed) {
3628
+ closeDrawer();
3629
+ void refresh();
3630
+ }
3631
+ }
3632
+
3633
+ // --- rendering -----------------------------------------------------------
3634
+
3635
+ function renderInit(model) {
3636
+ const uninitialised = model.initialised === false;
3637
+ frame.className = "hive" + (uninitialised ? " is-uninitialised" : "");
3638
+ const repo = model.repo || "—";
3639
+ initRepoLabel.textContent = translate("init.repo");
3640
+ initRepo.textContent = repo;
3641
+ setAttr(initRepo, "title", repo);
3642
+ initTitle.textContent = translate("init.title");
3643
+ initDescription.textContent = translate("init.description");
3644
+
3645
+ initButton.disabled = !model.writable || initBusy;
3646
+ const buttonLabel = initBusy ? translate("init.busy") : translate("init.button");
3647
+ const buttonAria = initBusy
3648
+ ? translate("init.busy")
3649
+ : model.writable
3650
+ ? translate("init.buttonAria")
3651
+ : translate("init.readOnlyAria");
3652
+ initButton.textContent = buttonLabel;
3653
+ setAttr(initButton, "title", buttonAria);
3654
+ setAttr(initButton, "aria-label", buttonAria);
3655
+ setAttr(initCard, "aria-busy", initBusy ? "true" : "false");
3656
+
3657
+ initReadOnly.textContent = model.writable ? "" : translate("init.readOnly");
3658
+ initReadOnly.className = "hive-init-readonly" + (model.writable ? " is-hidden" : "");
3659
+ initProgress.className = "hive-init-progress" + (initBusy ? "" : " is-hidden");
3660
+ initProgressText.textContent = translate("init.busy");
3661
+ initError.className = "hive-init-error" + (initErrorMessage ? "" : " is-hidden");
3662
+ initError.textContent = initErrorMessage ? translate("init.failed") + ": " + initErrorMessage : "";
3663
+ initOutputSummary.textContent = translate("init.output");
3664
+ setAttr(initOutputSummary, "title", translate("init.output"));
3665
+ initOutputPre.textContent = initOutput && initOutput.stdout ? initOutput.stdout : translate("init.noOutput");
3666
+ }
3667
+
3668
+ function renderQueenHint(model) {
3669
+ const initialised = Boolean(model && model.initialised !== false);
3670
+ const state = model && isRecord(model.queen) ? model.queen : null;
3671
+ const active = state ? state.active === true : Boolean(queenNotice);
3672
+ const show = initialised && Boolean(state || queenNotice);
3673
+ const offer = show && !active;
3674
+
3675
+ if (initialised && state) {
3676
+ const source =
3677
+ state.source === "auto"
3678
+ ? translate("queen.source.auto")
3679
+ : state.source === "manual"
3680
+ ? translate("queen.source.manual")
3681
+ : "";
3682
+ const title = active
3683
+ ? source
3684
+ ? translate("queen.activeTitle").replace("{source}", source)
3685
+ : translate("queen.status.active")
3686
+ : translate("queen.inactiveTitle");
3687
+ queenBadge.className = "hive-queen-badge " + (active ? "is-active" : "is-inactive");
3688
+ queenBadge.textContent = active ? translate("queen.status.active") : translate("queen.status.inactive");
3689
+ setAttr(queenBadge, "title", title);
3690
+ setAttr(queenBadge, "aria-label", title);
3691
+ } else {
3692
+ queenBadge.className = "hive-queen-badge is-hidden";
3693
+ queenBadge.textContent = "";
3694
+ setAttr(queenBadge, "title", "");
3695
+ setAttr(queenBadge, "aria-label", "");
3696
+ }
3697
+
3698
+ queenHint.className = "hive-queen-hint" + (show ? " is-visible" : "") + (offer ? " is-offer" : "");
3699
+ queenHintText.textContent = active ? translate("init.queen") : translate("queen.offer");
3700
+ queenOffer.className = "hive-queen-offer" + (offer ? "" : " is-hidden");
3701
+ queenTakeoverButton.disabled = queenBusy;
3702
+ queenTakeoverButton.textContent = queenBusy ? translate("queen.takeoverBusy") : translate("queen.takeover");
3703
+ const takeoverAria = queenBusy ? translate("queen.takeoverBusy") : translate("queen.takeoverAria");
3704
+ setAttr(queenTakeoverButton, "title", takeoverAria);
3705
+ setAttr(queenTakeoverButton, "aria-label", takeoverAria);
3706
+
3707
+ queenExit.className = "hive-queen-exit" + (active ? "" : " is-hidden");
3708
+ queenExitText.textContent = translate("init.queenExit");
3709
+ queenCommand.textContent = translate("init.queenCommand");
3710
+ queenOutputSummary.textContent = translate("init.queenOutput");
3711
+ setAttr(queenOutputSummary, "title", translate("init.queenOutput"));
3712
+ const output = initOutput && initOutput.stdout ? initOutput.stdout : translate("init.noOutput");
3713
+ queenOutputPre.textContent = output;
3714
+ queenOutputDetails.className =
3715
+ "hive-init-output hive-queen-output" + (show && active && initOutput ? "" : " is-hidden");
3716
+ }
3717
+
3718
+ function supervisorEndpoint(op) {
3719
+ const base = supervisorUrl.split("#")[0];
3720
+ const separator = !base.includes("?") ? "?" : /[?&]$/.test(base) ? "" : "&";
3721
+ return base + separator + "op=" + op;
3722
+ }
3723
+
3724
+ function renderSupervisor() {
3725
+ try {
3726
+ renderSupervisorContent();
3727
+ } catch {
3728
+ supervisorData = [];
3729
+ try {
3730
+ supervisorBar.className = "hive-supervisor is-hidden";
3731
+ supervisorLimitsButton.className = "hive-btn hive-btn-ghost hive-supervisor-limits is-hidden";
3732
+ if (limitsDialogNode) closeLimitsDialog(false);
3733
+ } catch {
3734
+ // Supervisor rendering is optional; never let it break the panel.
3735
+ }
3736
+ }
3737
+ }
3738
+
3739
+ function renderSupervisorContent() {
3740
+ clearNode(supervisorRepos);
3741
+ supervisorLabel.textContent = translate("supervisor.label");
3742
+ setAttr(supervisorBar, "aria-label", translate("supervisor.aria"));
3743
+ if (!Array.isArray(supervisorData) || supervisorData.length === 0) {
3744
+ supervisorBar.className = "hive-supervisor is-hidden";
3745
+ supervisorLimitsButton.className = "hive-btn hive-btn-ghost hive-supervisor-limits is-hidden";
3746
+ if (limitsDialogNode) closeLimitsDialog(false);
3747
+ return;
3748
+ }
3749
+ supervisorBar.className = "hive-supervisor";
3750
+ const canConfigure = Boolean(lastModel && lastModel.writable);
3751
+ supervisorLimitsButton.className = "hive-btn hive-btn-ghost hive-supervisor-limits" + (canConfigure ? "" : " is-hidden");
3752
+ supervisorLimitsButton.textContent = translate("limits.open");
3753
+ setAttr(supervisorLimitsButton, "title", translate("limits.openAria"));
3754
+ setAttr(supervisorLimitsButton, "aria-label", translate("limits.openAria"));
3755
+ if (!canConfigure && limitsDialogNode) closeLimitsDialog(false);
3756
+ for (const row of supervisorData) {
3757
+ const item = element(doc, "span", "hive-supervisor-item");
3758
+ const path = element(doc, "code", "hive-supervisor-path", row.repo);
3759
+ setAttr(path, "title", row.repo);
3760
+ item.appendChild(path);
3761
+
3762
+ let stateLabel = translate("supervisor.idle");
3763
+ if (row.state === "running") {
3764
+ stateLabel =
3765
+ row.running === null || row.running === undefined
3766
+ ? translate("supervisor.running")
3767
+ : translate("supervisor.runningCount").replace("{count}", String(row.running));
3768
+ } else if (row.state === "backoff") {
3769
+ stateLabel = translate("supervisor.backoff");
3770
+ } else if (row.state === "paused") {
3771
+ stateLabel = translate("supervisor.paused");
3772
+ }
3773
+ item.appendChild(element(doc, "span", "hive-supervisor-state is-" + row.state, stateLabel));
3774
+
3775
+ if (row.state === "paused") {
3776
+ const button = element(doc, "button", "hive-btn hive-supervisor-resume", translate("supervisor.resume"));
3777
+ setAttr(button, "type", "button");
3778
+ const aria = translate("supervisor.resumeAria").replace("{repo}", row.repo);
3779
+ setAttr(button, "title", aria);
3780
+ setAttr(button, "aria-label", aria);
3781
+ button.addEventListener("click", () => {
3782
+ void resumeSupervisor(row, button);
3783
+ });
3784
+ item.appendChild(button);
3785
+ }
3786
+ supervisorRepos.appendChild(item);
3787
+ }
3788
+ }
3789
+
3790
+ function setSupervisorData(rows) {
3791
+ supervisorData = Array.isArray(rows) ? rows : [];
3792
+ renderSupervisor();
3793
+ }
3794
+
3795
+ async function refreshSupervisor(force = false) {
3796
+ if (destroyed) return;
3797
+ if (!fetchImpl) {
3798
+ setSupervisorData([]);
3799
+ return;
3800
+ }
3801
+ if (supervisorRequest) {
3802
+ if (!force) return supervisorRequest;
3803
+ try {
3804
+ await supervisorRequest;
3805
+ } catch {
3806
+ // A failed status read is intentionally silent.
3807
+ }
3808
+ }
3809
+ if (destroyed) return;
3810
+ const request = (async () => {
3811
+ try {
3812
+ const response = await fetchImpl(supervisorEndpoint("status"), {
3813
+ cache: "no-store",
3814
+ headers: { accept: "application/json" },
3815
+ });
3816
+ if (!response || response.ok === false) throw new Error("supervisor status failed");
3817
+ let payload = null;
3818
+ try {
3819
+ payload = await response.json();
3820
+ } catch {
3821
+ payload = null;
3822
+ }
3823
+ if (!destroyed) setSupervisorData(normalizeSupervisorStatus(payload));
3824
+ } catch {
3825
+ // The supervisor service is optional; hide the strip without reporting.
3826
+ if (!destroyed) setSupervisorData([]);
3827
+ }
3828
+ })();
3829
+ supervisorRequest = request;
3830
+ try {
3831
+ await request;
3832
+ } finally {
3833
+ if (supervisorRequest === request) supervisorRequest = null;
3834
+ }
3835
+ }
3836
+
3837
+ async function resumeSupervisor(row, button) {
3838
+ if (destroyed || !fetchImpl) return;
3839
+ if (button) button.disabled = true;
3840
+ try {
3841
+ const response = await fetchImpl(supervisorEndpoint("resume"), {
3842
+ method: "POST",
3843
+ headers: { "content-type": "application/json", accept: "application/json" },
3844
+ body: JSON.stringify({ repo: row.repo }),
3845
+ });
3846
+ if (!response || response.ok === false) throw new Error("supervisor resume failed");
3847
+ let payload = null;
3848
+ try {
3849
+ payload = await response.json();
3850
+ } catch {
3851
+ payload = null;
3852
+ }
3853
+ if (payload && payload.ok === false) throw new Error("supervisor resume failed");
3854
+ await refreshSupervisor(true);
3855
+ } catch (error) {
3856
+ if (button) button.disabled = false;
3857
+ if (!destroyed) {
3858
+ showToast("error", translate("supervisor.resumeFailed"), actionErrorDetail(error) || translate("supervisor.resumeFailed"));
3859
+ }
3860
+ }
3861
+ }
3862
+
3863
+ function durationLabel(count, singularKey, pluralKey) {
3864
+ const key = count === 1 ? singularKey : pluralKey;
3865
+ return translate(key).replace("{count}", String(count));
3866
+ }
3867
+
3868
+ function elapsedLabel(createdAt) {
3869
+ const date = parseDate(createdAt);
3870
+ if (!date) return "";
3871
+ const seconds = Math.max(0, Math.floor((Date.now() - date.getTime()) / 1000));
3872
+ if (seconds < 60) return translate("stats.duration.justNow");
3873
+ const minutes = Math.floor(seconds / 60);
3874
+ if (minutes < 60) return durationLabel(minutes, "stats.duration.minute", "stats.duration.minutes");
3875
+ const hours = Math.floor(minutes / 60);
3876
+ if (hours < 24) return durationLabel(hours, "stats.duration.hour", "stats.duration.hours");
3877
+ return durationLabel(Math.floor(hours / 24), "stats.duration.day", "stats.duration.days");
3878
+ }
3879
+
3880
+ function renderStats(model) {
3881
+ clearNode(statsNode);
3882
+ const total = element(doc, "span", "hive-stat is-total");
3883
+ total.appendChild(element(doc, "strong", null, String(model.stats.total)));
3884
+ total.appendChild(element(doc, "span", "hive-stat-unit", " " + translate("stats.cards")));
3885
+ statsNode.appendChild(total);
3886
+
3887
+ for (const state of LANE_ORDER) {
3888
+ const count = model.stats.byState[state];
3889
+ if (count === undefined || count === null) continue;
3890
+ const pill = element(doc, "span", "hive-stat", laneLabel(state) + " " + count);
3891
+ statsNode.appendChild(pill);
3892
+ }
3893
+
3894
+ if (model.stats.oldestPending) {
3895
+ const pending = model.stats.oldestPending;
3896
+ const duration = elapsedLabel(pending.createdAt);
3897
+ const label = translate("stats.oldest") + (duration ? " " + duration : "");
3898
+ const oldest = element(doc, "span", "hive-stat is-warn hive-oldest");
3899
+ oldest.appendChild(element(doc, "span", "hive-oldest-label", label));
3900
+ if (pending.id) {
3901
+ oldest.appendChild(element(doc, "span", "hive-oldest-sep", " · "));
3902
+ oldest.appendChild(element(doc, "code", "hive-oldest-id", pending.id));
3903
+ }
3904
+ setAttr(oldest, "title", label + (pending.id ? " · " + pending.id : ""));
3905
+ statsNode.appendChild(oldest);
3906
+ }
3907
+
3908
+ const roleSummary = Object.keys(model.stats.byRole)
3909
+ .map((role) => role + " " + asCount(model.stats.byRole[role], 0))
3910
+ .join(" · ");
3911
+ setAttr(statsNode, "title", roleSummary ? translate("stats.byRoleTitle") + roleSummary : "");
3912
+ }
3913
+
3914
+ function renderFreezeBanner(model) {
3915
+ clearNode(freezeSlot);
3916
+ if (model.initialised === false || model.mode !== "freeze") return;
3917
+ const banner = element(doc, "div", "hive-freeze-banner");
3918
+ setAttr(banner, "role", "status");
3919
+ banner.appendChild(element(doc, "span", "hive-freeze-text", translate("mode.freeze.banner")));
3920
+ if (model.writable) {
3921
+ const button = element(doc, "button", "hive-btn", translate("action.unfreeze"));
3922
+ setAttr(button, "type", "button");
3923
+ setAttr(button, "title", translate("help.action.unfreeze"));
3924
+ setAttr(button, "aria-label", translate("help.action.unfreeze"));
3925
+ button.addEventListener("click", () => {
3926
+ void postAction("mode", { mode: "free", reason: "panel" });
3927
+ });
3928
+ banner.appendChild(button);
3929
+ }
3930
+ freezeSlot.appendChild(banner);
3931
+ }
3932
+
3933
+ function renderActions(model) {
3934
+ clearNode(actionsNode);
3935
+ for (const action of model.actions) {
3936
+ const button = element(doc, "button", "hive-btn", translate(action.labelKey));
3937
+ setAttr(button, "type", "button");
3938
+ setAttr(button, "title", translate(action.helpKey));
3939
+ setAttr(button, "aria-label", translate(action.helpKey));
3940
+ button.addEventListener("click", () => {
3941
+ void runToolbarAction(action, button);
3942
+ });
3943
+ if (action.name === "plan" && planDialogNode) planTriggerButton = button;
3944
+ actionsNode.appendChild(button);
3945
+ }
3946
+ }
3947
+
3948
+ function renderAgents(model) {
3949
+ clearNode(agentPills);
3950
+ if (model.initialised === false) {
3951
+ agentsCount.textContent = "0";
3952
+ return;
3953
+ }
3954
+ agentsCount.textContent = String(model.agents.length);
3955
+ if (model.agents.length === 0) {
3956
+ agentPills.appendChild(element(doc, "span", "hive-agents-empty", translate("agents.empty")));
3957
+ return;
3958
+ }
3959
+ for (const agent of model.agents) {
3960
+ const name = agent.agent || translate("agent.unknown");
3961
+ const task = agent.task || translate("agent.idle");
3962
+ const pill = element(doc, "button", "hive-agent-pill");
3963
+ setAttr(pill, "type", "button");
3964
+ const label =
3965
+ translate("agents.openAria") +
3966
+ " " +
3967
+ name +
3968
+ " · " +
3969
+ (agent.state || translate("agent.idle")) +
3970
+ " · " +
3971
+ task;
3972
+ setAttr(pill, "title", label);
3973
+ setAttr(pill, "aria-label", label);
3974
+
3975
+ pill.appendChild(element(doc, "span", "hive-agent-pill-name", name));
3976
+ const dot = element(doc, "span", "hive-dot is-" + safeClassToken(agent.state));
3977
+ setAttr(dot, "title", agent.state || translate("agent.idle"));
3978
+ pill.appendChild(dot);
3979
+ const taskNode = element(doc, "span", "hive-agent-pill-task", task);
3980
+ setAttr(taskNode, "title", task);
3981
+ pill.appendChild(taskNode);
3982
+
3983
+ pill.addEventListener("click", () => {
3984
+ openAgentDrawer(agent);
3985
+ });
3986
+ agentPills.appendChild(pill);
3987
+ }
3988
+ }
3989
+
3990
+ function renderCard(card, lane) {
3991
+ const node = element(doc, "article", "hive-card");
3992
+ setAttr(node, "tabindex", "0");
3993
+ setAttr(node, "role", "button");
3994
+ const openLabel = translate("card.openAria") + " " + (card.title || card.id || translate("card.untitled"));
3995
+ setAttr(node, "aria-label", openLabel);
3996
+ setAttr(node, "title", openLabel);
3997
+
3998
+ node.appendChild(element(doc, "div", "hive-card-title", card.title || translate("card.untitled")));
3999
+
4000
+ const meta = [];
4001
+ if (card.role) meta.push(translate("card.role") + " " + card.role);
4002
+ if (card.owner) meta.push(translate("card.owner") + " " + card.owner);
4003
+ if (meta.length) node.appendChild(element(doc, "div", "hive-card-meta", meta.join(" · ")));
4004
+
4005
+ if (card.scope.length) {
4006
+ const scopes = element(doc, "div", "hive-scopes");
4007
+ for (const scope of card.scope) {
4008
+ const chip = element(doc, "span", "hive-scope", scope);
4009
+ setAttr(chip, "title", scope);
4010
+ scopes.appendChild(chip);
4011
+ }
4012
+ node.appendChild(scopes);
4013
+ }
4014
+
4015
+ if (card.reason) {
4016
+ node.appendChild(element(doc, "div", "hive-reason", card.reason));
4017
+ }
4018
+
4019
+ const foot = element(doc, "div", "hive-card-foot");
4020
+ foot.appendChild(element(doc, "span", "hive-card-id", card.id || translate("card.noId")));
4021
+ foot.appendChild(element(doc, "span", "hive-card-state", laneLabel(lane)));
4022
+ node.appendChild(foot);
4023
+
4024
+ node.addEventListener("click", () => openDrawer(card, lane));
4025
+ node.addEventListener("keydown", (event) => {
4026
+ if (!event || (event.key !== "Enter" && event.key !== " ")) return;
4027
+ if (typeof event.preventDefault === "function") event.preventDefault();
4028
+ openDrawer(card, lane);
4029
+ });
4030
+ return node;
4031
+ }
4032
+
4033
+ function renderStageChips(model) {
4034
+ clearNode(stageChips);
4035
+ setAttr(stageChips, "aria-label", translate("board.filtersAria"));
4036
+ stageChipEntries = [];
4037
+ if (model.initialised === false) return;
4038
+ const total = LANE_ORDER.reduce((sum, lane) => sum + (model.lanes[lane] || []).length, 0);
4039
+ const addChip = (filter, text, label) => {
4040
+ const chip = element(doc, "button", "hive-stage-chip" + (stageFilter === filter ? " is-active" : ""));
4041
+ setAttr(chip, "type", "button");
4042
+ setAttr(chip, "aria-pressed", stageFilter === filter ? "true" : "false");
4043
+ setAttr(chip, "title", label);
4044
+ setAttr(chip, "aria-label", label);
4045
+ chip.textContent = text;
4046
+ chip.addEventListener("click", () => {
4047
+ selectStageFilter(filter);
4048
+ });
4049
+ stageChips.appendChild(chip);
4050
+ stageChipEntries.push({ filter, chip });
4051
+ };
4052
+ addChip("all", translate("board.all") + " " + total, translate("board.showAll"));
4053
+ for (const lane of LANE_ORDER) {
4054
+ const count = (model.lanes[lane] || []).length;
4055
+ const label = laneLabel(lane);
4056
+ addChip(
4057
+ lane,
4058
+ label + " " + count,
4059
+ translate("board.filterChip").replace("{lane}", label).replace("{count}", String(count)),
4060
+ );
4061
+ }
4062
+ }
4063
+
4064
+ function selectStageFilter(filter) {
4065
+ stageFilter = filter;
4066
+ for (const entry of stageChipEntries) {
4067
+ entry.chip.className = "hive-stage-chip" + (entry.filter === filter ? " is-active" : "");
4068
+ setAttr(entry.chip, "aria-pressed", entry.filter === filter ? "true" : "false");
4069
+ }
4070
+ if (lastModel) renderLanes(lastModel);
4071
+ }
4072
+
4073
+ function renderLanes(model) {
4074
+ clearNode(lanesNode);
4075
+ if (model.initialised === false) {
4076
+ boardCount.textContent = "0";
4077
+ filterEmpty.textContent = "";
4078
+ filterEmpty.className = "hive-filter-empty";
4079
+ return;
4080
+ }
4081
+ boardCount.textContent = String(model.stats.total);
4082
+ for (const lane of LANE_ORDER) {
4083
+ const cards = model.lanes[lane] || [];
4084
+ const classes = ["hive-lane", "hive-lane-" + lane];
4085
+ if (cards.length === 0) classes.push("is-empty");
4086
+ if (stageFilter !== "all" && stageFilter !== lane) classes.push("is-filtered-out");
4087
+ const column = element(doc, "section", classes.join(" "));
4088
+ const head = element(doc, "div", "hive-lane-head");
4089
+ head.appendChild(element(doc, "span", "hive-lane-name", laneLabel(lane)));
4090
+ head.appendChild(element(doc, "span", "hive-count", String(cards.length)));
4091
+ column.appendChild(head);
4092
+
4093
+ const list = element(doc, "div", "hive-lane-cards");
4094
+ if (cards.length === 0) {
4095
+ list.appendChild(emptyState("—"));
4096
+ } else {
4097
+ for (const card of cards) list.appendChild(renderCard(card, lane));
4098
+ }
4099
+ column.appendChild(list);
4100
+ lanesNode.appendChild(column);
4101
+ }
4102
+
4103
+ const visible = stageFilter === "all" ? model.lanes : { [stageFilter]: model.lanes[stageFilter] || [] };
4104
+ const visibleCount = Object.values(visible).reduce((sum, cards) => sum + (cards || []).length, 0);
4105
+ if (visibleCount === 0) {
4106
+ filterEmpty.textContent = translate("board.emptyFilter");
4107
+ filterEmpty.className = "hive-filter-empty is-visible";
4108
+ } else {
4109
+ filterEmpty.textContent = "";
4110
+ filterEmpty.className = "hive-filter-empty";
4111
+ }
4112
+ }
4113
+
4114
+ function renderEvents(model) {
4115
+ clearNode(eventsList);
4116
+ eventsLabel.textContent = translate("pane.events");
4117
+ if (model.initialised === false) {
4118
+ eventsCount.textContent = "0";
4119
+ eventsCaret.textContent = "▸";
4120
+ eventsDrawer.className = "hive-events-drawer";
4121
+ setAttr(eventsToggle, "aria-expanded", "false");
4122
+ return;
4123
+ }
4124
+ eventsCount.textContent = String(model.events.length);
4125
+ eventsCaret.textContent = eventsExpanded ? "▾" : "▸";
4126
+ eventsDrawer.className = "hive-events-drawer" + (eventsExpanded ? " is-open" : "");
4127
+ setAttr(eventsToggle, "aria-expanded", eventsExpanded ? "true" : "false");
4128
+ const toggleLabel = eventsExpanded ? translate("events.collapse") : translate("events.showAll");
4129
+ setAttr(eventsToggle, "title", toggleLabel);
4130
+ setAttr(eventsToggle, "aria-label", toggleLabel);
4131
+
4132
+ const events = eventsExpanded ? model.events : model.events.slice(0, 3);
4133
+ if (events.length === 0) {
4134
+ eventsList.appendChild(emptyState(translate("events.empty")));
4135
+ return;
4136
+ }
4137
+ for (const event of events) {
4138
+ const row = element(doc, "div", "hive-event");
4139
+ const time = element(doc, "time", "hive-event-time", formatTime(event.ts));
4140
+ setAttr(time, "datetime", event.ts);
4141
+ row.appendChild(time);
4142
+ row.appendChild(element(doc, "span", "hive-event-kind", event.kind || translate("event.unknown")));
4143
+ const detail = [];
4144
+ if (event.task) detail.push(event.task);
4145
+ if (event.actor) detail.push("@" + event.actor);
4146
+ row.appendChild(element(doc, "span", "hive-event-text", detail.join(" ") || "—"));
4147
+ eventsList.appendChild(row);
4148
+ }
4149
+ }
4150
+
4151
+ function render(model) {
4152
+ repoNode.textContent = model.repo || "—";
4153
+ setAttr(repoNode, "title", model.repo);
4154
+ timeNode.textContent = model.at ? formatStamp(model.at) : "—";
4155
+ setAttr(timeNode, "datetime", model.at);
4156
+
4157
+ renderInit(model);
4158
+ renderQueenHint(model);
4159
+ renderSupervisor();
4160
+ renderStats(model);
4161
+ renderActions(model);
4162
+ renderFreezeBanner(model);
4163
+ renderAgents(model);
4164
+ renderStageChips(model);
4165
+ renderLanes(model);
4166
+ renderEvents(model);
4167
+ }
4168
+
4169
+ // --- locale --------------------------------------------------------------
4170
+
4171
+ /** Re-render the current snapshot (and any open drawer or help) in the active language. */
4172
+ function rerender() {
4173
+ if (destroyed) return;
4174
+ const helpWasOpen = helpOpen;
4175
+ if (helpWasOpen) closeHelp(false);
4176
+ if (planDialogNode) closePlanDialog(false);
4177
+ if (limitsDialogNode) closeLimitsDialog(false);
4178
+ try {
4179
+ applyChrome();
4180
+ if (lastModel) render(lastModel);
4181
+ } catch (error) {
4182
+ reportError(error);
4183
+ }
4184
+ const state = drawerState;
4185
+ if (state) {
4186
+ closeDrawer();
4187
+ if (state.kind === "agent") openAgentDrawer(state.agent);
4188
+ else openDrawer(state.card, state.lane);
4189
+ }
4190
+ if (helpWasOpen) openHelp();
4191
+ }
4192
+
4193
+ // --- data flow -----------------------------------------------------------
4194
+
4195
+ function resetRepoState() {
4196
+ initRequestSeq += 1;
4197
+ initBusy = false;
4198
+ initOutput = null;
4199
+ initErrorMessage = "";
4200
+ queenNotice = false;
4201
+ queenBusy = false;
4202
+ stageFilter = "all";
4203
+ stageChipEntries = [];
4204
+ eventsExpanded = false;
4205
+ planTriggerButton = null;
4206
+ closeHelp(false);
4207
+ closePlanDialog(false);
4208
+ closeLimitsDialog(false);
4209
+ closeDrawer();
4210
+ closeToast();
4211
+ }
4212
+
4213
+ function setSnapshot(snapshot) {
4214
+ if (destroyed) return null;
4215
+ lastSnapshot = isRecord(snapshot) ? snapshot : {};
4216
+ const model = renderModel(lastSnapshot);
4217
+ if (lastModel && lastModel.repo !== model.repo) resetRepoState();
4218
+ lastModel = model;
4219
+ try {
4220
+ render(model);
4221
+ setStatus(null);
4222
+ } catch (error) {
4223
+ reportError(error);
4224
+ }
4225
+ if (planDialogNode && (!model.writable || !model.initialised)) closePlanDialog(false);
4226
+ if (helpOpen && helpSignature !== helpSignatureOf(model)) {
4227
+ closeHelp(false);
4228
+ openHelp();
4229
+ }
4230
+ return model;
4231
+ }
4232
+
4233
+ async function doRefresh() {
4234
+ if (!fetchImpl) {
4235
+ const missing = new Error("hive: fetch is not available");
4236
+ if (!destroyed) {
4237
+ setStatus("status.disconnected", "error");
4238
+ reportError(missing);
4239
+ }
4240
+ return;
4241
+ }
4242
+ try {
4243
+ const response = await fetchImpl(snapshotUrl, {
4244
+ cache: "no-store",
4245
+ headers: { accept: "application/json" },
4246
+ });
4247
+ if (!response || response.ok === false) {
4248
+ throw new Error("hive snapshot failed with status " + (response ? response.status : "none"));
4249
+ }
4250
+ const data = await response.json();
4251
+ if (!destroyed) setSnapshot(data);
4252
+ } catch (error) {
4253
+ if (!destroyed) {
4254
+ setStatus("status.disconnected", "error");
4255
+ reportError(error);
4256
+ }
4257
+ }
4258
+ }
4259
+
4260
+ function refresh() {
4261
+ if (destroyed) return Promise.resolve();
4262
+ void refreshSupervisor().catch(() => {
4263
+ // Status is optional; a rejected read must never surface as a panel error.
4264
+ });
4265
+ if (refreshPromise) return refreshPromise;
4266
+ refreshPromise = doRefresh().finally(() => {
4267
+ refreshPromise = null;
4268
+ });
4269
+ return refreshPromise;
4270
+ }
4271
+
4272
+ async function forceRefresh() {
4273
+ if (destroyed) return;
4274
+ if (refreshPromise) {
4275
+ try {
4276
+ await refreshPromise;
4277
+ } catch {
4278
+ // doRefresh already folds failures into the disconnected status.
4279
+ }
4280
+ }
4281
+ if (!destroyed) await refresh();
4282
+ }
4283
+
4284
+ function destroy() {
4285
+ if (destroyed) return;
4286
+ destroyed = true;
4287
+ if (unsubscribeLocale) {
4288
+ try {
4289
+ unsubscribeLocale();
4290
+ } catch {
4291
+ // Disposal must never throw.
4292
+ }
4293
+ unsubscribeLocale = null;
4294
+ }
4295
+ if (timer !== null) {
4296
+ unschedule(timer);
4297
+ timer = null;
4298
+ }
4299
+ closeHelp(false);
4300
+ closePlanDialog(false);
4301
+ closeLimitsDialog(false);
4302
+ closeToast();
4303
+ closeDrawer();
4304
+ if (frame.parentNode) frame.parentNode.removeChild(frame);
4305
+ lastSnapshot = null;
4306
+ lastModel = null;
4307
+ }
4308
+
4309
+ applyChrome();
4310
+
4311
+ if (typeof opts.subscribeLocale === "function") {
4312
+ try {
4313
+ const unsubscribe = opts.subscribeLocale(rerender);
4314
+ if (typeof unsubscribe === "function") unsubscribeLocale = unsubscribe;
4315
+ } catch (error) {
4316
+ reportError(error);
4317
+ }
4318
+ }
4319
+
4320
+ timer = schedule(() => {
4321
+ void refresh();
4322
+ }, intervalMs);
4323
+ void refresh();
4324
+
4325
+ return { setSnapshot, destroy, refresh, rerender };
4326
+ }