feat(kvb-check-score): score journal, backfill and per-metric burndown overlays (006)
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
3418738993
commit
5b55c39b64
30 files changed
+1806
-142
No files matched your search
@@ -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":
|
||||
|
||||
@@ -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"])}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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: "<emoji> <label>"} in the file's order for the entries with a string emoji and label; null when
|
||||
* none has both or labels is no such object.
|
||||
*/
|
||||
function overlayLabels(labels) {
|
||||
const metrics = labels && typeof labels === "object" ? labels.metrics : null;
|
||||
if (!metrics || typeof metrics !== "object" || Array.isArray(metrics)) {
|
||||
return null;
|
||||
}
|
||||
const kept = Object.entries(metrics).filter(([, metric]) => metric && typeof metric.emoji === "string" && typeof metric.label === "string");
|
||||
return kept.length ? Object.fromEntries(kept.map(([key, metric]) => [key, `${metric.emoji} ${metric.label}`])) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param series - overlaySeries().
|
||||
* @returns the top of the right axis: 100, or the largest value when one exceeds it.
|
||||
*/
|
||||
const overlayTop = (series) => Math.max(100, ...series.flatMap((found) => found.points.map((point) => point.value)));
|
||||
|
||||
const KEYS = {
|
||||
prio: () => null,
|
||||
wsjf: (row) => (row.wsjf ? row.wsjf.score : null),
|
||||
@@ -294,7 +332,7 @@ const Plan = (() => {
|
||||
return keyed.map((entry) => entry.row);
|
||||
}
|
||||
|
||||
return {FORECASTS, ESTIMATIONS, TRENDS, SORTS, SERIES, TRENDED, STATUS_ORDER, STALE_DAYS, median, medians, forecastLength, bars, etas, stale, scoped, burn, steps, trend, finishes, lineAt, sortRows};
|
||||
return {FORECASTS, ESTIMATIONS, TRENDS, SORTS, SERIES, TRENDED, STATUS_ORDER, STALE_DAYS, median, medians, forecastLength, bars, etas, stale, scoped, burn, steps, trend, finishes, lineAt, overlaySeries, overlayLabels, overlayTop, sortRows};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = Plan;
|
||||
|
||||
@@ -82,6 +82,15 @@ svg .burn-line.k-unestimated { stroke-dasharray: 6 4; }
|
||||
svg .burn-trend { fill: none; stroke: var(--c); stroke-width: 1.6; stroke-dasharray: 2 5; stroke-linecap: round; }
|
||||
svg .burn-point { fill: var(--c); stroke: transparent; stroke-width: 10; cursor: help; }
|
||||
svg .burn-point:hover { r: 6px; }
|
||||
svg .burn-overlay-line { fill: none; stroke: var(--c); stroke-width: 1.8; stroke-dasharray: 5 3; }
|
||||
svg .burn-overlay-point { fill: var(--c); stroke: transparent; stroke-width: 10; cursor: help; }
|
||||
svg.burn .overlay-axis { fill: var(--muted); }
|
||||
svg.burn .burn-overlay.k-fix, .burn-box .legend-chip.k-fix { --c: var(--ok); }
|
||||
svg.burn .burn-overlay.k-break, .burn-box .legend-chip.k-break { --c: var(--bad); }
|
||||
svg.burn .burn-overlay.k-tokens, .burn-box .legend-chip.k-tokens { --c: var(--warn); }
|
||||
svg.burn .burn-overlay.k-velocity, .burn-box .legend-chip.k-velocity { --c: var(--info); }
|
||||
svg.burn .burn-overlay.k-security, .burn-box .legend-chip.k-security { --c: var(--violet); }
|
||||
svg.burn .burn-overlay.k-score, .burn-box .legend-chip.k-score { --c: var(--accent); }
|
||||
svg .forecast-line { stroke: var(--ok); stroke-width: 1.4; stroke-dasharray: 4 3; }
|
||||
svg .forecast-label { fill: var(--ok); font-size: var(--fs-2xs); font-weight: 650; }
|
||||
.burn-forecast { display: inline-flex; align-items: center; gap: 6px; }
|
||||
|
||||
Reference in new issue
Block a user