@diffci.com/diffci 0.3.53 → 0.3.55

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 (130) hide show
  1. package/dist-client/src/client/agent-selection.d.ts +81 -1
  2. package/dist-client/src/client/agent-selection.js +107 -4
  3. package/dist-client/src/client/agent-setup.js +1 -1
  4. package/dist-client/src/client/cli.js +140 -18
  5. package/dist-client/src/client/command-batches.js +3 -2
  6. package/dist-client/src/client/context.js +32 -2
  7. package/dist-client/src/client/coverage-map.js +6 -1
  8. package/dist-client/src/client/full-command.js +19 -14
  9. package/dist-client/src/client/hook.d.ts +17 -0
  10. package/dist-client/src/client/hook.js +53 -1
  11. package/dist-client/src/client/install.d.ts +6 -0
  12. package/dist-client/src/client/install.js +30 -1
  13. package/dist-client/src/client/isolated-worktree.d.ts +31 -0
  14. package/dist-client/src/client/isolated-worktree.js +130 -0
  15. package/dist-client/src/client/mcp.js +23 -4
  16. package/dist-client/src/client/observe.d.ts +2 -0
  17. package/dist-client/src/client/observe.js +7 -2
  18. package/dist-client/src/client/report.d.ts +1 -1
  19. package/dist-client/src/client/shared-graph-cache.js +4 -2
  20. package/dist-client/src/client/telemetry.js +2 -1
  21. package/dist-client/src/client/usage-signal.d.ts +1 -1
  22. package/dist-client/src/client/verify-savings.d.ts +6 -0
  23. package/dist-client/src/client/verify-savings.js +15 -3
  24. package/dist-client/src/client/verify.d.ts +47 -3
  25. package/dist-client/src/client/verify.js +244 -22
  26. package/dist-client/src/client/working-tree.d.ts +22 -0
  27. package/dist-client/src/client/working-tree.js +45 -6
  28. package/node_modules/@diffci.com/core/README.md +17 -10
  29. package/node_modules/@diffci.com/core/dist/ci-inference/expression.d.ts +5 -0
  30. package/node_modules/@diffci.com/core/dist/ci-inference/expression.js +38 -5
  31. package/node_modules/@diffci.com/core/dist/ci-inference/expression.js.map +1 -1
  32. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +26 -6
  33. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
  34. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.d.ts +2 -1
  35. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +7 -2
  36. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
  37. package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js +15 -8
  38. package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js.map +1 -1
  39. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +6 -2
  40. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
  41. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +19 -4
  42. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
  43. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +13 -1
  44. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -1
  45. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +5 -0
  46. package/node_modules/@diffci.com/core/dist/git/git-diff.js +22 -20
  47. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  48. package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +22 -1
  49. package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -1
  50. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +6 -0
  51. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +14 -2
  52. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -1
  53. package/node_modules/@diffci.com/core/dist/planner/planner.js +65 -14
  54. package/node_modules/@diffci.com/core/dist/planner/planner.js.map +1 -1
  55. package/node_modules/@diffci.com/core/dist/planner/rust-command.js +43 -1
  56. package/node_modules/@diffci.com/core/dist/planner/rust-command.js.map +1 -1
  57. package/node_modules/@diffci.com/core/dist/planner/script-reads.js +5 -2
  58. package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -1
  59. package/node_modules/@diffci.com/core/dist/planner/test-command.js +17 -2
  60. package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
  61. package/node_modules/@diffci.com/core/dist/planner/type-program.js +27 -1
  62. package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -1
  63. package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +5 -1
  64. package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
  65. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +21 -2
  66. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
  67. package/node_modules/@diffci.com/core/dist/repo/adapters/python.d.ts +9 -1
  68. package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +158 -14
  69. package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
  70. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.d.ts +1 -0
  71. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +180 -15
  72. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
  73. package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +7 -0
  74. package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
  75. package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +16 -0
  76. package/node_modules/@diffci.com/core/dist/repo/file-references.js +76 -5
  77. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
  78. package/node_modules/@diffci.com/core/dist/repo/graph.js +100 -29
  79. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  80. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +7 -0
  81. package/node_modules/@diffci.com/core/dist/repo/impact.js +55 -8
  82. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  83. package/node_modules/@diffci.com/core/dist/repo/layout.js +4 -1
  84. package/node_modules/@diffci.com/core/dist/repo/layout.js.map +1 -1
  85. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +10 -1
  86. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
  87. package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
  88. package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
  89. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +5 -1
  90. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
  91. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +3 -0
  92. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +3 -3
  93. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
  94. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +65 -13
  95. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
  96. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +47 -2
  97. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
  98. package/node_modules/@diffci.com/core/package.json +1 -0
  99. package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +38 -5
  100. package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +21 -6
  101. package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +7 -2
  102. package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +15 -8
  103. package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +6 -2
  104. package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +18 -4
  105. package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +8 -1
  106. package/node_modules/@diffci.com/core/src/git/git-diff.ts +20 -21
  107. package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +22 -1
  108. package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +13 -2
  109. package/node_modules/@diffci.com/core/src/planner/planner.ts +42 -14
  110. package/node_modules/@diffci.com/core/src/planner/rust-command.ts +37 -1
  111. package/node_modules/@diffci.com/core/src/planner/script-reads.ts +5 -1
  112. package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -2
  113. package/node_modules/@diffci.com/core/src/planner/type-program.ts +25 -1
  114. package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +5 -1
  115. package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +20 -2
  116. package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +133 -14
  117. package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +136 -16
  118. package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +7 -1
  119. package/node_modules/@diffci.com/core/src/repo/file-references.ts +70 -5
  120. package/node_modules/@diffci.com/core/src/repo/graph.ts +81 -20
  121. package/node_modules/@diffci.com/core/src/repo/impact.ts +56 -7
  122. package/node_modules/@diffci.com/core/src/repo/layout.ts +5 -1
  123. package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +11 -1
  124. package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
  125. package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +4 -1
  126. package/node_modules/@diffci.com/core/src/repo/types.ts +3 -1
  127. package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +3 -3
  128. package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +43 -13
  129. package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +44 -2
  130. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ import { type VerificationTreeScope } from "./working-tree.js";
