reevesagents 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +232 -318
- package/dist/chunk-CJKEBBUI.js +7663 -0
- package/dist/{chunk-UEYJAKAZ.js → chunk-DGLUP7Q7.js} +2 -2
- package/dist/{chunk-PWYG5IM5.js → chunk-HTCENB3Q.js} +2 -2
- package/dist/chunk-PKMTELW4.js +115 -0
- package/dist/chunk-PVYM35RS.js +1697 -0
- package/dist/{chunk-OQJNBACW.js → chunk-QWUBYDUV.js} +2 -2
- package/dist/chunk-XEOWHTRQ.js +1246 -0
- package/dist/{chunk-KROKGL2R.js → chunk-XHP63Y64.js} +879 -2
- package/dist/cli.js +1099 -13
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -2
- package/dist/{router-AYNTF24M.js → router-S7KR2CIE.js} +146 -79
- package/dist/{server-TIFQ5JSM.js → server-4OILK2LL.js} +344 -6
- package/dist/{server-BNBSZZIP.js → server-5U4NNV43.js} +305 -14
- package/dist/{tui-launch-7DBX4JYA.js → tui-launch-7WKLVYEH.js} +2 -2
- package/dist/web/app.css +444 -11
- package/dist/web/app.js +672 -21
- package/dist/web/favicon.png +0 -0
- package/dist/web/index.html +75 -0
- package/dist/web/insights-core.js +92 -0
- package/dist/web/plan-controller.js +91 -0
- package/dist/web/plan-error.js +81 -0
- package/dist/web/tick-line.js +78 -0
- package/package.json +10 -8
- package/dist/chunk-DLWYZPW6.js +0 -3222
- package/dist/chunk-YWS3MILO.js +0 -266
package/dist/web/app.js
CHANGED
|
@@ -202,6 +202,39 @@
|
|
|
202
202
|
'web.effortXhigh': 'Extra high',
|
|
203
203
|
'web.effortMax': 'Max',
|
|
204
204
|
'web.effortHelp': 'Higher effort spends more on reasoning. Provider default is safest.',
|
|
205
|
+
'web.logs': 'Logs',
|
|
206
|
+
'web.insightsTitle': 'Plan and logs',
|
|
207
|
+
'web.insightsSubtitle': 'What the flow is doing and what your agents reported.',
|
|
208
|
+
'web.tabPlan': 'Plan',
|
|
209
|
+
'web.tabLogs': 'Logs',
|
|
210
|
+
'web.logsAllRuns': 'All runs',
|
|
211
|
+
'web.planFilterAll': 'All',
|
|
212
|
+
'web.planFilterOpen': 'Open',
|
|
213
|
+
'web.planFilterWaiting': 'Waiting for you',
|
|
214
|
+
'web.planWaitingTitle': 'Waiting for you',
|
|
215
|
+
'web.planNeedsBrief': 'needs a brief',
|
|
216
|
+
'web.planBlockedOwner': 'blocked',
|
|
217
|
+
'web.planEmptyTitle': 'No plan yet',
|
|
218
|
+
'web.planEmptyBody': 'Import the project document with `reevesagents flow plan import`.',
|
|
219
|
+
'web.logsEmptyTitle': 'No notifications yet',
|
|
220
|
+
'web.logsEmptyBody': 'Runs, approvals and flow events appear here as they happen.',
|
|
221
|
+
'web.logsMarkRead': 'Mark all read',
|
|
222
|
+
'web.logsMarkedRead': 'marked as read',
|
|
223
|
+
'web.logsRun': 'Run',
|
|
224
|
+
'web.logsUnreadOnly': 'Unread only',
|
|
225
|
+
'web.planStatus': 'Status',
|
|
226
|
+
'web.planCommit': 'Commit',
|
|
227
|
+
'web.planRounds': 'Rounds',
|
|
228
|
+
'web.planNotes': 'Notes',
|
|
229
|
+
'web.planBrief': 'Brief',
|
|
230
|
+
'web.planStatus_pending': 'pending',
|
|
231
|
+
'web.planStatus_needs_brief': 'needs brief',
|
|
232
|
+
'web.planStatus_queued': 'queued',
|
|
233
|
+
'web.planStatus_in_work': 'in work',
|
|
234
|
+
'web.planStatus_reviewing': 'reviewing',
|
|
235
|
+
'web.planStatus_done': 'done',
|
|
236
|
+
'web.planStatus_blocked_owner': 'blocked',
|
|
237
|
+
'web.planStatus_skipped': 'skipped',
|
|
205
238
|
}
|
|
206
239
|
|
|
207
240
|
const el = {
|
|
@@ -269,6 +302,34 @@
|
|
|
269
302
|
doctorRefresh: document.getElementById('doctor-refresh'),
|
|
270
303
|
doctorClose: document.getElementById('doctor-close'),
|
|
271
304
|
aboutBtn: document.getElementById('about-btn'),
|
|
305
|
+
logsBtn: document.getElementById('logs-btn'),
|
|
306
|
+
insightsDialog: document.getElementById('insights-dialog'),
|
|
307
|
+
insightsClose: document.getElementById('insights-close'),
|
|
308
|
+
planDialog: document.getElementById('plan-dialog'),
|
|
309
|
+
planDialogTitle: document.getElementById('plan-dialog-title'),
|
|
310
|
+
planClose: document.getElementById('plan-close'),
|
|
311
|
+
planPlayPause: document.getElementById('plan-play-pause'),
|
|
312
|
+
planError: document.getElementById('plan-error'),
|
|
313
|
+
planPanel: document.getElementById('plan-panel'),
|
|
314
|
+
logsPanel: document.getElementById('logs-panel'),
|
|
315
|
+
planList: document.getElementById('plan-list'),
|
|
316
|
+
planEmpty: document.getElementById('plan-empty'),
|
|
317
|
+
planDetail: document.getElementById('plan-detail'),
|
|
318
|
+
planWaiting: document.getElementById('plan-waiting'),
|
|
319
|
+
planTicks: document.getElementById('plan-ticks'),
|
|
320
|
+
planProgressFill: document.getElementById('plan-progress-fill'),
|
|
321
|
+
planProgressText: document.getElementById('plan-progress-text'),
|
|
322
|
+
planProgressBar: document.querySelector('#plan-panel .plan-progress-bar'),
|
|
323
|
+
planFilterAll: document.getElementById('plan-filter-all'),
|
|
324
|
+
planFilterOpen: document.getElementById('plan-filter-open'),
|
|
325
|
+
planFilterWaiting: document.getElementById('plan-filter-waiting'),
|
|
326
|
+
logsList: document.getElementById('logs-list'),
|
|
327
|
+
logsEmpty: document.getElementById('logs-empty'),
|
|
328
|
+
logsError: document.getElementById('logs-error'),
|
|
329
|
+
logsFilterRun: document.getElementById('logs-filter-run'),
|
|
330
|
+
logsUnread: document.getElementById('logs-unread'),
|
|
331
|
+
logsMarkRead: document.getElementById('logs-mark-read'),
|
|
332
|
+
logsAnnouncer: document.getElementById('logs-announcer'),
|
|
272
333
|
aboutDialog: document.getElementById('about-dialog'),
|
|
273
334
|
aboutList: document.getElementById('about-list'),
|
|
274
335
|
aboutClose: document.getElementById('about-close'),
|
|
@@ -296,6 +357,23 @@
|
|
|
296
357
|
}
|
|
297
358
|
|
|
298
359
|
let runs = []
|
|
360
|
+
// Insights dialog state: which tab, which filter, and the payloads it renders. Kept in one object so a refresh
|
|
361
|
+
// from the SSE stream and a click on a tab cannot disagree about what is on screen.
|
|
362
|
+
const insights = {
|
|
363
|
+
tab: 'plan',
|
|
364
|
+
planFilter: 'all',
|
|
365
|
+
runId: '',
|
|
366
|
+
plan: null,
|
|
367
|
+
logs: [],
|
|
368
|
+
readSeq: 0,
|
|
369
|
+
latestSeq: 0,
|
|
370
|
+
notifications: null,
|
|
371
|
+
// The driver's receipt from the last snapshot (`/api/state.tick`): who advances flows and when it last did.
|
|
372
|
+
tick: null,
|
|
373
|
+
}
|
|
374
|
+
// When the client first saw each notification summary, so a reload mid-pulse keeps the remainder.
|
|
375
|
+
const pulseSeenAt = new Map()
|
|
376
|
+
let pulseTimer = null
|
|
299
377
|
let history = []
|
|
300
378
|
let approvals = []
|
|
301
379
|
let providers = []
|
|
@@ -336,45 +414,104 @@
|
|
|
336
414
|
// --- initial load + live stream ------------------------------------------
|
|
337
415
|
|
|
338
416
|
async function loadState() {
|
|
339
|
-
|
|
340
|
-
|
|
417
|
+
// The same reader as every later refresh: it is the call that measures the server clock, and a first load without that
|
|
418
|
+
// measurement renders the driver line from a clock the browser has not corrected yet (block 71).
|
|
419
|
+
await refreshState()
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// The server clock, measured once per snapshot: the stream cannot carry it (a clock in the frame is exactly the value
|
|
423
|
+
// that made every frame different), so the offset is refreshed whenever a snapshot is read — including on every
|
|
424
|
+
// (re)connection, which is when a browser tab that slept needs it most.
|
|
425
|
+
let clockOffset = 0
|
|
426
|
+
|
|
427
|
+
// Any payload that carries the server clock — the snapshot, or a frame that was actually sent — corrects this browser's
|
|
428
|
+
// clock for the line it computes locally.
|
|
429
|
+
function noteServerClock(data) {
|
|
430
|
+
const offset = ticks.clockOffset(data, Date.now())
|
|
431
|
+
if (offset !== null) clockOffset = offset
|
|
341
432
|
}
|
|
342
433
|
|
|
343
434
|
async function refreshState() {
|
|
344
435
|
const data = await api('GET', '/api/state')
|
|
436
|
+
noteServerClock(data)
|
|
345
437
|
applyState(data)
|
|
346
438
|
}
|
|
347
439
|
|
|
440
|
+
// One consumer for "a state payload arrived", whether it is the first `/api/state` load or an SSE frame. A field
|
|
441
|
+
// that a frame does not carry (providers, language, theme, version — the stream sends neither) is left untouched
|
|
442
|
+
// instead of being reset to an empty value, which is what a shared consumer must respect.
|
|
348
443
|
function applyState(data) {
|
|
349
|
-
providers = data.providers
|
|
350
|
-
runs = data.runs
|
|
351
|
-
history = data.history
|
|
352
|
-
approvals = data.approvals
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
444
|
+
if (Array.isArray(data.providers)) providers = data.providers
|
|
445
|
+
if (Array.isArray(data.runs)) runs = data.runs
|
|
446
|
+
if (Array.isArray(data.history)) history = data.history
|
|
447
|
+
if (Array.isArray(data.approvals)) approvals = data.approvals
|
|
448
|
+
// A snapshot can change the flow's state under an open dialog (another tab pressed Pause, a ticker escalated it). Without this the
|
|
449
|
+
// button kept its old label and a second click answered `already_paused` — a stale button is a bug the operator has to interpret
|
|
450
|
+
// (block 51).
|
|
451
|
+
if (data.tick !== undefined) {
|
|
452
|
+
insights.tick = data.tick
|
|
453
|
+
renderPlanTicks()
|
|
454
|
+
}
|
|
455
|
+
syncPlanPlayPause()
|
|
456
|
+
if (typeof data.version === 'string' && data.version) appVersion = data.version
|
|
457
|
+
if (data.language) applyLanguage(data.language)
|
|
458
|
+
if (data.web_theme) applyTheme(data.web_theme)
|
|
459
|
+
if (Array.isArray(data.providers)) renderProviders()
|
|
460
|
+
if (data.notifications) {
|
|
461
|
+
const previous = insights.notifications
|
|
462
|
+
insights.notifications = data.notifications
|
|
463
|
+
// Remember when each timestamp was first seen (diagnostics only): the remaining time is measured from the
|
|
464
|
+
// event's server stamp to now, so a reload continues the ring instead of restarting it.
|
|
465
|
+
for (const entry of data.notifications.unread_by || []) {
|
|
466
|
+
if (entry.latest_ts && !pulseSeenAt.has(entry.latest_ts)) pulseSeenAt.set(entry.latest_ts, Date.now())
|
|
467
|
+
}
|
|
468
|
+
// The dialog refreshes itself from the same stream. Marking read on another tab does not change
|
|
469
|
+
// `latest_seq` — only `read_seq` and `unread` — so the condition watches those as well, or this tab keeps
|
|
470
|
+
// showing rows highlighted as unread after somebody has read them.
|
|
471
|
+
const changed = previous && (
|
|
472
|
+
previous.latest_seq !== data.notifications.latest_seq
|
|
473
|
+
|| previous.read_seq !== data.notifications.read_seq
|
|
474
|
+
|| previous.unread !== data.notifications.unread
|
|
475
|
+
)
|
|
476
|
+
if (el.insightsDialog.open && changed) void loadLogs()
|
|
477
|
+
schedulePulseTick()
|
|
478
|
+
}
|
|
357
479
|
renderSidebar()
|
|
358
480
|
reconcileCreateDialog()
|
|
359
481
|
reconcileSelectedAgent()
|
|
360
482
|
if (!welcomeChecked) { welcomeChecked = true; maybeShowWelcome() }
|
|
361
483
|
}
|
|
362
484
|
|
|
485
|
+
// The state the last rendered frame described, minus the driver line. A frame whose state is identical changed nothing
|
|
486
|
+
// but time — and time is not an event: it must not rebuild the cards (block 71).
|
|
487
|
+
let lastFrameKey = ''
|
|
488
|
+
|
|
363
489
|
function subscribe() {
|
|
364
490
|
const events = new EventSource('/api/events')
|
|
365
|
-
events.onopen = () =>
|
|
491
|
+
events.onopen = () => {
|
|
492
|
+
setConn('live')
|
|
493
|
+
// A (re)connection re-reads the snapshot: it carries the server clock, and the driver line must be rebuilt from the
|
|
494
|
+
// marks rather than from whatever the previous connection was showing.
|
|
495
|
+
void refreshState().catch(() => {})
|
|
496
|
+
}
|
|
366
497
|
events.onerror = () => setConn('down')
|
|
367
498
|
events.onmessage = (e) => {
|
|
368
499
|
try {
|
|
369
500
|
const data = JSON.parse(e.data)
|
|
370
|
-
|
|
371
|
-
|
|
501
|
+
// The clock first: the line about to be drawn is computed from this browser's clock, corrected by the server's.
|
|
502
|
+
noteServerClock(data)
|
|
503
|
+
const key = ticks.frameKey(data)
|
|
504
|
+
// The driver line next: a new receipt, a new deadline or a changed `active` is news even when nothing else moved.
|
|
505
|
+
if (data.tick !== undefined) {
|
|
506
|
+
insights.tick = data.tick
|
|
507
|
+
renderPlanTicks()
|
|
372
508
|
}
|
|
373
|
-
if (
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
509
|
+
if (key === lastFrameKey) return
|
|
510
|
+
lastFrameKey = key
|
|
511
|
+
// Everything a frame carries goes through the same consumer as the first load. The previous version only
|
|
512
|
+
// copied runs/history/approvals and dropped `notifications`, so a read (or a new event) on the stream never
|
|
513
|
+
// reached the badge, the pulse or the open Logs list.
|
|
514
|
+
applyState(data)
|
|
378
515
|
} catch { /* ignore malformed frame */ }
|
|
379
516
|
}
|
|
380
517
|
}
|
|
@@ -512,6 +649,21 @@
|
|
|
512
649
|
document.querySelector('#doctor-dialog .dialog-subtitle').textContent = t('web.doctorSubtitle')
|
|
513
650
|
el.doctorRefresh.textContent = t('web.refresh')
|
|
514
651
|
el.doctorClose.textContent = t('web.mcpClose')
|
|
652
|
+
el.logsBtn.textContent = t('web.logs')
|
|
653
|
+
document.querySelector('#insights-dialog .dialog-title').textContent = t('web.logsTitle')
|
|
654
|
+
document.querySelector('#insights-dialog .dialog-subtitle').textContent = t('web.logsSubtitle')
|
|
655
|
+
el.planClose.textContent = t('web.mcpClose')
|
|
656
|
+
el.planFilterAll.textContent = t('web.planFilterAll')
|
|
657
|
+
el.planFilterOpen.textContent = t('web.planFilterOpen')
|
|
658
|
+
el.planFilterWaiting.textContent = t('web.planFilterWaiting')
|
|
659
|
+
el.logsMarkRead.textContent = t('web.logsMarkRead')
|
|
660
|
+
el.insightsClose.textContent = t('web.mcpClose')
|
|
661
|
+
document.querySelector('#logs-panel .logs-filter span').textContent = t('web.logsRun')
|
|
662
|
+
document.querySelector('#logs-panel .logs-toggle span').textContent = t('web.logsUnreadOnly')
|
|
663
|
+
document.querySelector('#plan-empty .empty-title').textContent = t('web.planEmptyTitle')
|
|
664
|
+
document.querySelector('#plan-empty .empty-body').textContent = t('web.planEmptyBody')
|
|
665
|
+
document.querySelector('#logs-empty .empty-title').textContent = t('web.logsEmptyTitle')
|
|
666
|
+
document.querySelector('#logs-empty .empty-body').textContent = t('web.logsEmptyBody')
|
|
515
667
|
document.querySelector('#about-dialog .dialog-title').textContent = `${t('web.about')} ReevesAgents`
|
|
516
668
|
document.querySelector('#about-dialog .dialog-subtitle').textContent = t('web.aboutSubtitle')
|
|
517
669
|
el.aboutClose.textContent = t('web.mcpClose')
|
|
@@ -949,16 +1101,61 @@
|
|
|
949
1101
|
const meta = document.createElement('span')
|
|
950
1102
|
meta.className = 'run-meta'
|
|
951
1103
|
meta.textContent = `${statusLabel(run.status)} · ${agentCountLabel(run.terminals.length)}`
|
|
1104
|
+
// The counters are the first thing a narrow card drops; the tooltip is what keeps them reachable there.
|
|
1105
|
+
meta.title = meta.textContent
|
|
952
1106
|
headBody.appendChild(meta)
|
|
1107
|
+
// The flow chip is rendered by the server (core/flow-label.ts), so the client holds no copy of
|
|
1108
|
+
// its wording; attention is an attribute on the same chip, painted by app.css.
|
|
1109
|
+
if (run.flow) {
|
|
1110
|
+
// The badge is a label, not a control: it says what the flow is doing and nothing else. The plan has its own icon
|
|
1111
|
+
// beside it, so clicking the status cannot silently navigate somewhere.
|
|
1112
|
+
const flow = document.createElement('span')
|
|
1113
|
+
const tone = run.flow.tone || 'neutral'
|
|
1114
|
+
flow.className = `run-flow flow-badge flow-badge--${tone}${run.flow.pulse ? ' is-pulsing' : ''}`
|
|
1115
|
+
flow.textContent = run.flow.label
|
|
1116
|
+
if (run.flow.attention) {
|
|
1117
|
+
flow.dataset.attention = run.flow.attention
|
|
1118
|
+
}
|
|
1119
|
+
flow.title = run.flow.detail || run.flow.attention_label || run.flow.label
|
|
1120
|
+
headBody.appendChild(flow)
|
|
1121
|
+
|
|
1122
|
+
// The plan icon: drawn only when the run has a plan (T1.6.6 — no disabled placeholders), and the only control that
|
|
1123
|
+
// opens the plan dialog. The controller builds it, so the rules live where a test can drive them.
|
|
1124
|
+
const planBtn = planController.createIcon({ ...run.flow, run_id: run.id }, { ariaLabel: t('web.planOpenLabel') })
|
|
1125
|
+
if (planBtn) {
|
|
1126
|
+
// Whether the plan is running or paused, between the chip and the icon that opens it. A glyph, not a button:
|
|
1127
|
+
// pausing belongs to the dialog (one obvious control, with a label), and the card only has to say which state it
|
|
1128
|
+
// is in. It is appended *before* the icon so the row reads chip · state · icon — in the old two-column grid this
|
|
1129
|
+
// span had no cell of its own and fell to a third row (block 70).
|
|
1130
|
+
const planState = document.createElement('span')
|
|
1131
|
+
const paused = run.flow.status === 'paused'
|
|
1132
|
+
planState.className = `flow-plan-state${paused ? ' is-paused' : ''}`
|
|
1133
|
+
planState.dataset.paused = String(paused)
|
|
1134
|
+
planState.setAttribute('aria-label', paused ? t('web.planPaused') : t('web.planRunning'))
|
|
1135
|
+
planState.title = planState.getAttribute('aria-label')
|
|
1136
|
+
planState.innerHTML = paused
|
|
1137
|
+
? '<svg viewBox="0 0 16 16" width="11" height="11" aria-hidden="true" focusable="false">'
|
|
1138
|
+
+ '<path d="M5.5 3.5v9M10.5 3.5v9" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" fill="none"/></svg>'
|
|
1139
|
+
: '<svg viewBox="0 0 16 16" width="11" height="11" aria-hidden="true" focusable="false">'
|
|
1140
|
+
+ '<path d="M5.5 3.2l7 4.8-7 4.8z" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round" fill="none"/></svg>'
|
|
1141
|
+
headBody.appendChild(planState)
|
|
1142
|
+
|
|
1143
|
+
planBtn.addEventListener('click', () => { void openPlanDialog(run.id) })
|
|
1144
|
+
headBody.appendChild(planBtn)
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
953
1147
|
head.appendChild(headBody)
|
|
954
1148
|
|
|
955
1149
|
const actions = document.createElement('div')
|
|
956
1150
|
actions.className = 'run-actions'
|
|
1151
|
+
// Actions are icons in the corner, like window controls: the label moves into `aria-label`/`title` instead of
|
|
1152
|
+
// disappearing, so the meaning survives for a screen reader and for a hover.
|
|
957
1153
|
if (run.status === 'running') {
|
|
958
1154
|
const add = document.createElement('button')
|
|
959
1155
|
add.className = 'run-action'
|
|
960
1156
|
add.type = 'button'
|
|
961
|
-
add.
|
|
1157
|
+
add.innerHTML = runActionIcon('add')
|
|
1158
|
+
add.setAttribute('aria-label', t('web.addAgent'))
|
|
962
1159
|
add.title = t('web.addAgentTitle', { name: run.name })
|
|
963
1160
|
add.addEventListener('click', () => openAgentDialog(run.id))
|
|
964
1161
|
actions.appendChild(add)
|
|
@@ -967,7 +1164,8 @@
|
|
|
967
1164
|
const stop = document.createElement('button')
|
|
968
1165
|
stop.className = 'run-stop'
|
|
969
1166
|
stop.type = 'button'
|
|
970
|
-
stop.
|
|
1167
|
+
stop.innerHTML = runActionIcon('stop')
|
|
1168
|
+
stop.setAttribute('aria-label', t('web.stop'))
|
|
971
1169
|
stop.title = t('web.stopRunTitle', { name: run.name })
|
|
972
1170
|
stop.addEventListener('click', () => stopRun(run))
|
|
973
1171
|
actions.appendChild(stop)
|
|
@@ -976,7 +1174,8 @@
|
|
|
976
1174
|
const del = document.createElement('button')
|
|
977
1175
|
del.className = 'run-delete'
|
|
978
1176
|
del.type = 'button'
|
|
979
|
-
del.
|
|
1177
|
+
del.innerHTML = runActionIcon('delete')
|
|
1178
|
+
del.setAttribute('aria-label', t('common.delete'))
|
|
980
1179
|
del.title = t('web.deleteRunTitle', { name: run.name })
|
|
981
1180
|
del.addEventListener('click', () => deleteRun(run))
|
|
982
1181
|
actions.appendChild(del)
|
|
@@ -1100,9 +1299,438 @@
|
|
|
1100
1299
|
return item
|
|
1101
1300
|
}
|
|
1102
1301
|
|
|
1302
|
+
|
|
1303
|
+
// ---- Insights dialog: the Plan and Logs tabs -------------------------------------------------
|
|
1304
|
+
const core = () => window.insightsCore || {
|
|
1305
|
+
formatPlanProgress: (d, t) => ({ text: `${d}/${t}`, percent: 0 }),
|
|
1306
|
+
pulseRemaining: () => 0,
|
|
1307
|
+
filterPlanItems: items => items || [],
|
|
1308
|
+
planWaiting: () => ({ needsBrief: [], blocked: [], total: 0 }),
|
|
1309
|
+
planIconVisible: flow => Boolean(flow && flow.plan),
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// The dialog is run-scoped: the agent the operator has selected decides which run's plan opens.
|
|
1313
|
+
function selectedRun() {
|
|
1314
|
+
if (selectedId) {
|
|
1315
|
+
for (const run of runs) {
|
|
1316
|
+
const agents = run.agents || []
|
|
1317
|
+
const owner = agents.find(entry => entry.id === selectedId)
|
|
1318
|
+
if (owner) return run
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
return runs[0] || null
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
async function openInsightsDialog() {
|
|
1325
|
+
const run = selectedRun()
|
|
1326
|
+
insights.runId = run ? run.id : ''
|
|
1327
|
+
el.insightsDialog.showModal()
|
|
1328
|
+
await loadLogs()
|
|
1329
|
+
renderLogFilters()
|
|
1330
|
+
el.insightsClose.focus()
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// The plan dialog is opened by its own icon on the run card. The element is not remembered: `renderSidebar()` rebuilds
|
|
1334
|
+
// every card on each SSE frame, so a held reference would be detached from the document by the time Esc is pressed and
|
|
1335
|
+
// the focus would land on `body`. The run id survives a re-render; the button is looked up by it.
|
|
1336
|
+
// The run id, the aria attribute and the focus target live in `plan-controller.js`: the card is rebuilt on every SSE frame,
|
|
1337
|
+
// so a remembered element would be detached by the time the dialog closes.
|
|
1338
|
+
const planController = window.planDialogController.createPlanDialogController(document)
|
|
1339
|
+
|
|
1340
|
+
async function openPlanDialog(runId) {
|
|
1341
|
+
if (!runId) return
|
|
1342
|
+
// The id is the memory; the element is never kept. A line raised for another run is not this run's news.
|
|
1343
|
+
clearPlanError()
|
|
1344
|
+
planController.open(runId)
|
|
1345
|
+
insights.runId = runId
|
|
1346
|
+
const run = runs.find(entry => entry.id === runId)
|
|
1347
|
+
el.planDialogTitle.textContent = t('web.planTitle', { run: run ? run.name : runId })
|
|
1348
|
+
insights.flowState = run && run.flow ? run.flow.status : null
|
|
1349
|
+
renderPlanPlayPause(insights.flowState === 'paused')
|
|
1350
|
+
renderPlanTicks()
|
|
1351
|
+
el.planDialog.showModal()
|
|
1352
|
+
await loadPlan(runId)
|
|
1353
|
+
renderPlan()
|
|
1354
|
+
el.planClose.focus()
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
function closePlanDialog() {
|
|
1358
|
+
if (!el.planDialog.open) return
|
|
1359
|
+
el.planDialog.close()
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
// The dialog's play/pause: the same operation as `flow pause` / `flow resume`, through one route. The button's label and
|
|
1363
|
+
// `aria-pressed` follow the flow's state, so "Pause" never lies about a flow that is already parked.
|
|
1364
|
+
// Ask the freshest snapshot which state the plan is in, and draw the button from it.
|
|
1365
|
+
function syncPlanPlayPause() {
|
|
1366
|
+
// A line raised for a run that is no longer the open one is not news: drop it as soon as the snapshot shows the move.
|
|
1367
|
+
planErrorLine.bind(insights.runId)
|
|
1368
|
+
if (!insights.runId) return
|
|
1369
|
+
const run = runs.find(entry => entry.id === insights.runId)
|
|
1370
|
+
if (!run || !run.flow) return
|
|
1371
|
+
insights.flowState = run.flow.status
|
|
1372
|
+
if (el.planDialog.open) renderPlanPlayPause(insights.flowState === 'paused')
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
function renderPlanPlayPause(paused) {
|
|
1376
|
+
el.planPlayPause.textContent = paused ? t('web.planResume') : t('web.planPause')
|
|
1377
|
+
el.planPlayPause.setAttribute('aria-pressed', String(paused))
|
|
1378
|
+
el.planPlayPause.setAttribute('aria-label', paused ? t('web.planResumeLabel') : t('web.planPauseLabel'))
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// Who advances the flows, in one line. The panel never drives them — the external ticker does — so this only reports
|
|
1382
|
+
// the driver's own receipt, and says so plainly when no pass has been recorded (block 68). A timer that systemd
|
|
1383
|
+
// reports as not active takes the attention tone: a driver that stopped is the reason a flow sits still.
|
|
1384
|
+
// The driver line, from the marks the frame carries (`at`, `next_at`) and this browser's clock — never from a countdown
|
|
1385
|
+
// the server computed, because a countdown makes every frame look new (block 71). `clockOffset` corrects a browser clock
|
|
1386
|
+
// that disagrees with the server's; it comes from `/api/state`, the one payload that may carry "now".
|
|
1387
|
+
//
|
|
1388
|
+
// `tick-line.js` is part of the client build and is served from the same allowlist as this file; the fallback exists so
|
|
1389
|
+
// a page that somehow loads without it still draws a (static) line instead of failing inside an SSE handler.
|
|
1390
|
+
const ticks = window.tickLine || {
|
|
1391
|
+
lineText: (tick, _now, translate) => (tick ? translate('web.ticksNow', { driver: tick.driver, age: 0 }) : translate('web.ticksNone')),
|
|
1392
|
+
tone: (tick) => (!tick || tick.active === false ? 'attention' : 'neutral'),
|
|
1393
|
+
frameKey: (data) => JSON.stringify([data.runs, data.history, data.approvals, data.notifications]),
|
|
1394
|
+
clockOffset: () => null,
|
|
1395
|
+
}
|
|
1396
|
+
function renderPlanTicks() {
|
|
1397
|
+
if (!el.planTicks) return
|
|
1398
|
+
el.planTicks.hidden = false
|
|
1399
|
+
el.planTicks.dataset.tone = ticks.tone(insights.tick)
|
|
1400
|
+
el.planTicks.textContent = ticks.lineText(insights.tick, Date.now() + clockOffset, t)
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// Once a second, and only the line: the sidebar is rebuilt when state changes, not when time passes.
|
|
1404
|
+
function updatePlanTicksClock() {
|
|
1405
|
+
if (!el.planTicks || !insights.tick) return
|
|
1406
|
+
if (el.planDialog && !el.planDialog.open) return
|
|
1407
|
+
renderPlanTicks()
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
// A refusal is a code (`not_pausable`, `already_paused`, …), and a code is not a sentence: `plan-error.js` owns the translation, the
|
|
1411
|
+
// six-second life and the run it belongs to, so the behaviour can be driven in a real DOM with fake timers (block 59).
|
|
1412
|
+
const planErrorLine = window.planErrorLine.createPlanErrorLine(document, { t: t })
|
|
1413
|
+
|
|
1414
|
+
function clearPlanError() {
|
|
1415
|
+
planErrorLine.clear()
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function showPlanError(code, runId) {
|
|
1419
|
+
planErrorLine.show(code, runId)
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
async function togglePlanPlayPause() {
|
|
1423
|
+
const runId = insights.runId
|
|
1424
|
+
if (!runId) return
|
|
1425
|
+
const paused = insights.flowState === 'paused'
|
|
1426
|
+
el.planPlayPause.disabled = true
|
|
1427
|
+
try {
|
|
1428
|
+
const payload = await api('POST', `/api/flow/${paused ? 'resume' : 'pause'}`, { run_id: runId })
|
|
1429
|
+
clearPlanError()
|
|
1430
|
+
insights.flowState = payload && payload.flow ? payload.flow.state : insights.flowState
|
|
1431
|
+
renderPlanPlayPause(insights.flowState === 'paused')
|
|
1432
|
+
// The card's chip and glyph come from the next snapshot; ask for one now so the click is not invisible until the poll.
|
|
1433
|
+
await refreshState()
|
|
1434
|
+
} catch (err) {
|
|
1435
|
+
// The answer belongs to the run the click was made for. If the operator has moved on to another plan in the meantime, saying
|
|
1436
|
+
// anything here would be a story about the wrong plan.
|
|
1437
|
+
if (insights.runId !== runId) return
|
|
1438
|
+
const message = err instanceof Error ? err.message : String(err)
|
|
1439
|
+
showPlanError(String(message || 'unknown'), runId)
|
|
1440
|
+
} finally {
|
|
1441
|
+
el.planPlayPause.disabled = false
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
async function loadPlan(runId) {
|
|
1446
|
+
insights.plan = null
|
|
1447
|
+
if (!runId) return
|
|
1448
|
+
try {
|
|
1449
|
+
const data = await api('GET', `/api/plan?run=${encodeURIComponent(runId)}`)
|
|
1450
|
+
insights.plan = data && data.plan ? data.plan : null
|
|
1451
|
+
} catch {
|
|
1452
|
+
insights.plan = null
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
async function loadLogs() {
|
|
1457
|
+
const run = el.logsFilterRun.value
|
|
1458
|
+
const unread = el.logsUnread.checked
|
|
1459
|
+
// Built by hand: `URLSearchParams` is a browser global the lint config does not know, and the query is two
|
|
1460
|
+
// parameters wide.
|
|
1461
|
+
const parts = ['limit=200']
|
|
1462
|
+
if (run) parts.push(`run=${encodeURIComponent(run)}`)
|
|
1463
|
+
if (unread) parts.push('unread=1')
|
|
1464
|
+
const query = parts.join('&')
|
|
1465
|
+
try {
|
|
1466
|
+
const data = await api('GET', `/api/notifications?${query}`)
|
|
1467
|
+
insights.logs = data.events || []
|
|
1468
|
+
insights.readSeq = data.read_seq || 0
|
|
1469
|
+
insights.latestSeq = data.latest_seq || 0
|
|
1470
|
+
el.logsError.hidden = true
|
|
1471
|
+
} catch (err) {
|
|
1472
|
+
insights.logs = []
|
|
1473
|
+
el.logsError.textContent = err instanceof Error ? err.message : String(err)
|
|
1474
|
+
el.logsError.hidden = false
|
|
1475
|
+
}
|
|
1476
|
+
renderLogs()
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
function renderLogFilters() {
|
|
1480
|
+
const current = el.logsFilterRun.value
|
|
1481
|
+
el.logsFilterRun.replaceChildren()
|
|
1482
|
+
const all = document.createElement('option')
|
|
1483
|
+
all.value = ''
|
|
1484
|
+
all.textContent = t('web.logsAllRuns')
|
|
1485
|
+
el.logsFilterRun.appendChild(all)
|
|
1486
|
+
for (const run of runs) {
|
|
1487
|
+
const option = document.createElement('option')
|
|
1488
|
+
option.value = run.id
|
|
1489
|
+
option.textContent = run.name || run.id
|
|
1490
|
+
el.logsFilterRun.appendChild(option)
|
|
1491
|
+
}
|
|
1492
|
+
el.logsFilterRun.value = runs.some(run => run.id === current) ? current : ''
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
function planStatusBadge(status) {
|
|
1496
|
+
const badge = document.createElement('span')
|
|
1497
|
+
badge.className = 'plan-badge'
|
|
1498
|
+
badge.dataset.status = status
|
|
1499
|
+
badge.textContent = t(`web.planStatus_${status}`)
|
|
1500
|
+
return badge
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
function setPlanFilter(filter) {
|
|
1504
|
+
insights.planFilter = filter === 'open' || filter === 'waiting' ? filter : 'all'
|
|
1505
|
+
for (const [value, button] of [['all', el.planFilterAll], ['open', el.planFilterOpen], ['waiting', el.planFilterWaiting]]) {
|
|
1506
|
+
button.classList.toggle('is-active', value === insights.planFilter)
|
|
1507
|
+
}
|
|
1508
|
+
renderPlan()
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
function renderPlan() {
|
|
1512
|
+
const plan = insights.plan
|
|
1513
|
+
el.planEmpty.hidden = Boolean(plan)
|
|
1514
|
+
el.planList.replaceChildren()
|
|
1515
|
+
el.planWaiting.replaceChildren()
|
|
1516
|
+
el.planDetail.hidden = true
|
|
1517
|
+
if (!plan) {
|
|
1518
|
+
el.planProgressText.textContent = '0/0'
|
|
1519
|
+
el.planProgressFill.style.width = '0%'
|
|
1520
|
+
el.planWaiting.hidden = true
|
|
1521
|
+
return
|
|
1522
|
+
}
|
|
1523
|
+
const progress = core().formatPlanProgress(plan.progress.done, plan.progress.total)
|
|
1524
|
+
el.planProgressText.textContent = `${progress.text} · ${progress.percent}%`
|
|
1525
|
+
el.planProgressFill.style.width = `${progress.percent}%`
|
|
1526
|
+
el.planProgressBar.setAttribute('aria-valuenow', String(progress.percent))
|
|
1527
|
+
|
|
1528
|
+
const waiting = core().planWaiting(plan.items)
|
|
1529
|
+
if (waiting.total > 0) {
|
|
1530
|
+
el.planWaiting.hidden = false
|
|
1531
|
+
const title = document.createElement('div')
|
|
1532
|
+
title.className = 'plan-waiting-title'
|
|
1533
|
+
title.textContent = t('web.planWaitingTitle')
|
|
1534
|
+
el.planWaiting.appendChild(title)
|
|
1535
|
+
for (const item of [...waiting.needsBrief.map(entry => [entry, 'needs_brief']), ...waiting.blocked.map(entry => [entry, 'blocked_owner'])]) {
|
|
1536
|
+
const row = document.createElement('div')
|
|
1537
|
+
row.className = 'plan-waiting-row'
|
|
1538
|
+
const id = document.createElement('span')
|
|
1539
|
+
id.className = 'plan-waiting-id'
|
|
1540
|
+
id.textContent = item[0].id
|
|
1541
|
+
const why = document.createElement('span')
|
|
1542
|
+
why.className = 'plan-waiting-why'
|
|
1543
|
+
why.textContent = t(item[1] === 'needs_brief' ? 'web.planNeedsBrief' : 'web.planBlockedOwner')
|
|
1544
|
+
row.append(id, why)
|
|
1545
|
+
el.planWaiting.appendChild(row)
|
|
1546
|
+
}
|
|
1547
|
+
} else {
|
|
1548
|
+
el.planWaiting.hidden = true
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
const items = core().filterPlanItems(plan.items, insights.planFilter)
|
|
1552
|
+
for (const item of items) {
|
|
1553
|
+
const row = document.createElement('button')
|
|
1554
|
+
row.type = 'button'
|
|
1555
|
+
row.className = 'plan-row'
|
|
1556
|
+
row.dataset.status = item.status
|
|
1557
|
+
row.setAttribute('role', 'listitem')
|
|
1558
|
+
const id = document.createElement('span')
|
|
1559
|
+
id.className = 'plan-id'
|
|
1560
|
+
id.textContent = item.id
|
|
1561
|
+
const title = document.createElement('span')
|
|
1562
|
+
title.className = 'plan-title'
|
|
1563
|
+
title.textContent = item.title
|
|
1564
|
+
// A row the document no longer lists keeps its status, but the badge says so explicitly: without it the row
|
|
1565
|
+
// looks like ordinary open work that nobody is picking up.
|
|
1566
|
+
row.append(id, title, planStatusBadge(item.missing_since ? 'missing' : item.status))
|
|
1567
|
+
row.addEventListener('click', () => showPlanDetail(item))
|
|
1568
|
+
el.planList.appendChild(row)
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
function showPlanDetail(item) {
|
|
1573
|
+
el.planDetail.replaceChildren()
|
|
1574
|
+
const rows = [
|
|
1575
|
+
[`${t('web.planStatus')}`, item.missing_since ? t('web.planStatus_missing') : t(`web.planStatus_${item.status}`)],
|
|
1576
|
+
...(item.missing_since ? [[t('web.planMissingSince'), item.missing_since]] : []),
|
|
1577
|
+
[t('web.planCommit'), item.head || '—'],
|
|
1578
|
+
[t('web.planRounds'), String(item.rounds ?? 0)],
|
|
1579
|
+
[t('web.planNotes'), item.notes_ref || '—'],
|
|
1580
|
+
[t('web.planBrief'), item.spec_path || '—'],
|
|
1581
|
+
]
|
|
1582
|
+
for (const [label, value] of rows) {
|
|
1583
|
+
const row = document.createElement('div')
|
|
1584
|
+
row.className = 'plan-detail-row'
|
|
1585
|
+
const key = document.createElement('span')
|
|
1586
|
+
key.className = 'plan-detail-label'
|
|
1587
|
+
key.textContent = label
|
|
1588
|
+
const val = document.createElement('span')
|
|
1589
|
+
val.className = 'plan-detail-value'
|
|
1590
|
+
val.textContent = value
|
|
1591
|
+
row.append(key, val)
|
|
1592
|
+
el.planDetail.appendChild(row)
|
|
1593
|
+
}
|
|
1594
|
+
el.planDetail.hidden = false
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
function renderLogs() {
|
|
1598
|
+
el.logsList.replaceChildren()
|
|
1599
|
+
el.logsEmpty.hidden = insights.logs.length > 0
|
|
1600
|
+
for (const event of insights.logs) {
|
|
1601
|
+
const row = document.createElement('div')
|
|
1602
|
+
row.className = 'logs-row'
|
|
1603
|
+
row.setAttribute('role', 'listitem')
|
|
1604
|
+
row.tabIndex = -1
|
|
1605
|
+
row.dataset.kind = event.kind
|
|
1606
|
+
row.dataset.severity = event.severity
|
|
1607
|
+
if (event.seq > insights.readSeq) row.dataset.unread = 'true'
|
|
1608
|
+
|
|
1609
|
+
const time = document.createElement('span')
|
|
1610
|
+
time.className = 'logs-time'
|
|
1611
|
+
time.textContent = new Date(event.received_at).toLocaleTimeString()
|
|
1612
|
+
time.title = event.received_at
|
|
1613
|
+
|
|
1614
|
+
const where = document.createElement('span')
|
|
1615
|
+
where.className = 'logs-where'
|
|
1616
|
+
where.textContent = event.run_name || event.run_id || '—'
|
|
1617
|
+
|
|
1618
|
+
const who = document.createElement('span')
|
|
1619
|
+
who.className = 'logs-who'
|
|
1620
|
+
who.textContent = event.agent_nickname || event.agent_id || ''
|
|
1621
|
+
|
|
1622
|
+
const what = document.createElement('span')
|
|
1623
|
+
what.className = 'logs-what'
|
|
1624
|
+
const title = document.createElement('span')
|
|
1625
|
+
title.className = 'logs-title'
|
|
1626
|
+
title.textContent = event.title
|
|
1627
|
+
what.appendChild(title)
|
|
1628
|
+
if (event.detail) {
|
|
1629
|
+
const detail = document.createElement('span')
|
|
1630
|
+
detail.className = 'logs-detail'
|
|
1631
|
+
detail.textContent = event.detail
|
|
1632
|
+
what.appendChild(detail)
|
|
1633
|
+
}
|
|
1634
|
+
row.append(time, where, who, what)
|
|
1635
|
+
el.logsList.appendChild(row)
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
async function markAllRead() {
|
|
1640
|
+
try {
|
|
1641
|
+
const result = await api('POST', '/api/notifications/read', {})
|
|
1642
|
+
insights.readSeq = result.read_seq
|
|
1643
|
+
el.logsAnnouncer.textContent = t('web.logsMarkedRead')
|
|
1644
|
+
await loadLogs()
|
|
1645
|
+
clearPulse()
|
|
1646
|
+
} catch (err) {
|
|
1647
|
+
el.logsError.textContent = err instanceof Error ? err.message : String(err)
|
|
1648
|
+
el.logsError.hidden = false
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
// ---- the agent-card pulse --------------------------------------------------------------------
|
|
1653
|
+
// One timer for the next expiry, not one per card: a card's remainder is derived from the newest unread event's
|
|
1654
|
+
// server timestamp on every render, so a reload keeps the remainder instead of restarting the animation.
|
|
1655
|
+
function pulseState() {
|
|
1656
|
+
const notifications = insights.notifications || {}
|
|
1657
|
+
const pulseMs = Number(notifications.agent_pulse_ms ?? 0)
|
|
1658
|
+
return { pulseMs, latestTs: notifications.latest_ts || null }
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
// The pulse belongs to the card that has news: `unread_by` lists one entry per (run, agent), so an approval on one
|
|
1662
|
+
// agent no longer animates the whole sidebar. An event with no agent is run-level and pulses the run's cards.
|
|
1663
|
+
function pulseFor(agent, run) {
|
|
1664
|
+
const notifications = insights.notifications || {}
|
|
1665
|
+
const pulseMs = Number(notifications.agent_pulse_ms ?? 0)
|
|
1666
|
+
if (pulseMs <= 0) return 0
|
|
1667
|
+
const entries = Array.isArray(notifications.unread_by) ? notifications.unread_by : []
|
|
1668
|
+
// An agent event and a run-level event can both apply to this card: keep the *newest* timestamp, not the last
|
|
1669
|
+
// one in the array, or a card can pulse for a stale approval while its own news is newer.
|
|
1670
|
+
let latest = null
|
|
1671
|
+
for (const entry of entries) {
|
|
1672
|
+
const applies = entry.agent_id === agent.id || (entry.agent_id === '' && run && entry.run_id === run.id)
|
|
1673
|
+
if (!applies) continue
|
|
1674
|
+
if (!latest || entry.latest_ts > latest) latest = entry.latest_ts
|
|
1675
|
+
}
|
|
1676
|
+
if (!latest) return 0
|
|
1677
|
+
const seen = pulseSeenAt.get(latest)
|
|
1678
|
+
return core().pulseRemaining(latest, Date.now(), pulseMs, seen)
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
function renderPulse(card, agent, run) {
|
|
1682
|
+
const remaining = pulseFor(agent, run)
|
|
1683
|
+
card.classList.toggle('card-pulse', remaining > 0)
|
|
1684
|
+
if (remaining > 0) card.style.setProperty('--pulse-remaining', `${remaining}ms`)
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
// One timer for the *earliest* expiry, rescheduled whenever the summary changes: a timer pinned to the old
|
|
1688
|
+
// `agent_pulse_ms` would outlive a shorter setting, and a timer started at the full length would repaint long after
|
|
1689
|
+
// the last ring finished.
|
|
1690
|
+
function schedulePulseTick() {
|
|
1691
|
+
if (pulseTimer) { globalThis.clearTimeout(pulseTimer); pulseTimer = null }
|
|
1692
|
+
const { pulseMs } = pulseState()
|
|
1693
|
+
if (pulseMs <= 0) return
|
|
1694
|
+
const entries = (insights.notifications && insights.notifications.unread_by) || []
|
|
1695
|
+
let earliest = Number.POSITIVE_INFINITY
|
|
1696
|
+
const now = Date.now()
|
|
1697
|
+
for (const entry of entries) {
|
|
1698
|
+
const remaining = core().pulseRemaining(entry.latest_ts, now, pulseMs)
|
|
1699
|
+
if (remaining > 0 && remaining < earliest) earliest = remaining
|
|
1700
|
+
}
|
|
1701
|
+
if (!Number.isFinite(earliest)) return
|
|
1702
|
+
pulseTimer = setTimeout(() => {
|
|
1703
|
+
pulseTimer = null
|
|
1704
|
+
renderSidebar()
|
|
1705
|
+
schedulePulseTick()
|
|
1706
|
+
}, earliest + 25)
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
function clearPulse() {
|
|
1710
|
+
pulseSeenAt.clear()
|
|
1711
|
+
if (pulseTimer) { globalThis.clearTimeout(pulseTimer); pulseTimer = null }
|
|
1712
|
+
renderSidebar()
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
// 16-unit glyphs for the run actions, drawn like the plan icon: `currentColor`, no library, `aria-hidden` because the
|
|
1716
|
+
// button carries the label.
|
|
1717
|
+
function runActionIcon(kind) {
|
|
1718
|
+
const glyph = kind === 'add'
|
|
1719
|
+
? '<path d="M8 3v10M3 8h10" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" fill="none"/>'
|
|
1720
|
+
: kind === 'stop'
|
|
1721
|
+
? '<rect x="4" y="4" width="8" height="8" rx="1.5" stroke="currentColor" stroke-width="1.6" fill="none"/>'
|
|
1722
|
+
: '<path d="M3.5 5h9M6.5 5V3.5h3V5M5 5l.6 8h4.8L11 5" stroke="currentColor" stroke-width="1.4" '
|
|
1723
|
+
+ 'stroke-linecap="round" stroke-linejoin="round" fill="none"/>'
|
|
1724
|
+
return `<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" focusable="false">${glyph}</svg>`
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1103
1727
|
function renderCard(run, agent) {
|
|
1104
1728
|
const card = document.createElement('div')
|
|
1105
1729
|
card.className = 'card' + (agent.status === 'ended' ? ' is-ended' : '')
|
|
1730
|
+
// The plan dialog returns focus here when the run's card is gone: a keyboard user who pressed Esc must not land on
|
|
1731
|
+
// `body`, and the card is the next best place to be ("this is the thing I was looking at").
|
|
1732
|
+
card.dataset.runCard = run.id
|
|
1733
|
+
card.tabIndex = -1
|
|
1106
1734
|
card.setAttribute('aria-selected', String(agent.id === selectedId))
|
|
1107
1735
|
card.dataset.status = agent.status
|
|
1108
1736
|
card.dataset.provider = agent.provider
|
|
@@ -1174,6 +1802,7 @@
|
|
|
1174
1802
|
tail.appendChild(lifecycle)
|
|
1175
1803
|
}
|
|
1176
1804
|
card.appendChild(tail)
|
|
1805
|
+
renderPulse(card, agent, run)
|
|
1177
1806
|
|
|
1178
1807
|
if (agent.canAttach) {
|
|
1179
1808
|
open.title = t('web.openAgentTitle', { name: agent.nickname })
|
|
@@ -2104,6 +2733,20 @@
|
|
|
2104
2733
|
el.doctorRefresh.addEventListener('click', loadDoctor)
|
|
2105
2734
|
el.doctorClose.addEventListener('click', () => el.doctorDialog.close())
|
|
2106
2735
|
el.aboutBtn.addEventListener('click', openAboutDialog)
|
|
2736
|
+
el.logsBtn.addEventListener('click', () => { void openInsightsDialog() })
|
|
2737
|
+
el.insightsClose.addEventListener('click', () => el.insightsDialog.close())
|
|
2738
|
+
el.planClose.addEventListener('click', closePlanDialog)
|
|
2739
|
+
el.planPlayPause.addEventListener('click', () => { void togglePlanPlayPause() })
|
|
2740
|
+
// Esc closes the dialog natively; the focus has to come back to the icon that opened it, or the keyboard user lands on
|
|
2741
|
+
// `body`. The button is looked up by run id at this moment, because the card may have been rebuilt by an SSE frame while
|
|
2742
|
+
// the dialog was open — and if the card is gone entirely, the focus still has to land somewhere sensible.
|
|
2743
|
+
planController.attach(el.planDialog)
|
|
2744
|
+
el.planFilterAll.addEventListener('click', () => setPlanFilter('all'))
|
|
2745
|
+
el.planFilterOpen.addEventListener('click', () => setPlanFilter('open'))
|
|
2746
|
+
el.planFilterWaiting.addEventListener('click', () => setPlanFilter('waiting'))
|
|
2747
|
+
el.logsFilterRun.addEventListener('change', () => { void loadLogs() })
|
|
2748
|
+
el.logsUnread.addEventListener('change', () => { void loadLogs() })
|
|
2749
|
+
el.logsMarkRead.addEventListener('click', () => { void markAllRead() })
|
|
2107
2750
|
el.aboutClose.addEventListener('click', () => el.aboutDialog.close())
|
|
2108
2751
|
el.welcomeConnect.addEventListener('click', () => { el.welcomeDialog.close(); openMcpDialog() })
|
|
2109
2752
|
el.welcomeClose.addEventListener('click', () => el.welcomeDialog.close())
|
|
@@ -2181,6 +2824,14 @@
|
|
|
2181
2824
|
return `${String(value).replace('T', ' ').slice(0, 16)}Z`
|
|
2182
2825
|
}
|
|
2183
2826
|
|
|
2827
|
+
// A second of local clock for the driver line only. It touches `#plan-ticks` and nothing else: the cards are rebuilt
|
|
2828
|
+
// when the state changes, never because time passed (block 71).
|
|
2829
|
+
globalThis.setInterval(updatePlanTicksClock, 1000)
|
|
2830
|
+
document.addEventListener('visibilitychange', () => {
|
|
2831
|
+
// A tab that slept comes back with a stale countdown; the marks and the corrected clock fix it without a request.
|
|
2832
|
+
if (!document.hidden) updatePlanTicksClock()
|
|
2833
|
+
})
|
|
2834
|
+
|
|
2184
2835
|
initBrandDuck()
|
|
2185
2836
|
loadState().catch((err) => {
|
|
2186
2837
|
el.sidebarEmpty.hidden = false
|