--- title: Daily WSJF Triage --- ```js import {POLL_HEAVY, apiFetch, pollDelay, waitForVisible} from "./components/config.js"; import {injectTocTop} from "./components/toc-sidebar.js"; import {withDocHelp} from "./components/doc-overlay.js"; import { ACTION_META, actionMeta, buildCandidateIndex, buildPatternRows, isWithinDays, normalizeTriageReports, resolveCandidate, topAction, truncateSummary, } from "./components/wsjf-triage.js"; ``` ```js const triageState = (async function*() { let failures = 0; while (true) { let events = [], workplanIndex = {workstreams: {}}, ok = false; try { const [reportsResp, indexResp] = await Promise.all([ apiFetch("/progress/?event_type=daily_triage&limit=14"), apiFetch("/workplans/index"), ]); ok = reportsResp.ok && indexResp.ok; events = reportsResp.ok ? await reportsResp.json() : []; workplanIndex = indexResp.ok ? await indexResp.json() : {workstreams: {}}; } catch {} failures = ok ? 0 : failures + 1; yield {events, workplanIndex, ok, ts: new Date()}; await waitForVisible(pollDelay({ok, base: POLL_HEAVY, failures})); } })(); ``` ```js const reports = normalizeTriageReports(triageState.events ?? []); const candidateIndex = buildCandidateIndex(triageState.workplanIndex ?? {workstreams: {}}); const _ok = triageState.ok ?? false; const _ts = triageState.ts; const latestReport = reports[0] ?? null; ``` # Daily WSJF Triage ```js function fmtDateTime(iso) { if (!iso) return "-"; const d = new Date(iso); return Number.isNaN(d.getTime()) ? String(iso) : d.toLocaleString(); } function fmtDate(iso) { if (!iso) return "-"; const d = new Date(iso); return Number.isNaN(d.getTime()) ? String(iso).slice(0, 10) : d.toLocaleDateString(undefined, {year: "numeric", month: "short", day: "numeric"}); } function candidateNode(candidate, index) { const resolved = resolveCandidate(candidate, index); return resolved ? html`${candidate}` : html`${candidate || "-"}`; } function actionBadge(action, extraText = "") { const meta = actionMeta(action); return html`${meta.label}${extraText}`; } function recommendationTable(report, index) { const recommendations = report.recommendations ?? []; if (recommendations.length === 0) { return html`

No recommendations were recorded for this report.

`; } return html`
${recommendations.map(rec => html``)}
#CandidateActionConfidenceWhy
${rec.rank} ${candidateNode(rec.candidate, index)} ${actionBadge(rec.action)} ${rec.confidence} ${rec.why || "-"}
${Object.values(ACTION_META).map(meta => html`${actionBadge(meta.label)} ${meta.description}`)}
`; } function reportMetadata(report) { return html`
Scheduled for${fmtDateTime(report.scheduled_for)}
Created${fmtDateTime(report.created_at)}
Instruction${report.instruction_id ?? "-"}
Activity run${report.activity_core_run_id ?? "-"}
Activity${report.activity_id ?? "-"}
Memory note${report.memory_path ?? "-"}
`; } function renderReportDetail(report, index) { return html`

Report Detail

${fmtDate(report.scheduled_for ?? report.created_at)}

Summary

${report.summary || "-"}

Recommendations

${recommendationTable(report, index)}

Run Metadata

${reportMetadata(report)}
`; } function renderPatterns(reports, index) { const windowReports = reports.filter(report => isWithinDays(report.created_at, 14)); const rows = buildPatternRows(windowReports); return html`

Patterns

Last 14 days
${rows.length === 0 ? html`

No repeated recommendations are visible in the loaded 14-day window.

` : html`${rows.map(row => html``)}
WorkstreamTimes RecommendedMost Frequent Action
${candidateNode(row.candidate, index)} ${row.count} / ${Math.max(1, windowReports.length)} reports ${actionBadge(row.action, ` x${row.actionCount}`)}
`}
`; } function renderExplorer(reports, index) { const root = html`
`; const detail = html`
`; const tableBody = html``; const rows = []; let selectedId = reports[0]?.id; function selectReport(report, {scroll = true} = {}) { selectedId = report.id; for (const row of rows) { row.classList.toggle("is-selected", row.dataset.reportId === selectedId); row.setAttribute("aria-selected", row.dataset.reportId === selectedId ? "true" : "false"); } detail.replaceChildren(renderReportDetail(report, index)); if (scroll) detail.scrollIntoView({behavior: "smooth", block: "start"}); } for (const report of reports) { const top = topAction(report.recommendations); const row = html` ${fmtDate(report.scheduled_for ?? report.created_at)} ${truncateSummary(report.summary)} ${report.recommendations.length} ${top ? actionBadge(top.action, ` x${top.count}`) : "-"} `; row.addEventListener("click", () => selectReport(report)); row.addEventListener("keydown", event => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); selectReport(report); } }); rows.push(row); } tableBody.append(...rows); root.append( html`

Recent Reports

${reports.length} loaded
${tableBody}
DateSummary# RecsTop Action
`, detail, renderPatterns(reports, index), ); if (reports[0]) selectReport(reports[0], {scroll: false}); return root; } ``` ```js const _liveEl = html`
${_ok ? `Live - updated ${_ts?.toLocaleTimeString()} - ${reports.length} triage reports` : html`Offline - run: make api`}
`; withDocHelp(_liveEl, "/docs/live-data"); injectTocTop("live-indicator", _liveEl); const _h1 = document.querySelector("#observablehq-main h1"); if (_h1) { _h1.style.position = "relative"; withDocHelp(_h1, "/docs/wsjf-triage"); } display(html`

Daily State Hub triage from activity-core. Recommendations are advisory; the operator and workplan owners decide what to act on.

`); display(html`
Last updated ${latestReport ? fmtDateTime(latestReport.created_at) : "No daily_triage events yet"}
`); if (reports.length === 0) { const empty = html`

No daily triage reports yet.

The next run is scheduled for 07:20 Europe/Berlin (activity-core daily-statehub-wsjf-triage).

`; withDocHelp(empty, "/docs/wsjf-triage"); display(empty); } else { display(renderExplorer(reports, candidateIndex)); } ```