Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions dashboard/e2e/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
}
return json(route, body);
}
if (p === "/api/analytics/decisions") return json(route, DECISIONS);
if (p === "/api/analytics/decisions/export") return json(route, { cases: [{ case: "stop_judge" }] });
if (p === "/api/deliveries/analytics" && db.deliveries) {
if (db.deliveries === "refused") return json(route, { error: "Admins only" }, 403);
return json(route, {
Expand All @@ -183,6 +185,24 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
return db;
}

// Invented decisions: two of five questions were answered with the default;
// one of two blocks was dismissed.
const DECISIONS = {
days: 30,
summary: {
unnecessary_stops: {
total: 7, with_outcome: 5, wrong: 2, rate: 0.4, by_category: [["product_choice", 2]],
examples: [{ sk: "DECISION#RUN#01RUNASKED000000000000000A#2026-11-02T10:00:00.000Z", kind: "ask", step: "plan", category: "product_choice", detail: "Monthly or yearly totals?", outcome: "answered_default", created_at: "2026-11-02T10:00:00.000Z", run_id: "01RUNASKED000000000000000A" }],
},
nuisance_blocks: {
total: 3, with_outcome: 2, wrong: 1, rate: 0.5, by_category: [["correctness", 1]],
examples: [{ sk: "DECISION#PR#your-team/web#000101#2026-11-03T09:00:00.000Z", kind: "block", step: "review", category: "correctness", detail: "Retry loop never ends", outcome: "dismissed_review", created_at: "2026-11-03T09:00:00.000Z", repo: "your-team/web", pr_number: 101 }],
},
decisions: 25,
proceeded: 15,
},
};

async function shot(page: Page, name: string) {
fs.mkdirSync(SHOTS_DIR, { recursive: true });
await page.addStyleTag({ content: "nextjs-portal{display:none!important}" });
Expand Down Expand Up @@ -230,6 +250,26 @@ test("the scorecard answers whether it is worth it, against the previous period"
await shot(page, "analytics");
});

test("stops and blocks show the unnecessary and the nuisance ones, with examples to export as replay cases", async ({ page }) => {
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");
Expand Down
105 changes: 105 additions & 0 deletions dashboard/src/app/analytics/decisions.tsx
Original file line number Diff line number Diff line change
@@ -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<string, string> = {
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 <Link href={`/runs/detail?id=${e.run_id}`} className="text-zinc-100 underline-offset-2 hover:underline">Open run</Link>;
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<DecisionsAnalytics | null>(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 (
<Section
title="Stops and blocks"
id="decisions"
description="Every question, stop, extra fix round and request for changes goes through one judge. These are the ones people's next step showed weren't needed."
>
<StatGrid>
<StatTile testId="tile-unnecessary-stops" label="Unnecessary stops" value={pct(stops)} note={basis(stops, "stops")} />
<StatTile testId="tile-nuisance-blocks" label="Nuisance blocks" value={pct(blocks)} note={basis(blocks, "blocks")} />
<StatTile testId="tile-proceeded" label="Went ahead instead" value={String(s.proceeded)} note={`Of ${s.decisions} decisions the judge made`} />
</StatGrid>
<div className="mt-4">
<Table
label="Recent unnecessary stops and nuisance blocks"
head={["What", "Step", "Then", "Where"]}
rows={examples.map((e) => [e.detail, e.step.replace(/_/g, " "), OUTCOME[e.outcome] ?? e.outcome, where(e)])}
empty="None confirmed in this period."
/>
</div>
{stops.wrong + blocks.wrong > 0 && (
<p className="mt-3 text-sm text-zinc-400">
<button type="button" onClick={download} disabled={exporting} className="text-zinc-100 underline underline-offset-2 hover:text-white disabled:opacity-60" data-testid="export-decisions">
{exporting ? "Exporting…" : "Export them as replay cases"}
</button>{" "}
to add to the replay suite (remove names before committing them).
</p>
)}
</Section>
);
}
3 changes: 3 additions & 0 deletions dashboard/src/app/analytics/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -332,6 +333,8 @@ function Body({ data, loading, stats, tab }: { data: Analytics; loading: boolean
{!!data.loops_stopped?.total && <LoopsStopped stopped={data.loops_stopped} />}
</Section>

<DecisionsSection days={d} />

<Section title="Reviews" id="reviews" description="Pull request reviews Coderhelm posted, and what became of the findings it raised before.">
<StatGrid>
<Tile label="Reviews posted" value={count(data.reviews.posted)} change={delta(s.reviews, p.reviews, "count", vs)} basis={`On ${plural(data.reviews.prs_reviewed, "PR")}`} />
Expand Down
7 changes: 4 additions & 3 deletions dashboard/src/app/reviewer/config/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,13 @@ function ReviewerConfigPage() {
/>
<SettingsRow
label="Require tests"
help="Blocks pull requests whose new or changed behavior comes without tests."
help="Flags new or changed behavior that comes without tests, as a Suggestion on the approval."
more={
<p>
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&apos;s or a person&apos;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.
</p>
}
{...marks("require_tests")}
Expand Down
43 changes: 43 additions & 0 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DecisionsAnalytics>(`/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<Analytics>(
Expand Down Expand Up @@ -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;
};
}
16 changes: 15 additions & 1 deletion docs/content/docs/getting-started/reviewer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
Expand Down
Loading