From 5b55c39b64f807acc70a35983a0fd979733b1430 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 13 Nov 2026 12:32:54 +0000 Subject: [PATCH] feat(kvb-check-score): score journal, backfill and per-metric burndown overlays (006) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit score.py names the Cost and Time metrics Tokens and Velocity from one label file and appends every scored block to a score journal in the council root. backfill.py rebuilds that journal from commit messages with its own label mapping, deterministic and idempotent, so another host can import its history. The hub serves the journal, and the Gantt burndown draws each metric as its own overlay on a right 0-100 % axis, every overlay off by default and switched by legend chips whose state the view store keeps. ๐ŸŽฏ Fix: 90 % ๐Ÿ’ฅ Break: 5 % ๐Ÿ’ธ Cost: 100 % โฑ๏ธ Time: 100 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 86 ๐Ÿšฆ Gate: โœ… 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 --- orchestrator/kvb_orchestrator/handler.py | 3 + orchestrator/kvb_orchestrator/scores.py | 44 +++ orchestrator/templates/page-tasks-gantt.js | 78 +++- orchestrator/templates/plan.js | 40 +- orchestrator/templates/style-tasks.css | 9 + skills/kvb-check-confidence/SKILL.md | 4 +- skills/kvb-check-efficiency/SKILL.md | 4 +- .../kvb-check-efficiency/scripts/measure.py | 41 ++- skills/kvb-check-efficiency/scripts/tokens.py | 49 ++- skills/kvb-check-gate/SKILL.md | 2 +- skills/kvb-check-score/SKILL.md | 56 ++- skills/kvb-check-score/labels.json | 14 + skills/kvb-check-score/scripts/backfill.py | 252 +++++++++++++ skills/kvb-check-score/scripts/journal.py | 184 ++++++++++ skills/kvb-check-score/scripts/score.py | 162 ++++++--- skills/kvb-check-speed/SKILL.md | 6 +- skills/kvb-ci-triage/funnel.md | 2 +- skills/kvb-code-tune/listen.md | 2 +- skills/kvb-git-commit-no-verify/SKILL.md | 4 +- skills/kvb-git-pr-create/SKILL.md | 4 +- skills/kvb-git-pr-label/SKILL.md | 4 +- skills/kvb-org-matrix/SKILL.md | 4 +- skills/kvb-org-swarm/SKILL.md | 2 +- tests/score_fixture.py | 88 +++++ tests/test_efficiency.py | 41 ++- tests/test_hub_overlays.py | 232 ++++++++++++ tests/test_hub_scores.py | 60 +++ tests/test_score.py | 49 +-- tests/test_score_backfill.py | 165 +++++++++ tests/test_score_journal.py | 343 ++++++++++++++++++ 30 files changed, 1806 insertions(+), 142 deletions(-) create mode 100644 orchestrator/kvb_orchestrator/scores.py create mode 100644 skills/kvb-check-score/labels.json create mode 100755 skills/kvb-check-score/scripts/backfill.py create mode 100644 skills/kvb-check-score/scripts/journal.py create mode 100644 tests/score_fixture.py create mode 100644 tests/test_hub_overlays.py create mode 100644 tests/test_hub_scores.py create mode 100644 tests/test_score_backfill.py create mode 100644 tests/test_score_journal.py diff --git a/orchestrator/kvb_orchestrator/handler.py b/orchestrator/kvb_orchestrator/handler.py index 4f96e0a..7149aac 100644 --- a/orchestrator/kvb_orchestrator/handler.py +++ b/orchestrator/kvb_orchestrator/handler.py @@ -11,6 +11,7 @@ from .diffs import DIFF_BODY_LIMIT from .engines import STT_LIMIT from .exchange import PLAIN_CSP, Exchange from .resources import RESOURCES, sampled +from .scores import scored BODY_LIMIT = 1 << 20 UPLOAD_LIMIT = 50 << 20 @@ -118,6 +119,8 @@ class Handler(Exchange): self.answer(hub.repositories, HTTPStatus.OK) elif path == "/api/resources": self.answer(lambda: sampled(hub.kept / RESOURCES, hub.span(self.query(), time.time())), HTTPStatus.OK) + elif path == "/api/scores": + self.answer(lambda: scored(hub.council, hub.scripts.skills, hub.span(self.query(), time.time())), HTTPStatus.OK) elif path == "/api/subagents": self.answer(lambda: hub.subagents(self.query()), HTTPStatus.OK) elif path == "/api/runner/jobs": diff --git a/orchestrator/kvb_orchestrator/scores.py b/orchestrator/kvb_orchestrator/scores.py new file mode 100644 index 0000000..135405c --- /dev/null +++ b/orchestrator/kvb_orchestrator/scores.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +from pathlib import Path + +from .records import epoch, parse_line, read_json, read_regular + +SCORES = "scores.jsonl" +LABELS = "kvb-check-score/labels.json" +FILE_LIMIT = 64 << 20 + + +def checked(labels: object) -> dict | None: + """Args: + labels: the parsed label file, or None. + + Returns: + labels when its "metrics" is a non-empty object of entries with a string + emoji and label, else None. + """ + metrics = labels.get("metrics") if isinstance(labels, dict) else None + valid = isinstance(metrics, dict) and metrics and all(isinstance(metric, dict) and isinstance(metric.get("emoji"), str) and isinstance(metric.get("label"), str) for metric in metrics.values()) + return labels if valid else None + + +def scored(council: Path, skills: Path, span: tuple[float, float]) -> dict: + """Args: + council: the council directory holding scores.jsonl, which score.py + and backfill.py of kvb-check-score append to. + skills: the skills directory holding kvb-check-score/labels.json. + span: (begin, end) of the burndown's time range in epoch seconds. + + Returns: + {"since", "until", "labels", "rows"}: the label file, None when + unreadable or not as checked() wants it, and the journal rows whose time lies within the span, in + time order. + """ + begin, end = span + try: + lines = read_regular(council / SCORES, FILE_LIMIT).splitlines() + except (OSError, ValueError): + lines = [] + rows = [row for row in map(parse_line, lines) if row is not None and isinstance(row.get("values"), dict)] + inside = [row for row in rows if (moment := epoch(row.get("time"))) is not None and begin <= moment <= end] + return {"since": begin, "until": end, "labels": checked(read_json(skills / LABELS)), "rows": sorted(inside, key=lambda row: row["time"])} diff --git a/orchestrator/templates/page-tasks-gantt.js b/orchestrator/templates/page-tasks-gantt.js index 5c5fdca..470f4e1 100644 --- a/orchestrator/templates/page-tasks-gantt.js +++ b/orchestrator/templates/page-tasks-gantt.js @@ -1,5 +1,7 @@ const GANTT = {label: 240, right: 28, top: 34, lane: 30, width: 1180, bar: 16, ticks: 4}; - const BURN = {width: 900, height: 340, left: 52, right: 24, top: 20, bottom: 40}; + const BURN = {width: 900, height: 340, left: 52, right: 24, axis: 56, top: 20, bottom: 40}; + const OVERLAY_PATH = "burn.overlays"; + const scoreView = {key: "", rows: [], labels: null, busy: false, bound: false}; const EDGE_WORDS = {after: "Follows (rasci.py set --after)", base: "Branches from (base branch)", queue: "Waits behind (queue order)"}; const SERIES_WORDS = {scope: "Scope (burnup)", done: "Done (burnup)", remaining: "Remaining (burndown)", unestimated: "Unestimated tasks"}; const STEP_WORDS = [["started", "Started"], ["ended", "Ended"], ["joined", "Joined the scope"]]; @@ -80,11 +82,11 @@ return h("div", {class: "gantt-box"}, h("div", {class: "gantt-scroll"}, svg), legend); } - function burnAxis(svg, from, to, top) { - const x = (t) => BURN.left + ((t - from) / Math.max(to - from, 1)) * (BURN.width - BURN.left - BURN.right); + function burnAxis(svg, from, to, top, right) { + const x = (t) => BURN.left + ((t - from) / Math.max(to - from, 1)) * (BURN.width - BURN.left - right); const y = (value) => BURN.top + (1 - value / top) * (BURN.height - BURN.top - BURN.bottom); for (const value of [0, top / 2, top]) { - svg.append(s("line", {class: "grid", x1: BURN.left, x2: BURN.width - BURN.right, y1: fixed(y(value)), y2: fixed(y(value))})); + svg.append(s("line", {class: "grid", x1: BURN.left, x2: BURN.width - right, y1: fixed(y(value)), y2: fixed(y(value))})); svg.append(s("text", {class: "axis", x: BURN.left - 8, y: fixed(y(value)), dy: "0.35em", "text-anchor": "end"}, String(Math.round(value * 10) / 10))); } for (const [index, t] of [from, (from + to) / 2, to].entries()) { @@ -165,6 +167,68 @@ return {reach, end: forecast === null ? picked.to : Math.min(forecast, reach)}; } + const overlaysReady = () => typeof ViewStore === "object" && typeof LegendChips === "object"; + + async function fetchScores(key, from, to) { + scoreView.busy = true; + scoreView.key = key; + try { + const response = await fetch(`/api/scores?from=${Math.floor(from)}&to=${Math.ceil(to)}`, {cache: "no-store"}); + if (response.ok) { + const found = await response.json(); + scoreView.rows = Array.isArray(found.rows) ? found.rows.filter((row) => row && row.values && typeof row.values === "object") : []; + scoreView.labels = Plan.overlayLabels(found.labels); + } + } catch { + ui.offline = true; + } + scoreView.busy = false; + taskView.sig = ""; + drawTasks(); + } + + function overlayKeys() { + const kept = ViewStore.get(OVERLAY_PATH); + return Array.isArray(kept) && scoreView.labels ? Object.keys(scoreView.labels).filter((key) => kept.includes(key)) : []; + } + + const burnRight = () => (overlaysReady() && overlayKeys().length ? BURN.axis : BURN.right); + + function burnOverlays(svg, picked, x, right) { + const key = `${Math.floor(picked.from)}:${Math.floor(picked.to / 60)}`; + if (key !== scoreView.key && !scoreView.busy) { + fetchScores(key, picked.from, picked.to); + } + if (!scoreView.bound) { + scoreView.bound = true; + ViewStore.on(OVERLAY_PATH, () => { + taskView.sig = ""; + drawTasks(); + }); + } + if (!scoreView.labels) { + return null; + } + const series = Plan.overlaySeries(picked.rows, scoreView.rows, overlayKeys(), picked); + const top = Plan.overlayTop(series); + const y = (value) => BURN.top + (1 - value / top) * (BURN.height - BURN.top - BURN.bottom); + if (series.length) { + for (const value of [0, top / 2, top]) { + svg.append(s("text", {class: "axis overlay-axis", x: BURN.width - right + 6, y: fixed(y(value)), dy: "0.35em", "text-anchor": "start"}, `${Math.round(value)} %`)); + } + } + for (const {key: name, points} of series) { + const d = points.map((point, index) => `${index ? "L" : "M"}${fixed(x(point.t))},${fixed(y(point.value))}`).join(" "); + const group = s("g", {class: `burn-overlay k-${name}`, "data-overlay": name, "data-points": String(points.length)}, d ? s("path", {class: "burn-overlay-line", d}) : null); + for (const point of points) { + group.append(s("circle", {class: "burn-overlay-point", cx: fixed(x(point.t)), cy: fixed(y(point.value)), r: 3, "data-t": point.t, "data-value": point.value}, + s("title", {}, `${absolute.format(stampOf(point.t))} ยท ${scoreView.labels[name]}: ${point.value} % ยท ${point.branch}`))); + } + svg.append(group); + } + return LegendChips.render(Object.entries(scoreView.labels).map(([key, label]) => ({id: key, label, tone: `k-${key}`})), OVERLAY_PATH, "shown"); + } + function burnChart(rows, shown) { const picked = Plan.scoped(rows, taskView.scope, {filtered: shown, since: state.since, until: state.until, now: state.now, holders: lineHolders()}); const series = Plan.burn(picked.rows, {estimation: estimation(), from: picked.from, to: picked.to}).points; @@ -177,7 +241,8 @@ const top = Math.max(1, ...series.flatMap((point) => names.map((name) => point[name])), ...ends); const unit = estimation() === "points" ? "story points; unestimated tasks as a line of their own" : "tasks"; const svg = s("svg", {class: "chart burn", viewBox: `0 0 ${BURN.width} ${BURN.height}`, role: "img", "aria-label": `Burndown and burnup in ${unit}; hover a point for the work packages of its step`}); - const {x, y} = burnAxis(svg, picked.from, reach, top); + const right = burnRight(); + const {x, y} = burnAxis(svg, picked.from, reach, top, right); const last = series[series.length - 1]; if (reach > picked.to) { svg.append(s("line", {class: "now", x1: fixed(x(picked.to)), x2: fixed(x(picked.to)), y1: BURN.top, y2: BURN.height - BURN.bottom})); @@ -191,10 +256,11 @@ burnFinish(svg, segments, x, y); } svg.append(burnPoints(series, Plan.steps(picked.rows, series, picked.from), names, x, y)); + const overlays = overlaysReady() ? burnOverlays(svg, picked, x, right) : null; const stale = h("span", {class: "pill burn-stale", "data-tone": "warn", "data-stale": String(picked.stale.length), role: "img", ...named(`Stale: ${picked.stale.length}`, `Stale: ${picked.stale.length} tasks without a register change for ${Plan.STALE_DAYS} days, counted apart`)}, icon("bi-hourglass-bottom"), String(picked.stale.length)); const legend = h("div", {class: "legend"}, names.map((name) => h("span", {class: `burn-key k-${name}`, "data-series": name}, `${SERIES_WORDS[name]}: ${last[name]}`)), settings.trend.mode === "off" ? null : finishNotes(trend, finish), stale); - return h("div", {class: "burn-box"}, svg, legend, h("p", {class: "muted"}, `${picked.rows.length} tasks in scope, counted in ${unit}`)); + return h("div", {class: "burn-box", "data-panel": "burndown"}, svg, legend, overlays, h("p", {class: "muted"}, `${picked.rows.length} tasks in scope, counted in ${unit}`)); } async function chooseEstimation(id) { diff --git a/orchestrator/templates/plan.js b/orchestrator/templates/plan.js index 52b3873..9e7caf7 100644 --- a/orchestrator/templates/plan.js +++ b/orchestrator/templates/plan.js @@ -262,6 +262,44 @@ const Plan = (() => { return {fixed: reachable(fixed), growing: found.forecast}; } + const branchOf = (row) => (row.branch !== "-" ? row.branch : row.worktree_branch); + + /** + * @param rows - the burndown scope's task rows with branch ("-" for none) and worktree_branch ("" for none). + * @param journal - /api/scores rows {time, branch, values: {metric key: number or null}}. + * @param keys - the metric keys switched on, in the label file's order. + * @param span - {from, to} in epoch seconds. + * @returns one {key, points: [{t, value, branch}]} per key, in keys order: the journal rows of a branch of the + * scope's rows within span whose value for the key is a number, in time order. + */ + function overlaySeries(rows, journal, keys, span) { + const branches = new Set(rows.map(branchOf).filter(Boolean)); + const inside = journal.filter((entry) => branches.has(entry.branch) && entry.time >= span.from && entry.time <= span.to).sort((a, b) => a.time - b.time); + return keys.map((key) => ({ + key, points: inside.filter((entry) => Number.isFinite(entry.values[key])).map((entry) => ({t: entry.time, value: entry.values[key], branch: entry.branch})), + })); + } + + /** + * @param labels - the labels of /api/scores: {metrics: {key: {emoji, label}}}, or anything else. + * @returns {key: "