1
2
  /** Cheap change discovery, without building the dependency graph. */
2
3
  export declare function agentChangedFiles(repoInput: string): {
3
4
  schema: string;
@@ -47,9 +48,88 @@ export declare function agentSelection(repoInput: string): Promise<{
47
48
  tests_selected: number;
48
49
  command: string | undefined;
49
50
  }>;
51
+ /**
52
+ * A path as one shell word in POSIX shells, cmd.exe and PowerShell, or undefined when no quoting is
53
+ * literal in all three. Inside double quotes `$` and backticks still expand (POSIX, PowerShell), `%` and
54
+ * `!` expand in cmd.exe, and `\` and `"` cannot be escaped the same way in each. The agent runs this
55
+ * command as written, so a repository file named `$(…).ts` must never reach it (CodeQL alert 36).
56
+ */
57
+ export declare function shellPath(path: string): string | undefined;
58
+ /** The one command that verifies `scope` in isolation, as `diffci_select_tests` returns it, or undefined when a path cannot be quoted safely. */
59
+ export declare function scopedVerifyCommand(repoPath: string, scope: VerificationTreeScope, version?: string): string | undefined;
60
+ /**
61
+ * The plan for HEAD plus only the staged files, or only the named files (2026-11-17), made in the same
62
+ * temporary worktree `verify --staged` / `--paths` verifies in. Its `command` is that one verify
63
+ * command, which runs the gate checks and the selected tests in isolation: the selected test command
64
+ * itself would run in the shared checkout, where other sessions' files could change its result.
65
+ */
66
+ export declare function agentScopedSelection(repoInput: string, scope: VerificationTreeScope): Promise<{
67
+ status: "blocked" | "planned";
68
+ tests_executed: boolean;
69
+ snapshot: {
70
+ base_sha: string;
71
+ tree_sha: string;
72
+ unchanged: boolean;
73
+ };
74
+ changed_files: string[];
75
+ selection: "none";
76
+ selected_tests: string[];
77
+ tests_available: number;
78
+ tests_selected: number;
79
+ command: undefined;
80
+ checks: never[];
81
+ skipped_checks: never[];
82
+ reason: string;
83
+ fallback_reasons: never[];
84
+ analysis_status: string;
85
+ risk_signals: never[];
86
+ required_ci_authoritative: boolean;
87
+ scope: "paths" | "staged";
88
+ isolation: "temporary-worktree";
89
+ excluded_dirty_files: number;
90
+ excluded_dirty_paths: string[];
91
+ schema: string;
92
+ } | {
93
+ command: string | undefined;
94
+ commands: undefined;
95
+ reason: string;
96
+ worktree_command?: string | undefined;
97
+ status: string;
98
+ snapshot: {
99
+ base_sha: string;
100
+ tree_sha: string;
101
+ unchanged: boolean;
102
+ };
103
+ changed_files: string[];
104
+ scope: "paths" | "staged";
105
+ isolation: "temporary-worktree";
106
+ excluded_dirty_files: number;
107
+ excluded_dirty_paths: string[];
108
+ checks: import("./gate-checks.js").PlannedCheck[];
109
+ skipped_checks: {
110
+ id: string;
111
+ reason: string;
112
+ }[];
113
+ fallback_reasons: string[];
114
+ analysis_status: string;
115
+ analysis_mode: "SELECTIVE" | "FULL" | undefined;
116
+ graph_confidence: string | undefined;
117
+ risk_signals: {
118
+ level: string;
119
+ reason: string;
120
+ }[];
121
+ required_ci_authoritative: boolean;
122
+ schema: string;
123
+ tests_executed: boolean;
124
+ selection: "none" | "full" | "selected";
125
+ selected_tests: string[];
126
+ tests_available: number;
127
+ tests_selected: number;
128
+ }>;
129
+ export type AgentScopedSelectionPlan = Awaited<ReturnType<typeof agentScopedSelection>>;
50
130
  /**
51
131
  * One plain sentence ahead of the JSON, naming the exact command to run (2026-10-28). Agents given only
52
132
  * the JSON plan mostly went on to pick their own test files or run the whole suite; the first line is
53
133
  * what they act on, so it says what to run and nothing else.
54
134
  */
55
- export declare function selectionInstruction(plan: AgentSelectionPlan): string;
135
+ export declare function selectionInstruction(plan: AgentSelectionPlan | AgentScopedSelectionPlan): string;
@@ -1,11 +1,17 @@
1
1
  import { execFileSync } from "node:child_process";
2
- import { resolve } from "node:path";
2
+ import { readFileSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
3
4
  import { observe } from "./observe.js";
4
5
  import { plannedChecks } from "./gate-checks.js";
5
- import { executableSelection } from "./verify.js";
6
- import { captureWorkingTreeSnapshot } from "./working-tree.js";
6
+ import { hookCommand } from "./hook.js";
7
+ import { detectPackageManager } from "./install.js";
8
+ import { createIsolatedWorktree } from "./isolated-worktree.js";
9
+ import { requireDiffciPackageIdentity } from "./package-identity.js";
10
+ import { executableSelection, scopedChanges } from "./verify.js";
11
+ import { captureScopedTree, captureWorkingTreeSnapshot } from "./working-tree.js";
12
+ /** A rename is its old path and its new one: whatever imported the old path is affected too. */
7
13
  function changedPaths(repoPath, snapshot) {
8
- return execFileSync("git", ["diff", "--name-only", "-z", snapshot.baseSha, snapshot.commitSha], {
14
+ return execFileSync("git", ["diff", "--name-only", "--no-renames", "-z", snapshot.baseSha, snapshot.commitSha], {
9
15
  cwd: repoPath, encoding: "utf8", windowsHide: true,
10
16
  }).split("\0").filter(Boolean);
11
17
  }
@@ -76,6 +82,96 @@ export async function agentSelection(repoInput) {
76
82
  required_ci_authoritative: true,
77
83
  };
78
84
  }
85
+ /** How this repository runs DiffCI from a shell: its installed binary, or a pinned npx package. */
86
+ function diffciInvocation(repoPath, version) {
87
+ let declared = false;
88
+ try {
89
+ const manifest = JSON.parse(readFileSync(join(repoPath, "package.json"), "utf8"));
90
+ declared = ["dependencies", "devDependencies", "optionalDependencies"].some((field) => Boolean(manifest[field]?.["@diffci.com/diffci"]));
91
+ }
92
+ catch { /* no package.json: the pinned package below */ }
93
+ if (!declared)
94
+ return hookCommand(undefined, version);
95
+ try {
96
+ return hookCommand(detectPackageManager(repoPath), version);
97
+ }
98
+ catch {
99
+ return hookCommand("npm", version);
100
+ }
101
+ }
102
+ /**
103
+ * A path as one shell word in POSIX shells, cmd.exe and PowerShell, or undefined when no quoting is
104
+ * literal in all three. Inside double quotes `$` and backticks still expand (POSIX, PowerShell), `%` and
105
+ * `!` expand in cmd.exe, and `\` and `"` cannot be escaped the same way in each. The agent runs this
106
+ * command as written, so a repository file named `$(…).ts` must never reach it (CodeQL alert 36).
107
+ */
108
+ export function shellPath(path) {
109
+ if (/^[A-Za-z0-9_./@+-]+$/.test(path))
110
+ return path;
111
+ return /[$`"\\%!\0-\x1f\x7f]/.test(path) ? undefined : `"${path}"`;
112
+ }
113
+ /** The one command that verifies `scope` in isolation, as `diffci_select_tests` returns it, or undefined when a path cannot be quoted safely. */
114
+ export function scopedVerifyCommand(repoPath, scope, version = requireDiffciPackageIdentity().version) {
115
+ const run = diffciInvocation(repoPath, version);
116
+ if (scope.kind === "staged")
117
+ return `${run} verify --staged --json`;
118
+ const words = scope.paths.map(shellPath);
119
+ return words.every((word) => word !== undefined) ? `${run} verify --json --paths ${words.join(" ")}` : undefined;
120
+ }
121
+ const UNQUOTABLE_PATH = "a path contains a character no shell quoting keeps literal ($ ` \" \\ % ! or a control character), so DiffCI returns no command to paste; stage the files and use scope \"staged\", or run `diffci verify --paths` with the path quoted for your shell";
122
+ /**
123
+ * The plan for HEAD plus only the staged files, or only the named files (2026-11-17), made in the same
124
+ * temporary worktree `verify --staged` / `--paths` verifies in. Its `command` is that one verify
125
+ * command, which runs the gate checks and the selected tests in isolation: the selected test command
126
+ * itself would run in the shared checkout, where other sessions' files could change its result.
127
+ */
128
+ export async function agentScopedSelection(repoInput, scope) {
129
+ const repoPath = resolve(repoInput);
130
+ const { scoped, verified, excluded } = scopedChanges(repoPath, scope);
131
+ const scopeFields = {
132
+ scope: scope.kind,
133
+ isolation: "temporary-worktree",
134
+ excluded_dirty_files: excluded.length,
135
+ excluded_dirty_paths: excluded.slice(0, 50).map((change) => change.path),
136
+ };
137
+ const command = scopedVerifyCommand(repoPath, scope);
138
+ const unplanned = (status, reason) => ({
139
+ schema: "diffci.agent-selection.v1", ...scopeFields, status, tests_executed: false,
140
+ snapshot: { base_sha: scoped.baseSha, tree_sha: scoped.treeSha, unchanged: true },
141
+ changed_files: verified.map((change) => change.path), selection: "none", selected_tests: [],
142
+ tests_available: 0, tests_selected: 0, command: undefined, checks: [], skipped_checks: [], reason,
143
+ fallback_reasons: [], analysis_status: "not_needed", risk_signals: [], required_ci_authoritative: true,
144
+ });
145
+ if (!scoped.changed)
146
+ return unplanned("planned", scope.kind === "staged" ? "nothing is staged: the index matches HEAD" : "the given paths do not differ from HEAD");
147
+ if (command === undefined)
148
+ return unplanned("blocked", UNQUOTABLE_PATH);
149
+ const worktree = createIsolatedWorktree(repoPath, scoped.baseSha, scoped.treeSha);
150
+ if ("error" in worktree)
151
+ return unplanned("blocked", worktree.error);
152
+ let plan;
153
+ try {
154
+ plan = await agentSelection(worktree.path);
155
+ }
156
+ finally {
157
+ worktree.dispose();
158
+ }
159
+ const after = captureScopedTree(repoPath, scope);
160
+ const unchanged = plan.snapshot.unchanged && after.baseSha === scoped.baseSha && after.treeSha === scoped.treeSha;
161
+ const ready = unchanged && plan.status === "planned";
162
+ return {
163
+ ...plan,
164
+ ...scopeFields,
165
+ status: ready ? "planned" : "blocked",
166
+ snapshot: { base_sha: scoped.baseSha, tree_sha: scoped.treeSha, unchanged },
167
+ changed_files: verified.map((change) => change.path),
168
+ // What the verify command runs inside the temporary worktree, for reading, not for running here.
169
+ ...(plan.command ? { worktree_command: plan.command } : {}),
170
+ command: ready ? command : undefined,
171
+ commands: undefined,
172
+ reason: unchanged ? plan.reason : `the ${scope.kind === "staged" ? "index" : "given files"} or HEAD changed during analysis; reanalyze`,
173
+ };
174
+ }
79
175
  /**
80
176
  * One plain sentence ahead of the JSON, naming the exact command to run (2026-10-28). Agents given only
81
177
  * the JSON plan mostly went on to pick their own test files or run the whole suite; the first line is
@@ -89,6 +185,13 @@ export function selectionInstruction(plan) {
89
185
  const scope = plan.selection === "selected"
90
186
  ? `DiffCI selected ${plan.tests_selected} of ${plan.tests_available} test files`
91
187
  : `DiffCI requires the full suite (${plan.reason})`;
188
+ if ("isolation" in plan) {
189
+ // One command: it runs the gate checks and the tests in the temporary worktree, where only the
190
+ // scoped files differ from HEAD.
191
+ const what = plan.scope === "staged" ? "HEAD plus your staged files" : "HEAD plus the given files";
192
+ const excluded = plan.excluded_dirty_files ? ` ${plan.excluded_dirty_files} other changed file(s) in this checkout are excluded and stay at their HEAD version.` : "";
193
+ return `${scope} for ${what}.${excluded} Run exactly:\n${plan.command}\nIt runs the gate checks and those tests in a temporary worktree. Do not run the selected tests in this checkout, substitute your own test files, or run the full suite.`;
194
+ }
92
195
  const testCommands = plan.commands && plan.commands.length > 1 ? plan.commands : [plan.command];
93
196
  const all = [...plan.checks.map((check) => check.command), ...testCommands];
94
197
  const skipped = plan.skipped_checks?.length ? ` ${plan.skipped_checks.length} other gate check(s) are not affected by this change.` : "";
@@ -54,7 +54,7 @@ export function mcpServerEntry(version) {
54
54
  command: "node",
55
55
  args: [
56
56
  "-e",
57
- `const { spawn } = require('node:child_process'); const npxArgs = ['--yes', '--package', '@diffci.com/diffci@${version}', 'diffci-mcp']; const child = process.platform === 'win32' ? spawn(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', 'npx', ...npxArgs], { stdio: 'inherit' }); child.once('error', (error) => { console.error('Failed to launch DiffCI MCP:', error.message); process.exit(1); }); child.once('exit', (code, signal) => process.exit(code ?? (signal ? 1 : 0)));`,
57
+ `const { spawn } = require('node:child_process'); const npxArgs = ['--yes', '--package', '@diffci.com/diffci@${version}', 'diffci-mcp']; const child = process.platform === 'win32' ? spawn(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', 'npx', ...npxArgs], { stdio: 'inherit' }) : spawn('npx', npxArgs, { stdio: 'inherit' }); child.once('error', (error) => { console.error('Failed to launch DiffCI MCP:', error.message); process.exit(1); }); child.once('exit', (code, signal) => process.exit(code ?? (signal ? 1 : 0)));`,
58
58
  ],
59
59
  };
60
60
  }
@@ -41,12 +41,12 @@
41
41
  import { execFileSync, spawnSync } from "node:child_process";
42
42
  import { closeSync, constants, existsSync, fstatSync, mkdirSync, openSync, readFileSync, readSync, writeFileSync } from "node:fs";
43
43
  import { tmpdir } from "node:os";
44
- import { basename, dirname, join, resolve } from "node:path";
44
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
45
45
  import { observe, isInsideRepository } from "./observe.js";
46
46
  import { resolveObservationAgent } from "./agent-identity.js";
47
47
  import { inferFullCommand, inferComparableSelectedCommand, inferWorkspaceComparison } from "./full-command.js";
48
48
  import { addDiffciPackageScripts, detectPackageManager, installDiffci } from "./install.js";
49
- import { hookCommand, installPrePushHook, isGitRepository } from "./hook.js";
49
+ import { hookCommand, installPrePushHook, isGitRepository, refreshPrePushHook } from "./hook.js";
50
50
  import { AGENT_HOOK_TIMEOUT_SECONDS, ignoredWrites, MCP_CONFIG_PATHS, SKILL_PATHS, writeAgentStopHook, writeMcpConfig, writeSkill } from "./agent-setup.js";
51
51
  import { submitObservation } from "./submit.js";
52
52
  import { configureGraphCache } from "./shared-graph-cache.js";
@@ -56,7 +56,7 @@ import { formatJobSummary } from "./job-summary.js";
56
56
  import { configureTelemetry, readTelemetryPreference, recordUsage, telemetryNotice } from "./telemetry.js";
57
57
  import { formatFeedbackPrompt, markFeedbackPromptShown, shouldShowFeedbackPrompt } from "./feedback-prompt.js";
58
58
  import { detectSpecificationConflicts, readSpecificationFile } from "./spec-conflicts.js";
59
- import { formatVerificationSummary, verificationExitCode, verifyChanged, verifyRange } from "./verify.js";
59
+ import { formatVerificationSummary, verificationExitCode, verifyChanged, verifyRange, verifyScoped } from "./verify.js";
60
60
  import { startWatch } from "./watch.js";
61
61
  import { captureWorkingTreeSnapshot } from "./working-tree.js";
62
62
  import { decideStop, HOOK_AGENTS, maxAttempts, parseStopPayload, sessionAttempts, stopRepoPath } from "./agent-stop.js";
@@ -86,6 +86,15 @@ function parseArgs(argv) {
86
86
  }
87
87
  const key = token.slice(2);
88
88
  const next = args[i + 1];
89
+ if (key === "paths") {
90
+ // `--paths a b c` takes every value up to the next flag, and repeats add to it; NUL separates
91
+ // them because no path contains one.
92
+ const values = typeof flags.paths === "string" ? flags.paths.split("\0") : [];
93
+ while (args[i + 1] !== undefined && !args[i + 1].startsWith("--"))
94
+ values.push(args[++i]);
95
+ flags.paths = values.length ? values.join("\0") : true;
96
+ continue;
97
+ }
89
98
  if (next !== undefined && !next.startsWith("--")) {
90
99
  flags[key] = next;
91
100
  i++;
@@ -216,6 +225,12 @@ function defaultReportPath(env) {
216
225
  // Quoting the scoped package keeps the same command valid in POSIX shells, cmd.exe, and
217
226
  // PowerShell, where an unquoted leading `@` is parsed as the splatting operator.
218
227
  const PUBLIC_AGENT_DEFAULT_COMMAND = 'npx "@diffci.com/diffci@latest" verify --changed --json';
228
+ /** The pre-commit form of the agent command: the `diffci:verify:staged` script, or `--staged` in place of `--changed`. */
229
+ function stagedCommand(command) {
230
+ if (/ run diffci:verify$/.test(command))
231
+ return `${command}:staged`;
232
+ return command.replace("--changed", "--staged");
233
+ }
219
234
  function agentInstructions(command) {
220
235
  return `# DiffCI Agent Instructions
221
236
 
@@ -233,6 +248,14 @@ Use it instead of choosing test files yourself and instead of re-running the ful
233
248
  - Do not run the full test suite to be safe. DiffCI already falls back to the full suite when it cannot prove a smaller set is enough, and says why in \`reason\`.
234
249
  - When the MCP server is available, \`diffci_select_tests\` returns the one exact \`command\` to run; run that command as given.
235
250
 
251
+ Before a commit, verify what you will commit. Stage your own files by path (\`git add -- <your files>\`), then run:
252
+
253
+ \`\`\`bash
254
+ ${stagedCommand(command)}
255
+ \`\`\`
256
+
257
+ It verifies HEAD plus the staged files only, in a temporary worktree, so other uncommitted work in this checkout (another agent session's, for example) can neither fail nor pass your commit; the receipt lists those files under \`scoped.excluded_dirty_paths\`. \`diffci verify --paths <file...>\` does the same for named files without staging them; pair it with \`git commit -- <file...>\`. With MCP: \`diffci_select_tests\` with \`scope: "staged"\` (or \`scope: "paths"\` and \`paths\`) returns the one command to run.
258
+
236
259
  What this does:
237
260
 
238
261
  - snapshots staged, unstaged, and non-ignored untracked changes;
@@ -570,8 +593,12 @@ ${formatVerificationSummary(report)}`;
570
593
  }
571
594
  async function runVerifyCommand(flags, env) {
572
595
  const changed = flags.changed === true;
573
- if (changed && (flags.base !== undefined || flags.head !== undefined)) {
574
- console.error("diffci verify accepts either --changed or --base/--head, not both");
596
+ const staged = flags.staged === true;
597
+ const scopedPaths = flags.paths !== undefined || flags["paths-from"] !== undefined;
598
+ const range = flags.base !== undefined || flags.head !== undefined;
599
+ const modes = [changed && "--changed", staged && "--staged", scopedPaths && "--paths", range && "--base/--head"].filter(Boolean);
600
+ if (modes.length > 1) {
601
+ console.error(`diffci verify accepts one of --changed, --staged, --paths/--paths-from or --base/--head; got ${modes.join(" and ")}`);
575
602
  return 2;
576
603
  }
577
604
  const policy = flags.policy === true ? "" : stringFlag(flags, "policy");
@@ -579,11 +606,20 @@ async function runVerifyCommand(flags, env) {
579
606
  console.error(`diffci verify --policy accepts only "enforce", got ${JSON.stringify(policy)}`);
580
607
  return 2;
581
608
  }
582
- if (policy !== undefined && changed) {
583
- console.error("diffci verify --policy enforce applies to a commit range, not --changed");
609
+ if (policy !== undefined && (changed || staged || scopedPaths)) {
610
+ console.error(`diffci verify --policy enforce applies to a commit range, not ${modes[0]}`);
584
611
  return 2;
585
612
  }
586
613
  const repoPath = resolve(stringFlag(flags, "repo") ?? env.GITHUB_WORKSPACE ?? process.cwd());
614
+ let paths;
615
+ if (scopedPaths) {
616
+ const read = await scopedPathArguments(flags, repoPath);
617
+ if ("error" in read) {
618
+ console.error(`diffci verify: ${read.error}`);
619
+ return 2;
620
+ }
621
+ paths = read.paths;
622
+ }
587
623
  const out = stringFlag(flags, "out");
588
624
  const reportPath = out ? resolve(out) : undefined;
589
625
  if (reportPath && (reportPath === repoPath || isInsideRepository(repoPath, reportPath))) {
@@ -632,12 +668,31 @@ async function runVerifyCommand(flags, env) {
632
668
  };
633
669
  const report = changed
634
670
  ? await verifyChanged(common)
635
- : await verifyRange({
636
- ...common,
637
- baseOverride: stringFlag(flags, "base"),
638
- headOverride: stringFlag(flags, "head"),
639
- policy,
640
- });
671
+ : staged
672
+ ? await verifyScoped({ ...common, scope: { kind: "staged" } })
673
+ : paths
674
+ ? await verifyScoped({ ...common, scope: { kind: "paths", paths } })
675
+ : await verifyRange({
676
+ ...common,
677
+ baseOverride: stringFlag(flags, "base"),
678
+ headOverride: stringFlag(flags, "head"),
679
+ policy,
680
+ });
681
+ if (changed) {
682
+ const outside = filesOutsideIndex(repoPath);
683
+ if (outside > 0) {
684
+ console.error(`diffci: ${outside} changed file(s) here are not staged and were verified too. If other sessions share this checkout, stage your own files and run \`diffci verify --staged\` (or \`diffci verify --paths <file...>\`) to verify HEAD plus only those, in a temporary worktree.`);
685
+ }
686
+ }
687
+ // Never from the hook's own `verify --base/--head`, and never in CI, where no hook is installed.
688
+ if ((changed || staged || paths) && env.DIFFCI_HOOK_REFRESH !== "0" && !(Boolean(env.CI) && env.CI !== "false")) {
689
+ try {
690
+ const refreshed = refreshPrePushHook(repoPath);
691
+ if (refreshed)
692
+ console.error(refreshed);
693
+ }
694
+ catch { /* keeping an old hook never fails verification */ }
695
+ }
641
696
  await recordUsage("verify", report.verification, identity.version, flags, env, repoPath);
642
697
  if (flags["no-log"] !== true)
643
698
  appendOutcome(repoPath, report, env);
@@ -654,6 +709,66 @@ async function runVerifyCommand(flags, env) {
654
709
  }
655
710
  return verificationExitCode(report);
656
711
  }
712
+ /** Unstaged or untracked (non-ignored) files, for the `--changed` hint. Zero when Git cannot say. */
713
+ function filesOutsideIndex(repoPath) {
714
+ const status = spawnSync("git", ["status", "--porcelain", "-z", "--untracked-files=all"], { cwd: repoPath, encoding: "utf8", windowsHide: true, maxBuffer: 64 * 1024 * 1024 });
715
+ if (status.status !== 0)
716
+ return 0;
717
+ const entries = (status.stdout ?? "").split("\0");
718
+ let count = 0;
719
+ for (let i = 0; i < entries.length; i++) {
720
+ const entry = entries[i];
721
+ if (entry.length < 4)
722
+ continue;
723
+ if (entry.startsWith("??") || entry[1] !== " ")
724
+ count++;
725
+ // A rename's source path follows as its own field.
726
+ if (entry[0] === "R" || entry[0] === "C")
727
+ i++;
728
+ }
729
+ return count;
730
+ }
731
+ /**
732
+ * The paths for `--paths a b` and `--paths-from <file|->` (one per line, or NUL-separated), as
733
+ * repository-relative paths. Relative paths are read from the current directory when it is inside the
734
+ * repository, as Git reads them, and from the repository root otherwise.
735
+ */
736
+ async function scopedPathArguments(flags, repoPath) {
737
+ const given = [];
738
+ if (flags.paths === true)
739
+ return { error: "--paths needs at least one file" };
740
+ if (typeof flags.paths === "string")
741
+ given.push(...flags.paths.split("\0"));
742
+ const from = flags["paths-from"];
743
+ if (from === true)
744
+ return { error: "--paths-from needs a file, or - for standard input" };
745
+ if (typeof from === "string") {
746
+ let text;
747
+ try {
748
+ text = from === "-" ? await readStdin() : readFileSync(resolve(from), "utf8");
749
+ }
750
+ catch (error) {
751
+ return { error: `could not read --paths-from ${from}: ${error instanceof Error ? error.message : String(error)}` };
752
+ }
753
+ given.push(...text.split(/\0|\r?\n/));
754
+ }
755
+ const cwd = process.cwd();
756
+ const root = isInsideRepository(repoPath, cwd) || resolve(cwd) === repoPath ? cwd : repoPath;
757
+ const paths = [];
758
+ for (const raw of given) {
759
+ const path = raw.trim();
760
+ if (!path)
761
+ continue;
762
+ const absolute = resolve(root, path);
763
+ const rel = relative(repoPath, absolute);
764
+ if (rel === "" || rel.startsWith("..") || isAbsolute(rel))
765
+ return { error: `${path} is not a file inside ${repoPath}` };
766
+ paths.push(rel.split(sep).join("/"));
767
+ }
768
+ if (paths.length === 0)
769
+ return { error: "--paths/--paths-from named no files" };
770
+ return { paths: [...new Set(paths)] };
771
+ }
657
772
  function runCoverageCommand(flags, env) {
658
773
  const repoPath = resolve(stringFlag(flags, "repo") ?? env.GITHUB_WORKSPACE ?? process.cwd());
659
774
  const command = stringFlag(flags, "command") ?? inferFullCommand(repoPath).command;
@@ -1424,13 +1539,14 @@ Usage:
1424
1539
  diffci watch [--repo <path>] [--checks] [--debounce-ms <ms>] [--no-log]
1425
1540
  diffci agent-stop --agent claude|codex|cursor|copilot (run by the agent stop hooks init installs; reads the hook JSON on stdin)
1426
1541
  diffci mcp
1427
- diffci verify [--changed | --base <sha> --head <sha>] [--policy enforce] [--repo <path>] [--out <file>] [--json]
1542
+ diffci verify [--changed | --staged | --paths <file...> | --paths-from <file|-> | --base <sha> --head <sha>]
1543
+ [--policy enforce] [--repo <path>] [--out <file>] [--json]
1428
1544
  [--redact-paths] [--timeout-ms <ms>] [--baseline-on-failure] [--no-checks | --checks]
1429
- [--share-usage] [--no-send] [--no-log] [--no-reuse] [--no-rank] [--fail-fast]
1545
+ [--no-send] [--no-log] [--no-reuse] [--no-rank] [--fail-fast]
1430
1546
  [--shard <i/N> [--timings <file>]] [--no-coverage]
1431
1547
  diffci telemetry [--mode repo|count-only] [--internal-usage]
1432
1548
  diffci check [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
1433
- [--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>] [--share-usage]
1549
+ [--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>]
1434
1550
  diffci plan --base <sha> [--head <sha>] [--repo <path>]
1435
1551
  diffci check-plan --plan <plan.json> --results <junit.xml>
1436
1552
  diffci red-builds <owner/repo> [--runs <n>] [--workflow <id|file>] [--json <file>] [--check-jobs <regex>] [--ci-only-jobs <regex>]
@@ -1439,7 +1555,7 @@ Usage:
1439
1555
  [--label <name>] [--repository-url <https-url>] [--redact-paths]
1440
1556
  diffci observe [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
1441
1557
  [--redact-paths] [--json] [--quiet] [--fail-on-error] [--summary-out <file.md>]
1442
- [--api-url <url> --api-token <token>] [--no-send] [--share-usage] [--agent <name|auto>]
1558
+ [--api-url <url> --api-token <token>] [--no-send] [--agent <name|auto>]
1443
1559
  [--graph-cache-dir <dir>] [--shared-graph-cache [--graph-cache-url <url>]]
1444
1560
  diffci verify-savings --repo <path> --full <command>
1445
1561
  (--selected <command> | --selected-from-report <file>)
@@ -1473,12 +1589,18 @@ and adds diffci:verify, diffci:check, and diffci:observe package scripts without
1473
1589
  --verification-workflow adds a blocking GitHub check that uploads a commit-bound verification receipt.
1474
1590
  The pre-push hook runs diffci verify on the commits being pushed and blocks the push
1475
1591
  when verification fails (git push --no-verify skips it; DIFFCI_HOOK_STRICT=1 also blocks when it cannot verify).
1592
+ verify --changed, --staged and --paths replace an outdated DiffCI-written hook with this version's, same
1593
+ command (DIFFCI_HOOK_REFRESH=0 turns it off; a hook DiffCI did not write is never touched).
1476
1594
  mcp runs the stdio MCP server for native agent integrations.
1477
1595
  verify --changed snapshots staged, unstaged, and non-ignored untracked changes, runs the minimum
1478
1596
  executable verification (or full fallback), and exits zero only when that exact snapshot passes.
1479
1597
  verify first runs the rest of the repository's gate (the check script's lint, typecheck and check-script
1480
1598
  leaves) and stops at the first failure; --no-checks skips them, and they are skipped in CI unless --checks.
1481
- verify without --changed resolves the CI event range (or HEAD^..HEAD locally), requires a clean checkout,
1599
+ verify --staged verifies HEAD plus the index only, and --paths (or --paths-from, one path per line, - for
1600
+ stdin) HEAD plus only those working-tree files, in a temporary worktree with node_modules linked in: other
1601
+ uncommitted files stay at their HEAD version and are listed in the receipt (scoped.excluded_dirty_paths).
1602
+ Use it before a commit when other sessions share the checkout. The pre-push hook reuses a pass of the tree.
1603
+ verify without these flags resolves the CI event range (or HEAD^..HEAD locally), requires a clean checkout,
1482
1604
  and exits zero only when the analyzed head is the commit that actually passed verification.
1483
1605
  check analyzes the change, runs inferred full and selected commands, and shows measured savings.
1484
1606
  plan prints Core's advisory JSON plan for a clean checkout at --head; save it before the full suite runs.
@@ -1,6 +1,6 @@
1
1
  import { commandArguments } from "./selected-coverage.js";
2
2
  import { mergeTestFileResults } from "./test-results.js";
3
- import { measureCommand } from "./verify-savings.js";
3
+ import { measureCommand, tail as tailBytes } from "./verify-savings.js";
4
4
  /**
5
5
  * Selected-test commands too long for the shell (2026-10-21).
6
6
  *
@@ -149,7 +149,8 @@ export function measureCommands(commands, options) {
149
149
  const failingTests = [...new Set(parts.flatMap((part) => part.failingTests ?? []))].sort();
150
150
  const counted = ranAll && parts.every((part) => part.runnerTestCount !== undefined);
151
151
  const testResults = mergeTestFileResults(...parts.map((part) => part.testResults));
152
- const tail = (key) => parts.map((part) => part[key]).join("").slice(-Math.max(options.tailBytes, 0) || undefined);
152
+ // The same byte-bounded cut as a single command's tail: by UTF-8 bytes, at a character boundary.
153
+ const tail = (key) => tailBytes(parts.map((part) => part[key]).join(""), options.tailBytes);
153
154
  return {
154
155
  command: commands.join(" && "),
155
156
  exitCode: failed ? failed.exitCode : ranAll ? 0 : null,
@@ -129,6 +129,24 @@ function mergeBase(git, a, b) {
129
129
  const result = git(["merge-base", a, b]);
130
130
  return result.ok ? result.stdout.trim() || undefined : undefined;
131
131
  }
132
+ /**
133
+ * The base for a push that created its branch (2026-11-18). There is no `before`, and the head's parent
134
+ * covers only the last of the commits the push brought, so a change made earlier in the same push was
135
+ * never analysed. The commits the new branch adds are the ones not on the default branch, so the merge
136
+ * base with the default branch's remote-tracking ref is the base - the same range a pull request from the
137
+ * branch would get. Undefined when that ref is not in this checkout, or the head is already on it (nothing
138
+ * new to compare), and the caller then falls back to the labelled `head-parent` range.
139
+ */
140
+ function branchCreationBase(git, headSha, defaultBranch) {
141
+ if (!defaultBranch || !/^[A-Za-z0-9._/-]+$/.test(defaultBranch) || defaultBranch.startsWith("-") || defaultBranch.includes("..")) {
142
+ return undefined;
143
+ }
144
+ const tip = resolveSha(git, `refs/remotes/origin/${defaultBranch}`);
145
+ if (!tip)
146
+ return undefined;
147
+ const common = mergeBase(git, tip, headSha);
148
+ return common && common !== headSha && commitExists(git, common) ? common : undefined;
149
+ }
132
150
  /** The one sentence every "commit missing locally" refusal ends with, so the fix is never a guess. */
133
151
  const DEEPEN_HINT = "the commit is not in this checkout - add `fetch-depth: 0` to the actions/checkout step in the job that runs DiffCI (this does not affect any other job)";
134
152
  /** GitLab clones 20 commits deep by default, so a long merge request loses its base (2026-11-05). */
@@ -237,6 +255,11 @@ function resolveGitlabRange(env, git) {
237
255
  if (before && before !== ZERO_SHA && commitExists(git, before)) {
238
256
  return { ok: true, range: { baseSha: before, headSha, source: "push-event" } };
239
257
  }
258
+ if (before === ZERO_SHA || before === undefined) {
259
+ const common = branchCreationBase(git, headSha, asString(env.CI_DEFAULT_BRANCH));
260
+ if (common)
261
+ return { ok: true, range: { baseSha: common, headSha, source: "push-event", mergeBaseSha: common } };
262
+ }
240
263
  const parent = resolveSha(git, `${headSha}^`);
241
264
  if (!parent) {
242
265
  return {
@@ -344,8 +367,15 @@ export function resolveCommitRange(options) {
344
367
  if (before && before !== ZERO_SHA && commitExists(git, before)) {
345
368
  return { ok: true, range: { baseSha: before, headSha, source: "push-event" } };
346
369
  }
347
- // A branch's first push has no `before`. The head's own parent is the honest substitute and is
348
- // labelled as such - it answers "what did this commit change", not "what did this push change".
370
+ // A branch's first push has no `before`. Its merge base with the default branch covers every commit
371
+ // the push brought; only when that cannot be computed is the head's own parent used, labelled as
372
+ // such - it answers "what did this commit change", not "what did this push change".
373
+ if (before === ZERO_SHA) {
374
+ const defaultBranch = asString(nested(payload, "repository", "default_branch")) ?? asString(env.GITHUB_DEFAULT_BRANCH);
375
+ const common = branchCreationBase(git, headSha, defaultBranch);
376
+ if (common)
377
+ return { ok: true, range: { baseSha: common, headSha, source: "push-event", mergeBaseSha: common } };
378
+ }
349
379
  const parent = resolveSha(git, `${headSha}^`);
350
380
  if (!parent) {
351
381
  return {
@@ -25,12 +25,17 @@ export const COVERAGE_MAP_SCHEMA = "diffci.coverage-map.v1";
25
25
  const PROBE = `"use strict";
26
26
  if (process.env.NODE_TEST_CONTEXT && process.argv[1] && process.env.DIFFCI_COVERAGE_LOG) {
27
27
  const fs = require("node:fs");
28
+ const { resolve } = require("node:path");
28
29
  const { fileURLToPath } = require("node:url");
29
30
  const file = process.argv[1];
30
31
  const reads = new Set();
31
32
  const listed = new Set();
33
+ // A relative path is resolved against the test process's working directory when it is read, as fs does.
32
34
  const note = (set, target) => {
33
- try { set.add(typeof target === "string" ? target : target instanceof URL ? fileURLToPath(target) : Buffer.isBuffer(target) ? target.toString() : ""); } catch {}
35
+ try {
36
+ const name = typeof target === "string" ? target : target instanceof URL ? fileURLToPath(target) : Buffer.isBuffer(target) ? target.toString() : "";
37
+ if (name) set.add(resolve(name));
38
+ } catch {}
34
39
  };
35
40
  const wrap = (owner, name, set) => {
36
41
  const original = owner[name];
@@ -144,6 +144,9 @@ export function inferFullCommand(repoPath) {
144
144
  };
145
145
  }
146
146
  const packagePath = join(repoPath, "package.json");
147
+ // A package.json without a test script is often tooling only (prettier, husky, commitlint) beside a
148
+ // Go or Python project, whose own runner is then the full command, as it is for the selection.
149
+ let noTestScript;
147
150
  if (existsSync(packagePath)) {
148
151
  let pkg;
149
152
  try {
@@ -153,21 +156,23 @@ export function inferFullCommand(repoPath) {
153
156
  return { reason: "package.json could not be read" };
154
157
  }
155
158
  if (typeof pkg.scripts?.test !== "string" || !pkg.scripts.test.trim()) {
156
- return { reason: "package.json has no test script" };
159
+ noTestScript = { reason: "package.json has no test script" };
157
160
  }
158
- const manager = typeof pkg.packageManager === "string" ? pkg.packageManager.split("@")[0] : undefined;
159
- if (manager === "pnpm" || manager === "yarn" || manager === "bun") {
160
- return { command: `${manager} test`, reason: `package.json test script via ${manager}` };
161
+ else {
162
+ const manager = typeof pkg.packageManager === "string" ? pkg.packageManager.split("@")[0] : undefined;
163
+ if (manager === "pnpm" || manager === "yarn" || manager === "bun") {
164
+ return { command: `${manager} test`, reason: `package.json test script via ${manager}` };
165
+ }
166
+ if (manager && manager !== "npm")
167
+ return { reason: `unsupported package manager: ${manager}` };
168
+ if (existsSync(join(repoPath, "pnpm-lock.yaml")))
169
+ return { command: "pnpm test", reason: "package.json test script with pnpm lockfile" };
170
+ if (existsSync(join(repoPath, "yarn.lock")))
171
+ return { command: "yarn test", reason: "package.json test script with Yarn lockfile" };
172
+ if (existsSync(join(repoPath, "bun.lock")) || existsSync(join(repoPath, "bun.lockb")))
173
+ return { command: "bun test", reason: "package.json test script with Bun lockfile" };
174
+ return { command: "npm test", reason: "package.json test script" };
161
175
  }
162
- if (manager && manager !== "npm")
163
- return { reason: `unsupported package manager: ${manager}` };
164
- if (existsSync(join(repoPath, "pnpm-lock.yaml")))
165
- return { command: "pnpm test", reason: "package.json test script with pnpm lockfile" };
166
- if (existsSync(join(repoPath, "yarn.lock")))
167
- return { command: "yarn test", reason: "package.json test script with Yarn lockfile" };
168
- if (existsSync(join(repoPath, "bun.lock")) || existsSync(join(repoPath, "bun.lockb")))
169
- return { command: "bun test", reason: "package.json test script with Bun lockfile" };
170
- return { command: "npm test", reason: "package.json test script" };
171
176
  }
172
177
  if (existsSync(join(repoPath, "go.mod")))
173
178
  return { command: "go test ./...", reason: "root Go module" };
@@ -178,7 +183,7 @@ export function inferFullCommand(repoPath) {
178
183
  ? { command: `${interpreter} -m pytest`, reason: "Python project tested with pytest" }
179
184
  : { reason: "Python project, but no Python 3 interpreter (python3, python or py -3) is on PATH" };
180
185
  }
181
- return { reason: "no supported full test command could be inferred" };
186
+ return noTestScript ?? { reason: "no supported full test command could be inferred" };
182
187
  }
183
188
  function pythonInterpreter(cwd) {
184
189
  for (const candidate of [["python3"], ["python"], ["py", "-3"]]) {