@diffci.com/diffci 0.3.45 → 0.3.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,8 @@
1
- export declare const RED_BUILDS_SCHEMA = 1;
1
+ /**
2
+ * 2 (2026-11-16): rows carry `branchAgent`, the report adds `byBranchAgent`, and an agent
3
+ * found by its branch prefix is named (`"copilot"`) with `source: "branch"` instead of `"branch prefix"`.
4
+ */
5
+ export declare const RED_BUILDS_SCHEMA = 2;
2
6
  export type JobBucket = "infra" | "ci-only" | "check";
3
7
  export type Verdict = "preventable" | "partly" | "likely" | "shared" | "ci-only" | "flaky" | "infra";
4
8
  export declare const VERDICTS: readonly Verdict[];
@@ -51,9 +55,16 @@ export interface RedRun {
51
55
  ownership?: "own" | "shared" | "timeout" | "unknown";
52
56
  }>;
53
57
  runnerMinutes: number;
58
+ /**
59
+ * The coding agent the head branch is named after (`copilot/fix-123` -> "copilot"), or null. Free: no API
60
+ * call. The branch name itself is left out, since names such as `jane/fix` can carry a user name.
61
+ */
62
+ branchAgent: string | null;
63
+ /** Preventable runs only: agent co-author trailer or branch prefix, after reading the head commit. */
54
64
  agent?: {
55
65
  written: boolean;
56
66
  marker: string;
67
+ source: "trailer" | "branch" | "";
57
68
  commitRead: boolean;
58
69
  };
59
70
  }
@@ -68,10 +79,23 @@ export interface ClassifyInput {
68
79
  }
69
80
  /** Pure: sorts every red run whose jobs were read into one verdict. */
70
81
  export declare function classify(input: ClassifyInput): RedRun[];
82
+ /** The coding agent a branch is named after: `copilot/fix-123` and `claude-fix` give "copilot" and "claude". */
83
+ export declare function branchAgent(branch: string): string | null;
71
84
  export declare function agentMarker(message: string, branch: string): {
72
85
  written: boolean;
73
86
  marker: string;
87
+ source: "trailer" | "branch" | "";
74
88
  };
89
+ /** Pull request runs and red-run verdicts for one group of branches. */
90
+ export interface BranchAgentSlice {
91
+ pullRequestRuns: number;
92
+ redRuns: number;
93
+ analysed: number;
94
+ verdicts: Record<Verdict, number>;
95
+ preventableRunnerMinutes: number;
96
+ }
97
+ /** Key in `byBranchAgent` for runs whose branch names no coding agent. */
98
+ export declare const NO_AGENT_BRANCH = "other";
75
99
  export interface RedBuildsReport {
76
100
  schemaVersion: typeof RED_BUILDS_SCHEMA;
77
101
  repository: string;
@@ -93,10 +117,16 @@ export interface RedBuildsReport {
93
117
  runnerMinutes: number;
94
118
  }>;
95
119
  agentWrittenPreventable: number;
120
+ /**
121
+ * The same counts split by the coding agent each run's head branch is named after (`copilot`, `claude`...),
122
+ * with every other branch under `other`. Branch prefixes undercount agents that use ordinary branch names.
123
+ */
124
+ byBranchAgent: Record<string, BranchAgentSlice>;
96
125
  stoppedEarly: string | null;
97
126
  rows: RedRun[];
98
127
  }
99
- export declare function summarise(repository: string, runs: RunSummary[], rows: RedRun[], stoppedEarly: string | null, neverStarted?: number): RedBuildsReport;
128
+ /** `neverStarted`: the runs marked failed although no job started, as ids (for the per-agent split) or a count. */
129
+ export declare function summarise(repository: string, runs: RunSummary[], rows: RedRun[], stoppedEarly: string | null, neverStarted?: number | ReadonlySet<number>): RedBuildsReport;
100
130
  export declare function formatReport(report: RedBuildsReport): string;
