@diffci.com/diffci 0.3.45 → 0.3.47

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.
Files changed (26) hide show
  1. package/dist-client/src/client/red-builds.d.ts +33 -3
  2. package/dist-client/src/client/red-builds.js +71 -10
  3. package/dist-client/src/client/verify.d.ts +1 -1
  4. package/dist-client/src/client/verify.js +3 -6
  5. package/dist-client/src/client/working-tree.d.ts +1 -12
  6. package/dist-client/src/client/working-tree.js +60 -40
  7. package/node_modules/@diffci.com/core/README.md +34 -5
  8. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.d.ts +23 -0
  9. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +180 -0
  10. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -0
  11. package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +5 -0
  12. package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
  13. package/node_modules/@diffci.com/core/dist/repo/file-references.js +43 -6
  14. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
  15. package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +1 -1
  16. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +5 -0
  17. package/node_modules/@diffci.com/core/dist/repo/impact.js +22 -0
  18. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  19. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +9 -0
  20. package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +195 -0
  21. package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +2 -0
  22. package/node_modules/@diffci.com/core/src/repo/file-references.ts +41 -6
  23. package/node_modules/@diffci.com/core/src/repo/impact-types.ts +1 -0
  24. package/node_modules/@diffci.com/core/src/repo/impact.ts +22 -0
  25. package/node_modules/@diffci.com/core/src/repo/types.ts +6 -0
  26. package/package.json +2 -2
@@ -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;
@@ -52,7 +52,7 @@ export interface VerificationReport {
52
52
  written_during_verification?: string[];
53
53
  /** Files that existed before the run and changed during it, at most 20. Their presence blocks the verdict. */
54
54
  changed_during_verification?: SnapshotChange[];
55
- /** Commit-range only: checked-out files that differ from HEAD only by CRLF line endings, at most 20. */
55
+ /** Checked-out files left out of the snapshot because they differ from HEAD only by CRLF line endings, at most 20. */
56
56
  line_ending_only_changes?: string[];
57
57
  };
