@diffci.com/diffci 0.3.22 → 0.3.24
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.
- package/dist-client/src/client/agent-setup.d.ts +23 -0
- package/dist-client/src/client/agent-setup.js +111 -0
- package/dist-client/src/client/cli.js +33 -9
- package/dist-client/src/client/command-batches.d.ts +1 -0
- package/dist-client/src/client/command-batches.js +3 -2
- package/dist-client/src/client/failure-baseline.js +0 -0
- package/dist-client/src/client/full-command.d.ts +10 -0
- package/dist-client/src/client/full-command.js +22 -0
- package/dist-client/src/client/hook.d.ts +1 -0
- package/dist-client/src/client/hook.js +9 -0
- package/dist-client/src/client/mcp.js +10 -4
- package/dist-client/src/client/observe.js +10 -5
- package/dist-client/src/client/selected-coverage.d.ts +21 -1
- package/dist-client/src/client/selected-coverage.js +83 -10
- package/dist-client/src/client/verify-savings.d.ts +3 -1
- package/dist-client/src/client/verify-savings.js +1 -0
- package/dist-client/src/client/verify.js +50 -19
- package/dist-client/src/client/workflow-guard.js +14 -0
- package/node_modules/@diffci.com/core/README.md +4 -0
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +3 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +109 -8
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/types.d.ts +6 -2
- package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +4 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +140 -26
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/analyzer.js +9 -2
- package/node_modules/@diffci.com/core/dist/repo/analyzer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +231 -28
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +57 -7
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.d.ts +6 -0
- package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.js +161 -0
- package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.d.ts +5 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +55 -6
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/types.d.ts +7 -0
- package/node_modules/@diffci.com/core/package.json +1 -1
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +3 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +91 -7
- package/node_modules/@diffci.com/core/src/git/types.ts +6 -2
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +138 -22
- package/node_modules/@diffci.com/core/src/repo/analyzer.ts +9 -2
- package/node_modules/@diffci.com/core/src/repo/graph.ts +206 -30
- package/node_modules/@diffci.com/core/src/repo/impact.ts +53 -7
- package/node_modules/@diffci.com/core/src/repo/pnpm-lockfile.ts +147 -0
- package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +52 -8
- package/node_modules/@diffci.com/core/src/repo/types.ts +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent integrations `diffci init` sets up by default (2026-11-04): the MCP server in the project
|
|
3
|
+
* configs Claude Code (`.mcp.json`) and Cursor (`.cursor/mcp.json`) read, and the diffci-verify skill
|
|
4
|
+
* in `.claude/skills`.
|
|
5
|
+
*
|
|
6
|
+
* WHY. Agents called DiffCI in 24 of over 1,500 test commands on DentalPresence, where it was only an
|
|
7
|
+
* instruction. Growth depends on the agent finding DiffCI's tools in the repository without anyone
|
|
8
|
+
* installing a plugin, so one `diffci init` now registers them. Each write keeps files and servers
|
|
9
|
+
* DiffCI did not write.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MCP_CONFIG_PATHS: readonly [".mcp.json", ".cursor/mcp.json"];
|
|
12
|
+
export declare const SKILL_PATH = ".claude/skills/diffci-verify/SKILL.md";
|
|
13
|
+
/** Same launcher as the portable agent plugin: `npx` through cmd.exe on Windows, where agents cannot spawn `npx.cmd` directly. */
|
|
14
|
+
export declare function mcpServerEntry(version: string): {
|
|
15
|
+
command: string;
|
|
16
|
+
args: string[];
|
|
17
|
+
};
|
|
18
|
+
/** Adds or updates the `diffci` server and leaves every other server untouched. */
|
|
19
|
+
export declare function writeMcpConfig(repoPath: string, relativePath: string, version: string, force: boolean): string;
|
|
20
|
+
/** Kept identical to integrations/agent-plugin/skills/diffci-verify/SKILL.md (tested). */
|
|
21
|
+
export declare const DIFFCI_VERIFY_SKILL = "---\nname: diffci-verify\ndescription: Select and verify affected tests after editing code in a local Git repository, using DiffCI MCP tools or the DiffCI CLI before reporting the change ready.\n---\n\nPass the absolute path of the edited repository as `repo` on every tool call.\n\nUse `diffci_changed_files` to inspect staged, unstaged, and non-ignored untracked\nchanges. Use `diffci_select_tests` or `diffci_explain_selection` when you need the\naffected-test plan, command, or reasons for full fallback. These tools run no tests;\ntheir counts describe test files, not passing test cases. A plan is not verification.\n\nBefore reporting an edited change ready, call `diffci_run_affected_tests`. It\nrecomputes the selection and verifies the current snapshot. Accept a passing result\nonly when `safe_to_continue` is true and `snapshot.unchanged` is true. After further\nedits, rerun verification. For a clean committed change, use `diffci_verify` with the\nintended base/head range instead; no uncommitted changes does not mean the commit\nhas been tested.\n\nIf MCP is unavailable, use the installed CLI:\n\n```bash\ndiffci verify --changed --repo /absolute/path/to/repository --json\n```\n\nIf DiffCI is not installed, use `npx \"@diffci.com/diffci@latest\" verify --changed`\nwith the same repo and JSON flags. On blocked analysis or installation failure,\nrun the repository's normal verification and report the limitation. On a test\nfailure, fix the cause and rerun. On snapshot changes from generated files, inspect\nthe files and rerun for that snapshot.\n\nReport executed command, selection scope (affected or full fallback), test-file\ncounts, outcome, and any outstanding required checks. Never infer passed suites,\ntest cases, skipped CI jobs, or measured savings from selection counts. Required\nproject CI stays authoritative.\n";
|
|
22
|
+
/** A skill file DiffCI wrote is recognised by its frontmatter name and updated; any other file is kept. */
|
|
23
|
+
export declare function writeSkill(repoPath: string, force: boolean): string;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Agent integrations `diffci init` sets up by default (2026-11-04): the MCP server in the project
|
|
5
|
+
* configs Claude Code (`.mcp.json`) and Cursor (`.cursor/mcp.json`) read, and the diffci-verify skill
|
|
6
|
+
* in `.claude/skills`.
|
|
7
|
+
*
|
|
8
|
+
* WHY. Agents called DiffCI in 24 of over 1,500 test commands on DentalPresence, where it was only an
|
|
9
|
+
* instruction. Growth depends on the agent finding DiffCI's tools in the repository without anyone
|
|
10
|
+
* installing a plugin, so one `diffci init` now registers them. Each write keeps files and servers
|
|
11
|
+
* DiffCI did not write.
|
|
12
|
+
*/
|
|
13
|
+
export const MCP_CONFIG_PATHS = [".mcp.json", ".cursor/mcp.json"];
|
|
14
|
+
export const SKILL_PATH = ".claude/skills/diffci-verify/SKILL.md";
|
|
15
|
+
/** Same launcher as the portable agent plugin: `npx` through cmd.exe on Windows, where agents cannot spawn `npx.cmd` directly. */
|
|
16
|
+
export function mcpServerEntry(version) {
|
|
17
|
+
return {
|
|
18
|
+
command: "node",
|
|
19
|
+
args: [
|
|
20
|
+
"-e",
|
|
21
|
+
`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)));`,
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function isDiffciEntry(entry) {
|
|
26
|
+
return JSON.stringify(entry ?? null).includes("@diffci.com/diffci");
|
|
27
|
+
}
|
|
28
|
+
/** Adds or updates the `diffci` server and leaves every other server untouched. */
|
|
29
|
+
export function writeMcpConfig(repoPath, relativePath, version, force) {
|
|
30
|
+
const absolutePath = join(repoPath, relativePath);
|
|
31
|
+
const entry = mcpServerEntry(version);
|
|
32
|
+
let config = {};
|
|
33
|
+
let existing;
|
|
34
|
+
if (existsSync(absolutePath)) {
|
|
35
|
+
existing = readFileSync(absolutePath, "utf8");
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(existing);
|
|
38
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
39
|
+
throw new Error("not an object");
|
|
40
|
+
config = parsed;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return `kept ${relativePath} (not a JSON object; add the diffci MCP server by hand)`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const servers = config.mcpServers && typeof config.mcpServers === "object" ? config.mcpServers : {};
|
|
47
|
+
if (servers.diffci !== undefined && !isDiffciEntry(servers.diffci) && !force) {
|
|
48
|
+
return `kept ${relativePath} (its diffci server was not written by DiffCI; pass --force to replace it)`;
|
|
49
|
+
}
|
|
50
|
+
config.mcpServers = { ...servers, diffci: entry };
|
|
51
|
+
const next = `${JSON.stringify(config, null, 2)}\n`;
|
|
52
|
+
if (next === existing)
|
|
53
|
+
return `kept ${relativePath} (diffci MCP server current)`;
|
|
54
|
+
mkdirSync(dirname(absolutePath), { recursive: true });
|
|
55
|
+
writeFileSync(absolutePath, next, "utf8");
|
|
56
|
+
return `${existing === undefined ? "wrote" : "updated"} ${relativePath} (diffci MCP server)`;
|
|
57
|
+
}
|
|
58
|
+
/** Kept identical to integrations/agent-plugin/skills/diffci-verify/SKILL.md (tested). */
|
|
59
|
+
export const DIFFCI_VERIFY_SKILL = `---
|
|
60
|
+
name: diffci-verify
|
|
61
|
+
description: Select and verify affected tests after editing code in a local Git repository, using DiffCI MCP tools or the DiffCI CLI before reporting the change ready.
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
Pass the absolute path of the edited repository as \`repo\` on every tool call.
|
|
65
|
+
|
|
66
|
+
Use \`diffci_changed_files\` to inspect staged, unstaged, and non-ignored untracked
|
|
67
|
+
changes. Use \`diffci_select_tests\` or \`diffci_explain_selection\` when you need the
|
|
68
|
+
affected-test plan, command, or reasons for full fallback. These tools run no tests;
|
|
69
|
+
their counts describe test files, not passing test cases. A plan is not verification.
|
|
70
|
+
|
|
71
|
+
Before reporting an edited change ready, call \`diffci_run_affected_tests\`. It
|
|
72
|
+
recomputes the selection and verifies the current snapshot. Accept a passing result
|
|
73
|
+
only when \`safe_to_continue\` is true and \`snapshot.unchanged\` is true. After further
|
|
74
|
+
edits, rerun verification. For a clean committed change, use \`diffci_verify\` with the
|
|
75
|
+
intended base/head range instead; no uncommitted changes does not mean the commit
|
|
76
|
+
has been tested.
|
|
77
|
+
|
|
78
|
+
If MCP is unavailable, use the installed CLI:
|
|
79
|
+
|
|
80
|
+
\`\`\`bash
|
|
81
|
+
diffci verify --changed --repo /absolute/path/to/repository --json
|
|
82
|
+
\`\`\`
|
|
83
|
+
|
|
84
|
+
If DiffCI is not installed, use \`npx "@diffci.com/diffci@latest" verify --changed\`
|
|
85
|
+
with the same repo and JSON flags. On blocked analysis or installation failure,
|
|
86
|
+
run the repository's normal verification and report the limitation. On a test
|
|
87
|
+
failure, fix the cause and rerun. On snapshot changes from generated files, inspect
|
|
88
|
+
the files and rerun for that snapshot.
|
|
89
|
+
|
|
90
|
+
Report executed command, selection scope (affected or full fallback), test-file
|
|
91
|
+
counts, outcome, and any outstanding required checks. Never infer passed suites,
|
|
92
|
+
test cases, skipped CI jobs, or measured savings from selection counts. Required
|
|
93
|
+
project CI stays authoritative.
|
|
94
|
+
`;
|
|
95
|
+
/** A skill file DiffCI wrote is recognised by its frontmatter name and updated; any other file is kept. */
|
|
96
|
+
export function writeSkill(repoPath, force) {
|
|
97
|
+
const absolutePath = join(repoPath, SKILL_PATH);
|
|
98
|
+
if (existsSync(absolutePath)) {
|
|
99
|
+
const existing = readFileSync(absolutePath, "utf8");
|
|
100
|
+
if (existing.replace(/\r\n/g, "\n") === DIFFCI_VERIFY_SKILL)
|
|
101
|
+
return `kept ${SKILL_PATH} (current)`;
|
|
102
|
+
if (!/^---\r?\nname: diffci-verify\r?\n/.test(existing) && !force) {
|
|
103
|
+
return `kept ${SKILL_PATH} (existing file not written by DiffCI; pass --force to replace it)`;
|
|
104
|
+
}
|
|
105
|
+
writeFileSync(absolutePath, DIFFCI_VERIFY_SKILL, "utf8");
|
|
106
|
+
return `updated ${SKILL_PATH}`;
|
|
107
|
+
}
|
|
108
|
+
mkdirSync(dirname(absolutePath), { recursive: true });
|
|
109
|
+
writeFileSync(absolutePath, DIFFCI_VERIFY_SKILL, "utf8");
|
|
110
|
+
return `wrote ${SKILL_PATH} (Claude Code skill)`;
|
|
111
|
+
}
|
|
@@ -36,7 +36,8 @@ import { observe, isInsideRepository } from "./observe.js";
|
|
|
36
36
|
import { resolveObservationAgent } from "./agent-identity.js";
|
|
37
37
|
import { inferFullCommand, inferComparableSelectedCommand, inferWorkspaceComparison } from "./full-command.js";
|
|
38
38
|
import { addDiffciPackageScripts, detectPackageManager, installDiffci } from "./install.js";
|
|
39
|
-
import { hookCommand, installPrePushHook } from "./hook.js";
|
|
39
|
+
import { hookCommand, installPrePushHook, isGitRepository } from "./hook.js";
|
|
40
|
+
import { MCP_CONFIG_PATHS, SKILL_PATH, writeMcpConfig, writeSkill } from "./agent-setup.js";
|
|
40
41
|
import { submitObservation } from "./submit.js";
|
|
41
42
|
import { configureGraphCache } from "./shared-graph-cache.js";
|
|
42
43
|
import { GraphCache } from "@diffci.com/core/cache/graph-cache";
|
|
@@ -283,7 +284,22 @@ function runInit(flags, env) {
|
|
|
283
284
|
if (includeVerificationWorkflow) {
|
|
284
285
|
writes.push(writeInitFile(repoPath, ".github/workflows/diffci-verify.yml", diffciVerificationWorkflow(identity.version), force));
|
|
285
286
|
}
|
|
286
|
-
|
|
287
|
+
// The hook, MCP server and skill are on by default so an agent meets DiffCI without being told to.
|
|
288
|
+
const skipped = [];
|
|
289
|
+
if (flags["no-mcp"] === true)
|
|
290
|
+
skipped.push("skipped the MCP server configs (--no-mcp)");
|
|
291
|
+
else
|
|
292
|
+
for (const path of MCP_CONFIG_PATHS)
|
|
293
|
+
writes.push(writeMcpConfig(repoPath, path, identity.version, force));
|
|
294
|
+
if (flags["no-skill"] === true)
|
|
295
|
+
skipped.push(`skipped ${SKILL_PATH} (--no-skill)`);
|
|
296
|
+
else
|
|
297
|
+
writes.push(writeSkill(repoPath, force));
|
|
298
|
+
if (flags["no-hook"] === true)
|
|
299
|
+
skipped.push("skipped the pre-push hook (--no-hook)");
|
|
300
|
+
else if (!isGitRepository(repoPath))
|
|
301
|
+
skipped.push("skipped the pre-push hook (not a Git repository; rerun init after git init)");
|
|
302
|
+
else
|
|
287
303
|
writes.push(installPrePushHook(repoPath, hookCommand(manager, identity.version), force));
|
|
288
304
|
console.log(`DiffCI initialized for AI coding agents in ${repoPath}`);
|
|
289
305
|
for (const write of writes)
|
|
@@ -292,8 +308,8 @@ function runInit(flags, env) {
|
|
|
292
308
|
console.log(` ${installed}`);
|
|
293
309
|
else
|
|
294
310
|
console.log(" skipped package installation (pass --install to add an exact dev dependency)");
|
|
295
|
-
|
|
296
|
-
console.log(
|
|
311
|
+
for (const line of skipped)
|
|
312
|
+
console.log(` ${line}`);
|
|
297
313
|
if (!includeWorkflow)
|
|
298
314
|
console.log(" skipped .github/workflows/diffci.yml (pass --workflow to add it)");
|
|
299
315
|
if (!includeVerificationWorkflow)
|
|
@@ -502,7 +518,13 @@ function summarise(report, executionFollows = false) {
|
|
|
502
518
|
}
|
|
503
519
|
lines.push(` non-interference${executionFollows ? " (analysis phase)" : ""}: worktree ${report.nonInterference.worktreeUnchanged ? "unchanged" : "CHANGED - report this"}, report written ${report.nonInterference.reportWrittenOutsideRepository ? "outside" : "INSIDE"} the checkout`);
|
|
504
520
|
const blocking = report.nonInterference.workflowFindings.filter((f) => f.severity === "BLOCKING");
|
|
505
|
-
|
|
521
|
+
// `check` is a local trial, not an installation, so it names the count and where to look; `observe`
|
|
522
|
+
// runs inside the installation being judged and keeps every finding in its log.
|
|
523
|
+
if (blocking.length > 0 && executionFollows) {
|
|
524
|
+
const jobs = new Set(blocking.map((finding) => `${finding.workflow}#${finding.job ?? ""}`));
|
|
525
|
+
lines.push(` workflow: ${blocking.length} blocking finding(s) in ${jobs.size} DiffCI job(s) could let an observer affect CI; run \`diffci verify-workflow\` for details`);
|
|
526
|
+
}
|
|
527
|
+
else if (blocking.length > 0) {
|
|
506
528
|
lines.push(` workflow: ${blocking.length} blocking finding(s) - this installation CAN affect other jobs:`);
|
|
507
529
|
for (const finding of blocking)
|
|
508
530
|
lines.push(formatFinding(finding));
|
|
@@ -1061,7 +1083,7 @@ Open-source engine: https://github.com/DiffCI/core
|
|
|
1061
1083
|
Pilot a repository: https://diffci.com/#pilot
|
|
1062
1084
|
|
|
1063
1085
|
Usage:
|
|
1064
|
-
diffci init [--repo <path>] [--workflow] [--verification-workflow] [--install] [--hook] [--force]
|
|
1086
|
+
diffci init [--repo <path>] [--workflow] [--verification-workflow] [--install] [--no-hook] [--no-mcp] [--no-skill] [--force]
|
|
1065
1087
|
diffci mcp
|
|
1066
1088
|
diffci verify [--changed | --base <sha> --head <sha>] [--policy enforce] [--repo <path>] [--out <file>] [--json]
|
|
1067
1089
|
[--redact-paths] [--timeout-ms <ms>] [--baseline-on-failure] [--no-checks | --checks]
|
|
@@ -1092,12 +1114,14 @@ Usage:
|
|
|
1092
1114
|
[--head <sha>] [--rerun-junit <file>] [--open-issue]
|
|
1093
1115
|
diffci version
|
|
1094
1116
|
|
|
1095
|
-
init writes AGENTS.md, CLAUDE.md, Cursor rules, Copilot instructions, and diffci.config.json.
|
|
1096
|
-
|
|
1117
|
+
init writes AGENTS.md, CLAUDE.md, Cursor rules, Copilot instructions, and diffci.config.json. It also
|
|
1118
|
+
registers the DiffCI MCP server in .mcp.json (Claude Code) and .cursor/mcp.json (Cursor), keeping other
|
|
1119
|
+
servers, adds the diffci-verify skill to .claude/skills, and installs the pre-push hook; --no-mcp,
|
|
1120
|
+
--no-skill and --no-hook leave each out. --workflow adds a separate non-blocking observation workflow. --install detects npm, pnpm, Yarn,
|
|
1097
1121
|
or Bun, installs this DiffCI version as an exact dev dependency, updates the manager's lockfile,
|
|
1098
1122
|
and adds diffci:verify, diffci:check, and diffci:observe package scripts without replacing existing scripts.
|
|
1099
1123
|
--verification-workflow adds a blocking GitHub check that uploads a commit-bound verification receipt.
|
|
1100
|
-
|
|
1124
|
+
The pre-push hook runs diffci verify on the commits being pushed and blocks the push
|
|
1101
1125
|
when verification fails (git push --no-verify skips it; DIFFCI_HOOK_STRICT=1 also blocks when it cannot verify).
|
|
1102
1126
|
mcp runs the stdio MCP server for native agent integrations.
|
|
1103
1127
|
verify --changed snapshots staged, unstaged, and non-ignored untracked changes, runs the minimum
|
|
@@ -20,9 +20,10 @@ export function batchCommand(command, paths, limit = COMMAND_LINE_LIMIT) {
|
|
|
20
20
|
return [command];
|
|
21
21
|
const tokens = command.split(" ");
|
|
22
22
|
const selected = new Set(paths);
|
|
23
|
-
// A `node --test` path with brackets arrives quoted and class-escaped: "src/app
|
|
23
|
+
// A `node --test` path with brackets arrives quoted and class-escaped: "src/app/@([[])id@([]])/x.test.ts"
|
|
24
|
+
// (Core before 2026-11-02 emitted the bare class, "src/app/[[]id[]]/x.test.ts").
|
|
24
25
|
const isSelected = (token) => selected.has(token)
|
|
25
|
-
|| selected.has((commandArguments(token)[0] ?? "").replace(
|
|
26
|
+
|| selected.has((commandArguments(token)[0] ?? "").replace(/@\(\[(.)\]\)|\[(.)\]/g, (_, wrapped, bare) => wrapped ?? bare ?? ""));
|
|
26
27
|
let start = tokens.length;
|
|
27
28
|
while (start > 0 && isSelected(tokens[start - 1]))
|
|
28
29
|
start--;
|
|
Binary file
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A selection the planner splits across several commands - a workspace package and the root suite, or
|
|
3
|
+
* several Vitest projects - rebuilt from the repository so only the planner's own commands run, each
|
|
4
|
+
* split to fit the shell. Before 2026-11-04 verify ran the full suite for any plan of more than one
|
|
5
|
+
* command (LobeHub: every narrowed commit, 27 minutes then a timeout).
|
|
6
|
+
*/
|
|
7
|
+
export declare function inferSelectedCommands(repoPath: string, proposed: readonly string[], selectedTests: readonly string[]): {
|
|
8
|
+
commands?: string[];
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
1
11
|
/** Rebuild the complete plan locally; never join arbitrary report commands. */
|
|
2
12
|
export declare function inferWorkspaceComparison(repoPath: string, proposed: readonly string[], selectedTests: readonly string[]): {
|
|
3
13
|
full?: string;
|
|
@@ -3,6 +3,28 @@ import { join } from "node:path";
|
|
|
3
3
|
import { readRepositoryConfig } from "@diffci.com/core/repo/repo-config";
|
|
4
4
|
import { analyzeRepository } from "@diffci.com/core/repo/analyzer";
|
|
5
5
|
import { commandSpecToString, planSelectiveTestCommands } from "@diffci.com/core/planner/test-command";
|
|
6
|
+
import { batchCommand } from "./command-batches.js";
|
|
7
|
+
/**
|
|
8
|
+
* A selection the planner splits across several commands - a workspace package and the root suite, or
|
|
9
|
+
* several Vitest projects - rebuilt from the repository so only the planner's own commands run, each
|
|
10
|
+
* split to fit the shell. Before 2026-11-04 verify ran the full suite for any plan of more than one
|
|
11
|
+
* command (LobeHub: every narrowed commit, 27 minutes then a timeout).
|
|
12
|
+
*/
|
|
13
|
+
export function inferSelectedCommands(repoPath, proposed, selectedTests) {
|
|
14
|
+
const plan = planSelectiveTestCommands(analyzeRepository({ repoPath }), selectedTests);
|
|
15
|
+
if (plan.refusalReason || !plan.commands.length)
|
|
16
|
+
return { reason: plan.refusalReason ?? "the plan has no commands" };
|
|
17
|
+
if (JSON.stringify(plan.commands.map(commandSpecToString)) !== JSON.stringify(proposed))
|
|
18
|
+
return { reason: "report commands differ from the verified plan" };
|
|
19
|
+
const commands = plan.groups.flatMap((group) => {
|
|
20
|
+
// The trailing arguments that name selected files, as the shell string spells them.
|
|
21
|
+
const paths = group.commandSpec.args
|
|
22
|
+
.filter((arg) => group.paths.some((path) => path === arg || path.endsWith(`/${arg}`)))
|
|
23
|
+
.map((arg) => commandSpecToString({ executable: "", args: [arg] }).slice(1));
|
|
24
|
+
return batchCommand(commandSpecToString(group.commandSpec), paths);
|
|
25
|
+
});
|
|
26
|
+
return { commands, reason: `${plan.commands.length} commands from the verified plan` };
|
|
27
|
+
}
|
|
6
28
|
/** Rebuild the complete plan locally; never join arbitrary report commands. */
|
|
7
29
|
export function inferWorkspaceComparison(repoPath, proposed, selectedTests) {
|
|
8
30
|
const profile = analyzeRepository({ repoPath });
|
|
@@ -22,6 +22,7 @@ export declare function prePushHook(command: string): string;
|
|
|
22
22
|
/** The command the hook runs: the installed binary when the repository has DiffCI as a dependency,
|
|
23
23
|
* otherwise a pinned npx invocation, so the hook never floats to a newer release. */
|
|
24
24
|
export declare function hookCommand(manager: "npm" | "pnpm" | "yarn" | "bun" | undefined, version: string): string;
|
|
25
|
+
export declare function isGitRepository(repoPath: string): boolean;
|
|
25
26
|
/** Writes the hook into the directory Git actually runs hooks from (`core.hooksPath` included, such as
|
|
26
27
|
* `.husky`). An existing hook DiffCI did not write is kept unless `force` is set. */
|
|
27
28
|
export declare function installPrePushHook(repoPath: string, command: string, force: boolean): string;
|
|
@@ -77,6 +77,15 @@ export function hookCommand(manager, version) {
|
|
|
77
77
|
default: return `npx --yes "@diffci.com/diffci@${version}"`;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
+
export function isGitRepository(repoPath) {
|
|
81
|
+
try {
|
|
82
|
+
execFileSync("git", ["rev-parse", "--git-dir"], { cwd: repoPath, stdio: "ignore", windowsHide: true });
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
80
89
|
/** Writes the hook into the directory Git actually runs hooks from (`core.hooksPath` included, such as
|
|
81
90
|
* `.husky`). An existing hook DiffCI did not write is kept unless `force` is set. */
|
|
82
91
|
export function installPrePushHook(repoPath, command, force) {
|
|
@@ -69,14 +69,16 @@ const tools = [
|
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
name: "diffci_init",
|
|
72
|
-
description: "Seed a repository with
|
|
72
|
+
description: "Seed a repository with DiffCI agent instruction files, MCP server configs, the diffci-verify skill and the pre-push hook.",
|
|
73
73
|
inputSchema: {
|
|
74
74
|
type: "object",
|
|
75
75
|
properties: {
|
|
76
76
|
repo: { type: "string", description: "Repository path. Defaults to the MCP server working directory." },
|
|
77
77
|
workflow: { type: "boolean", description: "Also add the non-blocking GitHub Actions observer workflow." },
|
|
78
78
|
verificationWorkflow: { type: "boolean", description: "Also add the blocking GitHub Actions verification workflow." },
|
|
79
|
-
hook: { type: "boolean", description: "
|
|
79
|
+
hook: { type: "boolean", description: "Install the Git pre-push hook that verifies the commits being pushed (default true)." },
|
|
80
|
+
mcp: { type: "boolean", description: "Register the DiffCI MCP server in .mcp.json and .cursor/mcp.json (default true)." },
|
|
81
|
+
skill: { type: "boolean", description: "Add the diffci-verify skill to .claude/skills (default true)." },
|
|
80
82
|
force: { type: "boolean", description: "Overwrite existing instruction files." },
|
|
81
83
|
},
|
|
82
84
|
additionalProperties: false,
|
|
@@ -160,8 +162,12 @@ function commandForTool(name, args) {
|
|
|
160
162
|
command.push("--workflow");
|
|
161
163
|
if (booleanArg(args, "verificationWorkflow"))
|
|
162
164
|
command.push("--verification-workflow");
|
|
163
|
-
if (
|
|
164
|
-
command.push("--hook");
|
|
165
|
+
if (args.hook === false)
|
|
166
|
+
command.push("--no-hook");
|
|
167
|
+
if (args.mcp === false)
|
|
168
|
+
command.push("--no-mcp");
|
|
169
|
+
if (args.skill === false)
|
|
170
|
+
command.push("--no-skill");
|
|
165
171
|
if (booleanArg(args, "force"))
|
|
166
172
|
command.push("--force");
|
|
167
173
|
return command;
|
|
@@ -222,14 +222,19 @@ export async function observe(options) {
|
|
|
222
222
|
};
|
|
223
223
|
const impact = new ImpactAnalyzer().analyze(delta, graphResult, profile, analyzeOptions);
|
|
224
224
|
const baseline = runPathBaseline(profile.testFilePaths, delta.files, profile);
|
|
225
|
-
const
|
|
225
|
+
const affected = impact.affectedTests.map((test) => test.path).sort();
|
|
226
|
+
// `outsideSuitePaths` is newer than some bundled engines, which never return it.
|
|
227
|
+
const firstPlan = impact.fallbackRequired ? undefined : planSelectiveTestCommands(profile, affected);
|
|
228
|
+
// Affected tests the plan finds the full test command never runs (every Vitest project that would
|
|
229
|
+
// include them excludes them) move beside the selection, as impact.ts moves tests a node:test script
|
|
230
|
+
// never runs (2026-11-04, LobeHub: `apps/desktop` tests refused every plan).
|
|
231
|
+
const planOutside = new Set(firstPlan?.outsideSuitePaths ?? []);
|
|
232
|
+
const selectedTests = affected.filter((path) => !planOutside.has(path));
|
|
233
|
+
const commandPlan = planOutside.size ? planSelectiveTestCommands(profile, selectedTests) : firstPlan;
|
|
226
234
|
// The comparator's own identities, sorted and redacted identically so the two arms of an economics
|
|
227
235
|
// experiment are executed the same way rather than merely counted the same way.
|
|
228
236
|
const comparatorSelectedTests = [...baseline.selectedTests].sort().map(hashPath);
|
|
229
|
-
const
|
|
230
|
-
? undefined
|
|
231
|
-
: planSelectiveTestCommands(profile, selectedTests);
|
|
232
|
-
const outsideSuite = (impact.testsOutsideFullSuite ?? []).map((test) => test.path).sort();
|
|
237
|
+
const outsideSuite = [...(impact.testsOutsideFullSuite ?? []).map((test) => test.path), ...planOutside].sort();
|
|
233
238
|
const outsidePlan = outsideSuite.length ? planSelectiveTestCommands(profile, outsideSuite) : undefined;
|
|
234
239
|
markPhase("impactAndCommands");
|
|
235
240
|
return finish("OBSERVED", "complete", {
|
|
@@ -10,10 +10,30 @@
|
|
|
10
10
|
* `node --test`, the way Node's own glob matches them; a file no pattern claims means the selection is
|
|
11
11
|
* not executable as written. After running, the runner's own count is checked: a summary reporting
|
|
12
12
|
* fewer tests (node:test) or test files (vitest, jest) than files were selected means some never ran.
|
|
13
|
+
*
|
|
14
|
+
* 2026-11-02. Both checks passed under CLI 0.3.22 while the file still never ran on Linux. The command
|
|
15
|
+
* was `npx --no-install tsx --test "...[[]...path[]]..."`, and npx hands its arguments to a second
|
|
16
|
+
* `sh -c`, quoting only those with characters such as `(`, `*` or a space; that shell expanded the
|
|
17
|
+
* unquoted class back to the real `[...path]` directory. The pre-run check now models that second
|
|
18
|
+
* shell. The count check could not see one missing file among 120 tests, so a `node --test` selection
|
|
19
|
+
* also runs with a probe that records the file each test process started for (`traceNodeTestFiles`),
|
|
20
|
+
* and a selected file that never started blocks the verification.
|
|
13
21
|
*/
|
|
14
22
|
/** The arguments `sh` (or `cmd.exe` on Windows) would hand the program, for the quoting DiffCI emits. */
|
|
15
23
|
export declare function commandArguments(command: string, windows?: boolean): string[];
|
|
16
24
|
/** Selected files no `node --test` pattern in `command` matches. Empty when `command` runs no `node --test`. */
|
|
17
|
-
export declare function unmatchedNodeTests(command: string, selectedTests: readonly string[]): string[];
|
|
25
|
+
export declare function unmatchedNodeTests(command: string, selectedTests: readonly string[], windows?: boolean): string[];
|
|
26
|
+
/** Selected files `command` hands `node --test`, which the trace from `traceNodeTestFiles` must show. */
|
|
27
|
+
export declare function selectedNodeTests(command: string, selectedTests: readonly string[], windows?: boolean): string[];
|
|
28
|
+
export interface NodeTestTrace {
|
|
29
|
+
/** Environment for the command: NODE_OPTIONS extended with the probe. */
|
|
30
|
+
env: Record<string, string>;
|
|
31
|
+
/** Repository-relative paths of the files that started, or undefined when none did. */
|
|
32
|
+
read(): string[] | undefined;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|
|
35
|
+
export declare function traceNodeTestFiles(cwd: string, nodeOptions?: string | undefined): NodeTestTrace;
|
|
36
|
+
/** Selected `node --test` files the trace does not show starting. Empty when the trace proves nothing. */
|
|
37
|
+
export declare function unstartedNodeTests(expected: readonly string[], started: readonly string[] | undefined, windows?: boolean): string[];
|
|
18
38
|
/** The test count node:test's summary reports, or the test-file total vitest or jest reports. */
|
|
19
39
|
export declare function runnerTestCount(output: string): number | undefined;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join, matchesGlob, relative, sep } from "node:path";
|
|
2
4
|
/**
|
|
3
5
|
* Selected tests the runner would never execute (2026-11-01).
|
|
4
6
|
*
|
|
@@ -11,6 +13,14 @@ import { matchesGlob } from "node:path";
|
|
|
11
13
|
* `node --test`, the way Node's own glob matches them; a file no pattern claims means the selection is
|
|
12
14
|
* not executable as written. After running, the runner's own count is checked: a summary reporting
|
|
13
15
|
* fewer tests (node:test) or test files (vitest, jest) than files were selected means some never ran.
|
|
16
|
+
*
|
|
17
|
+
* 2026-11-02. Both checks passed under CLI 0.3.22 while the file still never ran on Linux. The command
|
|
18
|
+
* was `npx --no-install tsx --test "...[[]...path[]]..."`, and npx hands its arguments to a second
|
|
19
|
+
* `sh -c`, quoting only those with characters such as `(`, `*` or a space; that shell expanded the
|
|
20
|
+
* unquoted class back to the real `[...path]` directory. The pre-run check now models that second
|
|
21
|
+
* shell. The count check could not see one missing file among 120 tests, so a `node --test` selection
|
|
22
|
+
* also runs with a probe that records the file each test process started for (`traceNodeTestFiles`),
|
|
23
|
+
* and a selected file that never started blocks the verification.
|
|
14
24
|
*/
|
|
15
25
|
/** The arguments `sh` (or `cmd.exe` on Windows) would hand the program, for the quoting DiffCI emits. */
|
|
16
26
|
export function commandArguments(command, windows = process.platform === "win32") {
|
|
@@ -47,29 +57,92 @@ export function commandArguments(command, windows = process.platform === "win32"
|
|
|
47
57
|
args.push(current);
|
|
48
58
|
return args;
|
|
49
59
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
/** Arguments npm's `sh` escaping leaves unquoted when npx re-runs a bin through `sh -c`
|
|
61
|
+
* (@npmcli/promise-spawn): those without whitespace or any of ``"#$&'()*;<>?\`|~``. */
|
|
62
|
+
const NPM_UNQUOTED = /^[^\s"#$&'()*;<>?\\`|~]+$/;
|
|
63
|
+
/** The file patterns of each `node --test` invocation in `command` (directly, or through tsx). Paths
|
|
64
|
+
* npx passes to a second `sh` unquoted are marked: that shell expands a pattern that matches files. */
|
|
65
|
+
function nodeTestPatterns(command, windows) {
|
|
66
|
+
const patterns = [];
|
|
53
67
|
let segment = [];
|
|
54
|
-
for (const arg of [...commandArguments(command), "&&"]) {
|
|
68
|
+
for (const arg of [...commandArguments(command, windows), "&&"]) {
|
|
55
69
|
if (arg !== "&&") {
|
|
56
70
|
segment.push(arg);
|
|
57
71
|
continue;
|
|
58
72
|
}
|
|
59
73
|
const testFlag = segment.indexOf("--test");
|
|
60
74
|
if (testFlag > 0 && (segment[0] === "node" || segment.slice(0, testFlag).includes("tsx"))) {
|
|
61
|
-
|
|
75
|
+
const viaNpx = !windows && (segment[0] === "npx" || (segment[0] === "npm" && segment[1] === "exec"));
|
|
76
|
+
for (const pattern of segment.slice(testFlag + 1).filter((value) => !value.startsWith("-"))) {
|
|
77
|
+
patterns.push({ pattern, reglobbed: viaNpx && NPM_UNQUOTED.test(pattern) });
|
|
78
|
+
}
|
|
62
79
|
}
|
|
63
80
|
segment = [];
|
|
64
81
|
}
|
|
65
|
-
return
|
|
82
|
+
return patterns;
|
|
83
|
+
}
|
|
84
|
+
/** Whether node --test, handed `pattern` by `command`, would run `path`. A pattern the second shell
|
|
85
|
+
* expands reaches node as the literal path it matched, which node then reads as a glob again. */
|
|
86
|
+
function claims({ pattern, reglobbed }, path) {
|
|
87
|
+
return matchesGlob(path, pattern) && (!reglobbed || matchesGlob(path, path));
|
|
66
88
|
}
|
|
67
89
|
/** Selected files no `node --test` pattern in `command` matches. Empty when `command` runs no `node --test`. */
|
|
68
|
-
export function unmatchedNodeTests(command, selectedTests) {
|
|
69
|
-
const patterns = nodeTestPatterns(command)
|
|
90
|
+
export function unmatchedNodeTests(command, selectedTests, windows = process.platform === "win32") {
|
|
91
|
+
const patterns = nodeTestPatterns(command, windows);
|
|
70
92
|
if (patterns.length === 0)
|
|
71
93
|
return [];
|
|
72
|
-
return selectedTests.filter((path) => !patterns.some((pattern) =>
|
|
94
|
+
return selectedTests.filter((path) => !patterns.some((pattern) => claims(pattern, path)));
|
|
95
|
+
}
|
|
96
|
+
/** Selected files `command` hands `node --test`, which the trace from `traceNodeTestFiles` must show. */
|
|
97
|
+
export function selectedNodeTests(command, selectedTests, windows = process.platform === "win32") {
|
|
98
|
+
const patterns = nodeTestPatterns(command, windows);
|
|
99
|
+
return selectedTests.filter((path) => patterns.some(({ pattern }) => pattern === path || matchesGlob(path, pattern)));
|
|
100
|
+
}
|
|
101
|
+
/** Records the file each node:test process starts for. node --test runs every file in a child process
|
|
102
|
+
* with NODE_TEST_CONTEXT set and the file as argv[1]; NODE_OPTIONS reaches it through npx and tsx.
|
|
103
|
+
* Under `--test-isolation=none` no child starts and the trace stays empty, which proves nothing. */
|
|
104
|
+
const PROBE = `"use strict";
|
|
105
|
+
if (process.env.NODE_TEST_CONTEXT && process.argv[1] && process.env.DIFFCI_NODE_TEST_TRACE) {
|
|
106
|
+
try { require("node:fs").appendFileSync(process.env.DIFFCI_NODE_TEST_TRACE, process.argv[1] + "\\n"); } catch {}
|
|
107
|
+
}
|
|
108
|
+
`;
|
|
109
|
+
export function traceNodeTestFiles(cwd, nodeOptions = process.env.NODE_OPTIONS) {
|
|
110
|
+
const dir = mkdtempSync(join(tmpdir(), "diffci-node-test-trace-"));
|
|
111
|
+
const probe = join(dir, "probe.cjs");
|
|
112
|
+
const log = join(dir, "started.txt");
|
|
113
|
+
writeFileSync(probe, PROBE);
|
|
114
|
+
// NODE_OPTIONS reads a backslash inside double quotes as an escape; forward slashes work on Windows.
|
|
115
|
+
const required = `--require "${probe.split(sep).join("/")}"`;
|
|
116
|
+
const real = (path) => { try {
|
|
117
|
+
return realpathSync.native(path);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return path;
|
|
121
|
+
} };
|
|
122
|
+
return {
|
|
123
|
+
env: { NODE_OPTIONS: nodeOptions?.trim() ? `${nodeOptions} ${required}` : required, DIFFCI_NODE_TEST_TRACE: log },
|
|
124
|
+
read() {
|
|
125
|
+
let lines;
|
|
126
|
+
try {
|
|
127
|
+
lines = readFileSync(log, "utf8").split("\n").filter(Boolean);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const root = real(cwd);
|
|
133
|
+
const files = lines.map((file) => relative(root, real(file)).split(sep).join("/"));
|
|
134
|
+
return files.length ? [...new Set(files)].sort() : undefined;
|
|
135
|
+
},
|
|
136
|
+
dispose() { rmSync(dir, { recursive: true, force: true }); },
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Selected `node --test` files the trace does not show starting. Empty when the trace proves nothing. */
|
|
140
|
+
export function unstartedNodeTests(expected, started, windows = process.platform === "win32") {
|
|
141
|
+
if (!started?.length)
|
|
142
|
+
return [];
|
|
143
|
+
const key = (path) => windows ? path.toLowerCase() : path;
|
|
144
|
+
const seen = new Set(started.map(key));
|
|
145
|
+
return expected.filter((path) => !seen.has(key(path)));
|
|
73
146
|
}
|
|
74
147
|
/** The test count node:test's summary reports, or the test-file total vitest or jest reports. */
|
|
75
148
|
export function runnerTestCount(output) {
|
|
@@ -159,7 +159,9 @@ interface ResolvedSelection {
|
|
|
159
159
|
observationSha256?: string;
|
|
160
160
|
observerVersion?: string;
|
|
161
161
|
}
|
|
162
|
-
export declare function measureCommand(command: string, options: Pick<VerifySavingsOptions, "cwd" | "timeoutMs" | "tailBytes">
|
|
162
|
+
export declare function measureCommand(command: string, options: Pick<VerifySavingsOptions, "cwd" | "timeoutMs" | "tailBytes"> & {
|
|
163
|
+
env?: Record<string, string>;
|
|
164
|
+
}): CommandMeasurement;
|
|
163
165
|
export declare function buildVerifySavingsReport(input: {
|
|
164
166
|
producedAt?: string;
|
|
165
167
|
label?: string;
|
|
@@ -262,6 +262,7 @@ export function measureCommand(command, options) {
|
|
|
262
262
|
windowsVerbatimArguments: process.platform === "win32",
|
|
263
263
|
env: {
|
|
264
264
|
...withoutTestRunnerContext(process.env),
|
|
265
|
+
...options.env,
|
|
265
266
|
CI: "1",
|
|
266
267
|
FORCE_COLOR: "0",
|
|
267
268
|
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
|