101
131
  export type GitHubGet = (path: string) => Promise<{
102
132
  status: number;
@@ -135,7 +165,7 @@ export interface CollectOptions {
135
165
  /** Fetches runs, jobs, annotations and commit messages, then classifies. Partial data on a stop. */
136
166
  export declare function collectRedBuilds(options: CollectOptions): Promise<RedBuildsReport>;
137
167
  export declare function resolveGitHubToken(env: NodeJS.ProcessEnv): string | undefined;
138
- export declare const RED_BUILDS_USAGE = "Usage: diffci red-builds <owner/repo> [--runs <n>] [--workflow <id|file>] [--json <file>]\n [--check-jobs <regex>] [--ci-only-jobs <regex>]\nHow many of a repository's red pull request builds failed on checks the author could have run before\npushing. Reads GitHub Actions history (read-only, paced) and runs nothing. Needs a GitHub token:\nGITHUB_TOKEN, GH_TOKEN, or a signed-in gh CLI. --runs: most recent pull request runs to read (default 200,\nmax 1000). --check-jobs / --ci-only-jobs: regexes that override which job names count as local checks.";
168
+ export declare const RED_BUILDS_USAGE = "Usage: diffci red-builds <owner/repo> [--runs <n>] [--workflow <id|file>] [--json <file>]\n [--check-jobs <regex>] [--ci-only-jobs <regex>]\nHow many of a repository's red pull request builds failed on checks the author could have run before\npushing. Reads GitHub Actions history (read-only, paced) and runs nothing. Needs a GitHub token:\nGITHUB_TOKEN, GH_TOKEN, or a signed-in gh CLI. --runs: most recent pull request runs to read (default 200,\nmax 1000). --check-jobs / --ci-only-jobs: regexes that override which job names count as local checks.\nRuns on branches named after a coding agent (copilot/, claude/, codex/...) are also counted per agent.";
139
169
  /** Entry point for `diffci red-builds`. Returns the exit code: 0 on a report, 2 on bad input or errors. */
140
170
  export declare function runRedBuildsCommand(args: string[], env?: NodeJS.ProcessEnv, deps?: {
141
171
  get?: GitHubGet;
@@ -24,7 +24,11 @@
24
24
  */
25
25
  import { spawnSync } from "node:child_process";
26
26
  import { writeFileSync } from "node:fs";
27
- export const RED_BUILDS_SCHEMA = 1;
27
+ /**
28
+ * 2 (2026-11-16): rows carry `branchAgent`, the report adds `byBranchAgent`, and an agent
29
+ * found by its branch prefix is named (`"copilot"`) with `source: "branch"` instead of `"branch prefix"`.
30
+ */
31
+ export const RED_BUILDS_SCHEMA = 2;
28
32
  const REPOSITORY = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/;
29
33
  const INFRA_STEP = /set up|setup|checkout|install|cache|download|upload|restore|docker|login|post /i;
30
34
  /** Jobs no local check can stand in for, whatever else the name says ("e2e tests" is not a unit test). */
@@ -186,19 +190,56 @@ export function classify(input) {
186
190
  verdict,
187
191
  failingJobs: detail,
188
192
  runnerMinutes: Math.round(jobs.reduce((sum, job) => sum + minutes(job), 0) * 10) / 10,
193
+ branchAgent: branchAgent(run.headBranch),
189
194
  });
190
195
  }
191
196
  return rows;
192
197
  }
198
+ /** The coding agent a branch is named after: `copilot/fix-123` and `claude-fix` give "copilot" and "claude". */
199
+ export function branchAgent(branch) {
200
+ return AGENT_BRANCH.exec(branch)?.[1]?.toLowerCase() ?? null;
201
+ }
193
202
  export function agentMarker(message, branch) {
194
203
  const trailer = AGENT_TRAILER.exec(message);
195
204
  if (trailer)
196
- return { written: true, marker: (trailer[1] ?? trailer[2] ?? "agent").toLowerCase() };
197
- if (AGENT_BRANCH.test(branch))
198
- return { written: true, marker: "branch prefix" };
199
- return { written: false, marker: "" };
205
+ return { written: true, marker: (trailer[1] ?? trailer[2] ?? "agent").toLowerCase(), source: "trailer" };
206
+ const fromBranch = branchAgent(branch);
207
+ if (fromBranch)
208
+ return { written: true, marker: fromBranch, source: "branch" };
209
+ return { written: false, marker: "", source: "" };
210
+ }
211
+ /** Key in `byBranchAgent` for runs whose branch names no coding agent. */
212
+ export const NO_AGENT_BRANCH = "other";
213
+ function sliceByBranchAgent(runs, rows, neverStartedIds) {
214
+ const slices = {};
215
+ const sliceOf = (agent) => {
216
+ const key = agent ?? NO_AGENT_BRANCH;
217
+ return slices[key] ??= {
218
+ pullRequestRuns: 0, redRuns: 0, analysed: 0, preventableRunnerMinutes: 0,
219
+ verdicts: Object.fromEntries(VERDICTS.map((v) => [v, 0])),
220
+ };
221
+ };
222
+ for (const run of runs) {
223
+ const slice = sliceOf(branchAgent(run.headBranch));
224
+ slice.pullRequestRuns++;
225
+ if (run.conclusion === "failure" && !neverStartedIds.has(run.id))
226
+ slice.redRuns++;
227
+ }
228
+ for (const row of rows) {
229
+ const slice = sliceOf(row.branchAgent);
230
+ slice.analysed++;
231
+ slice.verdicts[row.verdict]++;
232
+ if (row.verdict === "preventable")
233
+ slice.preventableRunnerMinutes += row.runnerMinutes;
234
+ }
235
+ for (const slice of Object.values(slices))
236
+ slice.preventableRunnerMinutes = Math.round(slice.preventableRunnerMinutes);
237
+ return slices;
200
238
  }
239
+ /** `neverStarted`: the runs marked failed although no job started, as ids (for the per-agent split) or a count. */
201
240
  export function summarise(repository, runs, rows, stoppedEarly, neverStarted = 0) {
241
+ const neverStartedIds = typeof neverStarted === "number" ? new Set() : neverStarted;
242
+ const neverStartedCount = typeof neverStarted === "number" ? neverStarted : neverStarted.size;
202
243
  const verdicts = Object.fromEntries(VERDICTS.map((v) => [v, { runs: 0, runnerMinutes: 0 }]));
203
244
  for (const row of rows) {
204
245
  verdicts[row.verdict].runs++;
@@ -207,7 +248,7 @@ export function summarise(repository, runs, rows, stoppedEarly, neverStarted = 0
207
248
  for (const v of VERDICTS)
208
249
  verdicts[v].runnerMinutes = Math.round(verdicts[v].runnerMinutes);
209
250
  const times = runs.map((r) => r.createdAt).sort();
210
- const red = runs.filter((r) => r.conclusion === "failure").length - neverStarted;
251
+ const red = runs.filter((r) => r.conclusion === "failure").length - neverStartedCount;
211
252
  return {
212
253
  schemaVersion: RED_BUILDS_SCHEMA,
213
254
  repository,
@@ -215,11 +256,12 @@ export function summarise(repository, runs, rows, stoppedEarly, neverStarted = 0
215
256
  window: times.length ? { from: times[0], to: times.at(-1) } : null,
216
257
  pullRequestRuns: runs.length,
217
258
  redRuns: red,
218
- neverStarted,
259
+ neverStarted: neverStartedCount,
219
260
  analysed: rows.length,
220
261
  unreadable: red - rows.length,
221
262
  verdicts,
222
263
  agentWrittenPreventable: rows.filter((r) => r.verdict === "preventable" && r.agent?.written).length,
264
+ byBranchAgent: sliceByBranchAgent(runs, rows, neverStartedIds),
223
265
  stoppedEarly,
224
266
  rows,
225
267
  };
@@ -241,6 +283,24 @@ const NOTES = {
241
283
  function pct(part, whole) {
242
284
  return whole ? `${Math.round((part / whole) * 100)}%` : "0%";
243
285
  }
286
+ /** A table of the per-agent split, shown only when some branch is named after a coding agent. */
287
+ function formatBranchAgents(report) {
288
+ const agents = Object.keys(report.byBranchAgent).filter((key) => key !== NO_AGENT_BRANCH).sort();
289
+ if (agents.length === 0)
290
+ return [];
291
+ const lines = ["", `${"By branch prefix".padEnd(20)}${"PR runs".padStart(9)}${"red".padStart(12)}${"preventable".padStart(16)}`];
292
+ for (const key of [...agents, NO_AGENT_BRANCH]) {
293
+ const slice = report.byBranchAgent[key];
294
+ if (!slice)
295
+ continue;
296
+ const label = key === NO_AGENT_BRANCH ? "other branches" : `${key}/...`;
297
+ const red = `${slice.redRuns} (${pct(slice.redRuns, slice.pullRequestRuns)})`;
298
+ const preventable = `${slice.verdicts.preventable} of ${slice.analysed}`;
299
+ lines.push(` ${label.padEnd(18)}${String(slice.pullRequestRuns).padStart(9)}${red.padStart(12)}${preventable.padStart(16)}`);
300
+ }
301
+ lines.push("Agents that use ordinary branch names count under other branches.");
302
+ return lines;
303
+ }
244
304
  export function formatReport(report) {
245
305
  const lines = [`DiffCI red-build check: ${report.repository}${report.workflow ? ` · workflow "${report.workflow}"` : ""}`];
246
306
  if (!report.window) {
@@ -268,7 +328,7 @@ export function formatReport(report) {
268
328
  }
269
329
  const p = report.verdicts.preventable.runs;
270
330
  const likely = report.verdicts.likely.runs;
271
- lines.push("", `Up to ${p} of ${report.analysed} red runs (${pct(p, report.analysed)}) failed only on checks the author could have run before pushing.`, ...(likely ? [`${likely} more failed on such checks without annotations, so whose failure it was is unconfirmed.`] : []), "That is an upper bound: it assumes the check ran and covered the failing test. CI history only; nothing was run.", "", "Catch these inside your coding agent's loop, before the push: npx @diffci.com/diffci init", "Method: https://github.com/DiffCI/core/blob/main/docs/red-builds.md");
331
+ lines.push("", `Up to ${p} of ${report.analysed} red runs (${pct(p, report.analysed)}) failed only on checks the author could have run before pushing.`, ...(likely ? [`${likely} more failed on such checks without annotations, so whose failure it was is unconfirmed.`] : []), "That is an upper bound: it assumes the check ran and covered the failing test. CI history only; nothing was run.", ...formatBranchAgents(report), "", "Catch these inside your coding agent's loop, before the push: npx @diffci.com/diffci init", "Method: https://github.com/DiffCI/core/blob/main/docs/red-builds.md");
272
332
  if (report.stoppedEarly)
273
333
  lines.push("", `Stopped early: ${report.stoppedEarly}. The figures cover what was read.`);
274
334
  return lines.join("\n");
@@ -482,7 +542,7 @@ export async function collectRedBuilds(options) {
482
542
  stoppedEarly = error.message;
483
543
  }
484
544
  }
485
- const neverStarted = runs.filter((r) => r.conclusion === "failure" && jobs.has(r.id) && nothingRan(jobs.get(r.id))).length;
545
+ const neverStarted = new Set(runs.filter((r) => r.conclusion === "failure" && jobs.has(r.id) && nothingRan(jobs.get(r.id))).map((r) => r.id));
486
546
  const report = summarise(repository, runs, rows, stoppedEarly, neverStarted);
487
547
  report.workflow = workflowLabel || runs[0]?.workflowName || null;
488
548
  return report;
@@ -500,7 +560,8 @@ export const RED_BUILDS_USAGE = `Usage: diffci red-builds <owner/repo> [--runs <
500
560
  How many of a repository's red pull request builds failed on checks the author could have run before
501
561
  pushing. Reads GitHub Actions history (read-only, paced) and runs nothing. Needs a GitHub token:
502
562
  GITHUB_TOKEN, GH_TOKEN, or a signed-in gh CLI. --runs: most recent pull request runs to read (default 200,
503
- max 1000). --check-jobs / --ci-only-jobs: regexes that override which job names count as local checks.`;
563
+ max 1000). --check-jobs / --ci-only-jobs: regexes that override which job names count as local checks.
564
+ Runs on branches named after a coding agent (copilot/, claude/, codex/...) are also counted per agent.`;
504
565
  /** Entry point for `diffci red-builds`. Returns the exit code: 0 on a report, 2 on bad input or errors. */
505
566
  export async function runRedBuildsCommand(args, env = process.env, deps = {}) {
506
567
  let repository;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffci.com/diffci",
3
- "version": "0.3.45",
3
+ "version": "0.3.46",
4
4
  "description": "Verification for AI coding agents: runs the tests and checks a change affects, with full fallback and a receipt",
5
5
  "keywords": [
6
6
  "ci",