58
58
  analysis: {
@@ -13,7 +13,7 @@ import { outcomeLogPath, readOutcomes, reusablePass } from "./outcome-log.js";
13
13
  import { likelyFailures, rankTests, testHistory } from "./test-ranking.js";
14
14
  import { assignShards } from "./test-shards.js";
15
15
  import { mergeTestFileResults } from "./test-results.js";
16
- import { captureWorkingTreeSnapshot, lineEndingOnlyChanges, snapshotChanges } from "./working-tree.js";
16
+ import { captureWorkingTreeSnapshot, snapshotChanges } from "./working-tree.js";
17
17
  export const VERIFICATION_SCHEMA = "diffci.verification.v1";
18
18
  function receiptRange(range) {
19
19
  if (!range)
@@ -425,12 +425,9 @@ async function verifyCommitRange(options) {
425
425
  const message = error instanceof Error ? error.message : String(error);
426
426
  return blocked(unknownSnapshot(), "commit-range", message, { status: "ERROR", stage: "context", fallback_reasons: [], error: message });
427
427
  }
428
+ // A checkout that differs from HEAD only by CRLF line endings is clean: the snapshot leaves those files out.
428
429
  if (before.changed) {
429
- const lineEndingOnly = lineEndingOnlyChanges(repoPath, before);
430
- if (!lineEndingOnly) {
431
- return blocked(before, "commit-range", "commit-range verification requires a clean checkout; use verify --changed for uncommitted changes", { status: "not_needed", fallback_reasons: [] });
432
- }
433
- before = { ...before, lineEndingOnly };
430
+ return blocked(before, "commit-range", "commit-range verification requires a clean checkout; use verify --changed for uncommitted changes", { status: "not_needed", fallback_reasons: [] });
434
431
  }
435
432
  const temporaryDirectory = mkdtempSync(join(tmpdir(), "diffci-verify-"));
436
433
  try {
@@ -6,20 +6,9 @@ export interface WorkingTreeSnapshot {
6
6
  /** Unreachable commit used only so the existing commit-range analyzer can inspect the tree. */
7
7
  commitSha: string;
8
8
  changed: boolean;
9
- /** Set when every difference from HEAD is a CRLF checkout of an LF-committed file (see lineEndingOnlyChanges). */
9
+ /** Files left out of the snapshot because they differ from HEAD only by a CRLF checkout of LF content (crlfCheckouts). */
10
10
  lineEndingOnly?: string[];
11
11
  }
12
- /**
13
- * The paths, when every difference between HEAD and the snapshot is only CRLF line endings on files
14
- * committed with LF; otherwise undefined.
15
- *
16
- * WHY (2026-11-06). On DentalPresence the pre-push hook could not verify any push: 268 files had been
17
- * checked out with CRLF under Git for Windows' system-wide `core.autocrlf=true` before the repository
18
- * set it to false. `git status` called the checkout clean because its stat cache still matched, while
19
- * the snapshot re-reads every file and saw 268 changes. Git's own view decides "clean" for the user, so
20
- * a CRLF-only checkout is verified rather than blocked, and the receipt names the files.
21
- */
22
- export declare function lineEndingOnlyChanges(repoPathInput: string, snapshot: WorkingTreeSnapshot): string[] | undefined;
23
12
  /** One path that differs between two snapshots. A rename is a deletion plus an addition. */
24
13
  export interface SnapshotChange {
25
14
  path: string;
@@ -2,45 +2,6 @@ import { spawnSync } from "node:child_process";
2
2
  import { mkdtempSync, readFileSync, rmSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join, resolve } from "node:path";
5
- /**
6
- * The paths, when every difference between HEAD and the snapshot is only CRLF line endings on files
7
- * committed with LF; otherwise undefined.
8
- *
9
- * WHY (2026-11-06). On DentalPresence the pre-push hook could not verify any push: 268 files had been
10
- * checked out with CRLF under Git for Windows' system-wide `core.autocrlf=true` before the repository
11
- * set it to false. `git status` called the checkout clean because its stat cache still matched, while
12
- * the snapshot re-reads every file and saw 268 changes. Git's own view decides "clean" for the user, so
13
- * a CRLF-only checkout is verified rather than blocked, and the receipt names the files.
14
- */
15
- export function lineEndingOnlyChanges(repoPathInput, snapshot) {
16
- const repoPath = resolve(repoPathInput);
17
- const baseTreeSha = requireGit(repoPath, ["rev-parse", "--verify", `${snapshot.baseSha}^{tree}`], "could not resolve the snapshot base tree");
18
- const changes = snapshotChanges(repoPath, baseTreeSha, snapshot.treeSha);
19
- if (changes.length === 0 || changes.some((change) => change.status !== "modified"))
20
- return undefined;
21
- for (const change of changes) {
22
- const committed = spawnSync("git", ["cat-file", "blob", `${baseTreeSha}:${change.path}`], {
23
- cwd: repoPath,
24
- maxBuffer: 256 * 1024 * 1024,
25
- windowsHide: true,
26
- });
27
- if (committed.status !== 0 || committed.stdout.includes(13))
28
- return undefined;
29
- let checkedOut;
30
- try {
31
- checkedOut = readFileSync(join(repoPath, change.path));
32
- }
33
- catch {
34
- return undefined;
35
- }
36
- if (!checkedOut.includes(13))
37
- return undefined;
38
- const normalized = Buffer.from(checkedOut.toString("latin1").replace(/\r\n/g, "\n"), "latin1");
39
- if (!normalized.equals(committed.stdout))
40
- return undefined;
41
- }
42
- return changes.map((change) => change.path);
43
- }
44
5
  function runGit(repoPath, args, env, input) {
45
6
  const result = spawnSync("git", args, {
46
7
  cwd: repoPath,
@@ -64,6 +25,61 @@ function requireGit(repoPath, args, context, env, input) {
64
25
  }
65
26
  return result.stdout.trim();
66
27
  }
28
+ /**
29
+ * Files staged in the temporary index that differ from the base tree only because the checkout has CRLF
30
+ * where the commit has LF (2026-11-15). On diffci.com, 968 of 1,020 "changed" files were such checkouts
31
+ * next to 52 real changes. The earlier rule (2026-11-06, DentalPresence's pre-push hook) cleared them only
32
+ * when nothing else had changed, so the analysis
33
+ * resolved readers for every one, chose the full suite, and verify took 15 minutes. `git status` calls
34
+ * these files clean, and so does the snapshot now, whatever else changed; the receipt lists them.
35
+ */
36
+ function crlfCheckouts(repoPath, baseTreeSha, indexEnvironment) {
37
+ const modified = requireGit(repoPath, ["diff-index", "--cached", "--no-renames", "--diff-filter=M", "--name-only", "-z", baseTreeSha], "could not compare the working tree with HEAD", indexEnvironment)
38
+ .split("\0").filter(Boolean);
39
+ const candidates = [];
40
+ for (const path of modified) {
41
+ let checkedOut;
42
+ try {
43
+ checkedOut = readFileSync(join(repoPath, path));
44
+ }
45
+ catch {
46
+ continue;
47
+ }
48
+ if (!checkedOut.includes(13))
49
+ continue;
50
+ candidates.push({ path, normalized: Buffer.from(checkedOut.toString("latin1").replace(/\r\n/g, "\n"), "latin1") });
51
+ }
52
+ if (candidates.length === 0)
53
+ return [];
54
+ // One batch read of the committed blobs: `--batch` prints "<sha> blob <size>\n<bytes>\n" per object.
55
+ const batch = spawnSync("git", ["cat-file", "--batch"], {
56
+ cwd: repoPath,
57
+ input: candidates.map(({ path }) => `${baseTreeSha}:${path}\n`).join(""),
58
+ maxBuffer: 1024 * 1024 * 1024,
59
+ windowsHide: true,
60
+ });
61
+ if (batch.status !== 0)
62
+ return [];
63
+ const output = batch.stdout;
64
+ const found = [];
65
+ let offset = 0;
66
+ for (const { path, normalized } of candidates) {
67
+ const headerEnd = output.indexOf(10, offset);
68
+ if (headerEnd < 0)
69
+ break;
70
+ const header = output.subarray(offset, headerEnd).toString("utf8").split(" ");
71
+ if (header[1] !== "blob") {
72
+ offset = headerEnd + 1;
73
+ continue;
74
+ }
75
+ const size = Number(header[2]);
76
+ const committed = output.subarray(headerEnd + 1, headerEnd + 1 + size);
77
+ offset = headerEnd + 1 + size + 1;
78
+ if (!committed.includes(13) && normalized.equals(committed))
79
+ found.push(path);
80
+ }
81
+ return found;
82
+ }
67
83
  /**
68
84
  * Materialize the current worktree as a Git tree without changing the user's index or checkout.
69
85
  *
@@ -86,6 +102,10 @@ export function captureWorkingTreeSnapshot(repoPathInput) {
86
102
  try {
87
103
  requireGit(repoPath, ["read-tree", baseSha], "could not initialize the verification snapshot", indexEnvironment);
88
104
  requireGit(repoPath, ["add", "-A", "--", "."], "could not capture the working tree", indexEnvironment);
105
+ const lineEndingOnly = crlfCheckouts(repoPath, baseTreeSha, indexEnvironment);
106
+ if (lineEndingOnly.length > 0) {
107
+ requireGit(repoPath, ["reset", "-q", baseSha, "--pathspec-from-file=-", "--pathspec-file-nul"], "could not leave line-ending-only files out of the snapshot", indexEnvironment, `${lineEndingOnly.join("\0")}\0`);
108
+ }
89
109
  const treeSha = requireGit(repoPath, ["write-tree"], "could not write the verification tree", indexEnvironment);
90
110
  const identityEnvironment = {
91
111
  GIT_AUTHOR_NAME: "DiffCI",
@@ -96,7 +116,7 @@ export function captureWorkingTreeSnapshot(repoPathInput) {
96
116
  GIT_COMMITTER_DATE: "2000-01-01T00:00:00Z",
97
117
  };
98
118
  const commitSha = requireGit(repoPath, ["commit-tree", treeSha, "-p", baseSha], "could not create the verification snapshot", identityEnvironment, "DiffCI working tree snapshot\n");
99
- return { baseSha, treeSha, commitSha, changed: treeSha !== baseTreeSha };
119
+ return { baseSha, treeSha, commitSha, changed: treeSha !== baseTreeSha, ...(lineEndingOnly.length > 0 ? { lineEndingOnly } : {}) };
100
120
  }
101
121
  finally {
102
122
  rmSync(temporaryDirectory, { recursive: true, force: true });
@@ -15,11 +15,13 @@ Run it in any Git checkout with Node.js 22.5+. [What the output means](docs/usin
15
15
 
16
16
  If DiffCI saves you CI time, a ⭐ helps others find it.
17
17
 
18
- **On every pull request**, add one job beside your existing CI. Its job summary shows which tests the change affects and why, or that the full suite is needed and why. It runs no tests and skips or changes nothing:
18
+ **On every pull request, with no workflow file:** [install the DiffCI GitHub App](https://github.com/apps/diffci/installations/new). On each pull request of a public repository it posts one "DiffCI change impact" check listing the affected tests and why. The check is always neutral, so it never blocks a merge. The App reads code and Actions runs and its only write permission is that check run; it never skips tests or changes required checks. [Data handling](https://diffci.com/data-handling).
19
+
20
+ **Or in your own workflow** (including private repositories), add one job beside your existing CI. Its job summary shows which tests the change affects and why, or that the full suite is needed and why. It runs no tests and skips or changes nothing:
19
21
 
20
22
  ```yaml
21
23
  - uses: actions/checkout@v7
22
- - uses: DiffCI/core@v0.3.39
24
+ - uses: DiffCI/core@v0.3.46
23
25
  ```
24
26
 
25
27
  Add `with: comment: "true"` (and `pull-requests: write` on the job) and the same answer appears on the pull request itself, updated in place on each push:
@@ -41,6 +43,12 @@ Coding agents pass the narrow check they picked and miss wider breakage, then re
41
43
  - **When DiffCI could narrow the run, it selected 2.2% of test files**, cutting test time by 93%. None of those commits had a failing test, so this shows speed, not regression catching.
42
44
  - **DiffCI still fell back to the full suite on 58% of commits**, mostly because a config file or `package.json` changed. Narrowing those safely is the main open problem, and [a good place to contribute](#contributing).
43
45
 
46
+ **Check your own repository.** How many of its red pull request builds failed on checks the author could have run before pushing? This reads GitHub Actions history only, runs nothing, and needs a GitHub token ([method](docs/red-builds.md)):
47
+
48
+ ```sh
49
+ npx "@diffci.com/diffci@latest" red-builds owner/repo
50
+ ```
51
+
44
52
  ## MCP server
45
53
 
46
54
  This repository contains DiffCI's MCP server. It is implemented in
@@ -125,6 +133,11 @@ first, and fails within minutes when one breaks. It adds a job and skips
125
133
  nothing, so your full test job stays as it is
126
134
  ([example](examples/github-actions-fast-check.yml)).
127
135
 
136
+ Add `check-run: "true"` for a [merge gate](docs/github-action-observer.md#merge-gate):
137
+ a "DiffCI merge gate" check run that branch protection can require. It passes
138
+ when the affected tests passed, fails when they failed, stays neutral when
139
+ DiffCI is unsure, and names the AI coding agent that wrote the change.
140
+
128
141
  The [v0.3.10 corresponding source](https://github.com/DiffCI/core/tree/4c76be14cec37d94eb7df93922f3c29d202f4e65/packages/diffci-cli)
129
142
  remains publicly available at tagged Core commit `4c76be14` (`cli-v0.3.10-source`)
130
143
  while distribution migrates to the Core-native CLI package.
@@ -135,6 +148,19 @@ while distribution migrates to the Core-native CLI package.
135
148
 
136
149
  ![Recorded Cal.com sandbox comparison](docs/calcom-runtime-evidence.svg)
137
150
 
151
+ ### Case studies
152
+
153
+ Each study is a replay on real repositories, with its method, raw data and limitations on the linked page. None is a forecast for your repository.
154
+
155
+ | Study | Result |
156
+ |---|---|
157
+ | [Agent breakage replay](https://diffci.com/case-studies/agent-breakage-replay) | Every red CI commit in two agent-built repositories: 32 of 38 introduced breakages caught before push; about 70% of red commits only inherited a broken main |
158
+ | [LobeHub vs a Vitest planner](https://diffci.com/case-studies/lobehub) | 40 commits against the maintainers' own affected-test planner: same share of tests, no planner-picked test missed, 15 of 18 introduced failures caught before push |
159
+ | [Paperclip red builds](https://diffci.com/case-studies/paperclip) | 74 red PR builds classified job by job: 12 failed only on the PR's own pre-push checks (11 agent-written), about 15% of red runs |
160
+ | [Cal.com](https://diffci.com/case-studies/calcom) | Six real merges, executed and timed: 86–91.6% test-stage reduction, 44.2% at job level |
161
+ | [deepseek-harness](https://diffci.com/case-studies/deepseek-harness) | Five merges on a dirty baseline: 79.5–89.5% job-level reduction; one result withheld because the selection was not honored |
162
+ | [DiffCI's own CI](https://diffci.com/case-studies/diffci-own-ci) | Cost per job on ephemeral containers, and the bug our own green CI was hiding |
163
+
138
164
  [Star Core](https://github.com/DiffCI/core) · [Volunteer a pilot repository](https://diffci.com/#pilot) · [Find a first contribution](https://github.com/DiffCI/core/issues?q=is%3Aopen+label%3A%22good+first+issue%22).
139
165
  Watch → Custom → Releases and Discussions for benchmark results and support updates. [Public roadmap](docs/roadmap.md).
140
166
 
@@ -157,6 +183,8 @@ node dist/cli.js plan --repo /path/to/clean-checkout --base HEAD~1 --head HEAD
157
183
 
158
184
  The target must be a clean Git repository root checked out at `--head`. Fetch the base commit beforehand if using a shallow clone. JSON goes to stdout; analysis errors exit nonzero and recommend full CI. Core does not execute repository scripts, contact a DiffCI backend or send telemetry. Installation requires the npm registry.
159
185
 
186
+ The `diffci` CLI, the GitHub Action and the MCP server count runs with the repository name (host/owner/repo), never its content. `diffci telemetry --mode count-only` drops the name; `DO_NOT_TRACK=1` stops counting. Details: [usage counting](docs/telemetry.md).
187
+
160
188
  To evaluate the same command on pull requests without changing required jobs, copy the [advisory GitHub Actions example](examples/README.md).
161
189
 
162
190
  **Plans are advisory.** This release does not execute, skip or cancel CI jobs. `SKIP_CANDIDATE` is a candidate, not permission to bypass a check. Keep full CI authoritative while evaluating Core. Missing command synthesis, unsupported configuration and incomplete evidence must not be treated as an empty test suite. Static analysis is not proof that a test can safely be omitted.
@@ -248,14 +276,15 @@ Most open work is teaching DiffCI to narrow changes it currently treats as "run
248
276
  Thank you to everyone who has improved DiffCI:
249
277
 
250
278
  - <a href="https://github.com/KingEmma7"><img src="https://github.com/KingEmma7.png?size=80" width="40" height="40" alt="@KingEmma7"></a> **[Emmanuel Mawulolo Tagbor](https://github.com/KingEmma7)**: [`diffci check-plan`](docs/using-diffci.md#compare-a-plan-with-a-full-suite-junit-report) for comparing a saved plan with full-suite JUnit results ([#74](https://github.com/DiffCI/core/pull/74)), Yarn Classic lockfile narrowing ([#63](https://github.com/DiffCI/core/pull/63)), and follow-ups ([#67](https://github.com/DiffCI/core/pull/67), [#70](https://github.com/DiffCI/core/pull/70)).
251
- - <a href="https://github.com/FredApps"><img src="https://github.com/FredApps.png?size=80" width="40" height="40" alt="@FredApps"></a> **[@FredApps](https://github.com/FredApps)**: five safety fixes for runtime module dependencies, Maven module resources, runner suites, deleted assets and Go runtime inputs ([#32](https://github.com/DiffCI/core/pull/32)–[#36](https://github.com/DiffCI/core/pull/36)).
279
+ - <a href="https://github.com/FredApps"><img src="https://github.com/FredApps.png?size=80" width="40" height="40" alt="@FredApps"></a> **[@FredApps](https://github.com/FredApps)**, **[Area maintainer: Rust](CONTRIBUTING.md#contributor-tiers)**: Cargo package and test-target mapping, the foundation for [Rust support](https://github.com/DiffCI/core/issues/62) ([#91](https://github.com/DiffCI/core/pull/91)), and five safety fixes for runtime module dependencies, Maven module resources, runner suites, deleted assets and Go runtime inputs ([#32](https://github.com/DiffCI/core/pull/32)–[#36](https://github.com/DiffCI/core/pull/36)).
252
280
  - <a href="https://github.com/shounakjoshi88-a11y"><img src="https://github.com/shounakjoshi88-a11y.png?size=80" width="40" height="40" alt="@shounakjoshi88-a11y"></a> **[Shounak Joshi](https://github.com/shounakjoshi88-a11y)**: Go package-owned `testdata` selection, so a golden-file edit runs the owning package's tests instead of the full suite ([#85](https://github.com/DiffCI/core/pull/85)).
253
281
  - <a href="https://github.com/bfs2021"><img src="https://github.com/bfs2021.png?size=80" width="40" height="40" alt="@bfs2021"></a> **[@bfs2021](https://github.com/bfs2021)**: `bun.lock` and `npm-shrinkwrap.json` recognition in the lockfile signal ([#64](https://github.com/DiffCI/core/pull/64)).
254
- - <a href="https://github.com/sarankumar1325"><img src="https://github.com/sarankumar1325.png?size=80" width="40" height="40" alt="@sarankumar1325"></a> **[@sarankumar1325](https://github.com/sarankumar1325)**: `bun.lock` detection in CI inference ([#105](https://github.com/DiffCI/core/pull/105)), removal of dead config-file patterns with a test for every entry ([#106](https://github.com/DiffCI/core/pull/106)), a shared lockfile list so every lockfile invalidates the Vue analysis cache ([#107](https://github.com/DiffCI/core/pull/107)), a regression test for `vite.config`-only changes in Vitest projects ([#109](https://github.com/DiffCI/core/pull/109)), Go `replace` targets inside the repository modelled under root-module scope instead of forcing the full suite ([#110](https://github.com/DiffCI/core/pull/110)), a full run when only `babel.config.*` or `.babelrc*` changes, where these files used to select no tests ([#108](https://github.com/DiffCI/core/pull/108)), and the shared lockfile names in reference resolution, impact analysis and the lockfile-free dependency check, replacing three hand-written copies ([#118](https://github.com/DiffCI/core/pull/118)–[#120](https://github.com/DiffCI/core/pull/120)).
282
+ - <a href="https://github.com/sarankumar1325"><img src="https://github.com/sarankumar1325.png?size=80" width="40" height="40" alt="@sarankumar1325"></a> **[@sarankumar1325](https://github.com/sarankumar1325)**: `bun.lock` detection in CI inference ([#105](https://github.com/DiffCI/core/pull/105)), removal of dead config-file patterns with a test for every entry ([#106](https://github.com/DiffCI/core/pull/106)), a shared lockfile list so every lockfile invalidates the Vue analysis cache ([#107](https://github.com/DiffCI/core/pull/107)), a regression test for `vite.config`-only changes in Vitest projects ([#109](https://github.com/DiffCI/core/pull/109)), Go `replace` targets inside the repository modelled under root-module scope instead of forcing the full suite ([#110](https://github.com/DiffCI/core/pull/110)), a full run when only `babel.config.*` or `.babelrc*` changes, where these files used to select no tests ([#108](https://github.com/DiffCI/core/pull/108)), and the shared lockfile names in reference resolution, impact analysis and the lockfile-free dependency check, replacing three hand-written copies ([#118](https://github.com/DiffCI/core/pull/118)–[#120](https://github.com/DiffCI/core/pull/120)), and a full-suite fallback when a package's Jest, Vitest or Babel config changes ([#121](https://github.com/DiffCI/core/pull/121)).
255
283
  - <a href="https://github.com/robertwmccarty-caelum"><img src="https://github.com/robertwmccarty-caelum.png?size=80" width="40" height="40" alt="@robertwmccarty-caelum"></a> **[@robertwmccarty-caelum](https://github.com/robertwmccarty-caelum)**: the Vitest reporter/timeout config fixture and its narrowing conditions ([#53](https://github.com/DiffCI/core/issues/53#issuecomment-6514436312), landed in [#65](https://github.com/DiffCI/core/pull/65)).
256
284
  - <a href="https://github.com/varshith84"><img src="https://github.com/varshith84.png?size=80" width="40" height="40" alt="@varshith84"></a> **[Varshith Sai Pasupuleti](https://github.com/varshith84)**: tests for transitive Vue selection and full fallback ([#16](https://github.com/DiffCI/core/pull/16)).
285
+ - <a href="https://github.com/aniKet0753"><img src="https://github.com/aniKet0753.png?size=80" width="40" height="40" alt="@aniKet0753"></a> **[@aniKet0753](https://github.com/aniKet0753)**: a `diffci help` command list and `USAGE` text that match the commands the CLI runs, with a test that fails when a command is missing ([#130](https://github.com/DiffCI/core/pull/130)).
257
286
 
258
- Every merged contribution is credited in the release notes, here, and next to the feature in the docs.
287
+ Every merged contribution is credited in the release notes, here, on [diffci.com/contributors](https://diffci.com/contributors), and next to the feature in the docs. The README and website entries are added automatically when a pull request merges. A [contributor tier](CONTRIBUTING.md#contributor-tiers) above Contributor is written after the name, as in **[Area maintainer: Rust](CONTRIBUTING.md#contributor-tiers)**, and diffci.com copies it from here.
259
288
 
260
289
  ## License
261
290
 
@@ -0,0 +1,23 @@
1
+ import { type AdapterContext, type AdapterContribution, type RepositoryAdapter } from "./types.js";
2
+ export interface CargoTarget {
3
+ name: string;
4
+ kind: string[];
5
+ src_path: string;
6
+ test: boolean;
7
+ doctest: boolean;
8
+ }
9
+ export interface CargoPackage {
10
+ id: string;
11
+ name: string;
12
+ manifest_path: string;
13
+ targets: CargoTarget[];
14
+ }
15
+ export interface CargoMetadata {
16
+ packages: CargoPackage[];
17
+ workspace_members: string[];
18
+ workspace_root: string;
19
+ }
20
+ /** Metadata is external input: incomplete output is not an empty successful graph. */
21
+ export declare function parseCargoMetadata(output: string): CargoMetadata;
22
+ export declare function analyzeRustMetadata(context: AdapterContext, output: string): AdapterContribution;
23
+ export declare const rustAdapter: RepositoryAdapter;