diff --git a/dashboard/e2e/analytics.spec.ts b/dashboard/e2e/analytics.spec.ts index 73dcd501..a1be1fc0 100644 --- a/dashboard/e2e/analytics.spec.ts +++ b/dashboard/e2e/analytics.spec.ts @@ -171,6 +171,8 @@ async function mockApi(page: Page, init: Partial = {}): Promise = {}): Promise { + const db = await mockApi(page); + await page.goto("/analytics?tab=reliability"); + await expect(page.getByTestId("tile-unnecessary-stops")).toContainText("40%"); + await expect(page.getByTestId("tile-unnecessary-stops")).toContainText("2 of 5 with an outcome (7 stops in all)"); + await expect(page.getByTestId("tile-nuisance-blocks")).toContainText("50%"); + await expect(page.getByTestId("tile-proceeded")).toContainText("15"); + const table = page.getByRole("table", { name: "Recent unnecessary stops and nuisance blocks" }); + await expect(table.locator("tbody tr td:first-child")).toHaveText(["Retry loop never ends", "Monthly or yearly totals?"]); + await expect(table).toContainText("Review dismissed"); + await expect(table).toContainText("Answered with the default"); + await expect(table.getByRole("link", { name: "Open run" })).toHaveAttribute("href", /\/runs\/detail\/?\?id=01RUNASKED000000000000000A$/); + const download = page.waitForEvent("download"); + await page.getByTestId("export-decisions").click(); + expect((await download).suggestedFilename()).toBe("replay-cases-30d.json"); + expect(db.calls).toContain("/api/analytics/decisions?days=30"); + await page.getByTestId("tile-nuisance-blocks").scrollIntoViewIfNeeded(); + await shot(page, "analytics-decisions"); +}); + test("where it struggles places every red CI run in one outcome, base-branch failures apart", async ({ page }) => { await mockApi(page); await page.goto("/analytics?tab=reliability"); diff --git a/dashboard/src/app/analytics/decisions.tsx b/dashboard/src/app/analytics/decisions.tsx new file mode 100644 index 00000000..e9f9f971 --- /dev/null +++ b/dashboard/src/app/analytics/decisions.tsx @@ -0,0 +1,105 @@ +"use client"; + +import Link from "next/link"; +import { useEffect, useState } from "react"; +import { api, type DecisionRate, type DecisionsAnalytics } from "@/lib/api"; +import { StatGrid, StatTile } from "@/components/stat-tile"; +import { Section } from "@/components/page"; +import { Table } from "@/components/charts"; + +const OUTCOME: Record = { + answered_default: "Answered with the default", + answered_other: "Answered otherwise", + dismissed_review: "Review dismissed", + merged_flagged_unchanged: "Merged with the flagged lines unchanged", + fixed: "Fixed", + cancelled_run: "Run cancelled", + retried: "Retried as it was", + overrode: "Went ahead over it", +}; + +const pct = (r: DecisionRate) => (r.with_outcome ? `${Math.round(r.rate * 100)}%` : "—"); + +function basis(r: DecisionRate, what: string) { + if (!r.total) return `No ${what} in this period`; + if (!r.with_outcome) return `${r.total} ${what}, none acted on yet`; + return `${r.wrong} of ${r.with_outcome} with an outcome (${r.total} ${what} in all)`; +} + +function where(e: DecisionRate["examples"][number]) { + if (e.run_id) return Open run; + if (e.repo && e.pr_number) return `${e.repo} #${e.pr_number}`; + return "—"; +} + +/** The stop judge's wrong calls: questions answered with the default, stops retried as they were, reviews dismissed or merged unchanged. */ +export function DecisionsSection({ days }: { days: number }) { + const window = (days === 7 || days === 90 ? days : 30) as 7 | 30 | 90; + const [data, setData] = useState(null); + const [failed, setFailed] = useState(false); + const [exporting, setExporting] = useState(false); + + useEffect(() => { + let live = true; + api + .getDecisions(window) + .then((d) => live && setData(d)) + .catch(() => live && setFailed(true)); + return () => { + live = false; + }; + }, [window]); + + const download = async () => { + setExporting(true); + try { + const out = await api.exportDecisions(window); + const blob = new Blob([JSON.stringify(out.cases, null, 2)], { type: "application/json" }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = `replay-cases-${window}d.json`; + a.click(); + URL.revokeObjectURL(url); + } finally { + setExporting(false); + } + }; + + if (failed || !data) return null; + const s = data.summary; + const stops = s.unnecessary_stops; + const blocks = s.nuisance_blocks; + const examples = [...stops.examples, ...blocks.examples] + .sort((a, b) => b.created_at.localeCompare(a.created_at)) + .slice(0, 10); + return ( +
+ + + + + +
+ [e.detail, e.step.replace(/_/g, " "), OUTCOME[e.outcome] ?? e.outcome, where(e)])} + empty="None confirmed in this period." + /> + + {stops.wrong + blocks.wrong > 0 && ( +

+ {" "} + to add to the replay suite (remove names before committing them). +

+ )} + + ); +} diff --git a/dashboard/src/app/analytics/page.tsx b/dashboard/src/app/analytics/page.tsx index f123c3a5..f9f36449 100644 --- a/dashboard/src/app/analytics/page.tsx +++ b/dashboard/src/app/analytics/page.tsx @@ -15,6 +15,7 @@ import { inputClass } from "@/components/ui"; import { Page, PageHeader, Section } from "@/components/page"; import { RepoFilter, formatDuration, formatMs } from "@/components/list"; import { ChartCard, ChartTip, SERIES, Table, axis, delta, shortDay } from "@/components/charts"; +import { DecisionsSection } from "./decisions"; const PERIODS: { value: `${AnalyticsPeriod}`; label: string }[] = [ { value: "7", label: "7 days" }, @@ -332,6 +333,8 @@ function Body({ data, loading, stats, tab }: { data: Analytics; loading: boolean {!!data.loops_stopped?.total && } + +
diff --git a/dashboard/src/app/reviewer/config/page.tsx b/dashboard/src/app/reviewer/config/page.tsx index ab5ef2a6..5ce72ade 100644 --- a/dashboard/src/app/reviewer/config/page.tsx +++ b/dashboard/src/app/reviewer/config/page.tsx @@ -603,12 +603,13 @@ function ReviewerConfigPage() { /> New features need new tests; changed or fixed behavior needs its tests added or updated. Coderhelm writes those tests itself - when it plans and codes a change (following your AGENTS.md / CLAUDE.md test conventions), and the reviewer blocks any pull - request, Coderhelm's or a person's, whose tests are missing or stale. Refactors, docs, config and dependency bumps are exempt. + when it plans and codes a change (following your AGENTS.md / CLAUDE.md test conventions), and the reviewer always flags a + missing or stale test as a Suggestion. Changes are requested only for a correctness, security or data-loss problem, so a + missing test alone never holds the merge. Refactors, docs, config and dependency bumps are exempt.

} {...marks("require_tests")} diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts index a786e8b9..dd60c788 100644 --- a/dashboard/src/lib/api.ts +++ b/dashboard/src/lib/api.ts @@ -484,6 +484,10 @@ export const api = { getStats: () => request<{ month: Stats; all_time: Stats }>("/api/stats"), getStatsHistory: () => request<{ months: MonthStats[] }>("/api/stats/history"), + /** The stop judge's decisions: unnecessary stops and nuisance blocks over 7, 30 or 90 days. */ + getDecisions: (days: 7 | 30 | 90) => request(`/api/analytics/decisions?days=${days}`), + /** Every confirmed-wrong decision as a replay case (names as written: scrub before committing one). */ + exportDecisions: (days: 7 | 30 | 90) => request<{ cases: unknown[] }>(`/api/analytics/decisions/export?days=${days}`), /** The analytics page: one period (7, 30 or 90 days, or this month so far) and the one before it. */ getAnalytics: (period: AnalyticsPeriod, repo?: string) => request( @@ -4908,3 +4912,42 @@ export interface SelfHostDetail { trend: SelfHostTrendDay[]; audit: { action: string; at: string; detail: string }[]; } + +/** One decision people's act showed was wrong (`common::decision_log::Example`). */ +export interface DecisionExample { + sk: string; + kind: string; + step: string; + category: string; + detail: string; + outcome: string; + created_at: string; + run_id?: string; + repo?: string; + pr_number?: number; +} + +/** A rate of wrong stops or blocks (`common::decision_log::Rate`). */ +export interface DecisionRate { + /** Stops (or blocks) the judge let happen. */ + total: number; + /** Of those, the ones a person's act settled either way. */ + with_outcome: number; + /** Of those, confirmed wrong. */ + wrong: number; + /** wrong / with_outcome. */ + rate: number; + by_category: [string, number][]; + examples: DecisionExample[]; +} + +/** GET /api/analytics/decisions. */ +export interface DecisionsAnalytics { + days: number; + summary: { + unnecessary_stops: DecisionRate; + nuisance_blocks: DecisionRate; + decisions: number; + proceeded: number; + }; +} diff --git a/docs/content/docs/getting-started/reviewer.mdx b/docs/content/docs/getting-started/reviewer.mdx index 98f4410e..af8f2d12 100644 --- a/docs/content/docs/getting-started/reviewer.mdx +++ b/docs/content/docs/getting-started/reviewer.mdx @@ -5,6 +5,20 @@ description: Turn on CoderHelm's reviewer for your team's pull requests, and con The reviewer reviews pull requests written by people (and by CoderHelm). It posts a real GitHub review, either **Approve** or **Request changes**, with comments on the lines that matter, and a risk level of low, medium or high. Changes that touch migrations, authentication, secrets or payments are always rated high. +## When it requests changes + +It requests changes only for a named correctness, security or data-loss problem, with the file and line and the evidence that shows it (the code path, a test or CI result, a data query, or the documentation of the tool involved). Before it posts, a final check looks at the whole pull request and its threads; when nothing named holds up, it approves instead and says what it assumed. + +Every other finding is a labeled note on the approval: + +| Label | What it is | +| --- | --- | +| **Nit** | A style, naming or layout preference | +| **Suggestion** | An optional improvement, hardening, a refactor, a missing test, or a written team rule the change doesn't follow with no defect shown | +| **FYI** | A question, a fact worth confirming, or a concern nothing in the change could show | + +A request for changes lasts only while what it names does: once those threads are fixed or answered, the next review approves. + ## Turn it on 1. Open **Reviewer**, then **Reviewer settings**, and pick a repository. @@ -33,7 +47,7 @@ When the review is done, the check ends as neutral if the review has findings, a | Section | What you can set | | --- | --- | | Reviews | On or off, trigger label, what to focus on | -| Tests | Check the change by running tests; require tests | +| Tests | Check the change by running tests (a failing run requests changes); require tests (a missing test is a Suggestion, and CoderHelm writes tests for its own changes) | | CI labels | Labels it may add, labels that must go together, guidance | | Auto-merge | Merge when it approves, merge method, deploy labels, also require a person's approval | | Tags and health check | Tag after merge, tag style and prefix, batch window, health check after merge |