@diffci.com/diffci 0.3.63 → 0.3.65
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/cli.js +4 -1
- package/dist-client/src/client/hook.d.ts +13 -0
- package/dist-client/src/client/hook.js +25 -0
- package/dist-client/src/client/mcp.js +14 -0
- package/dist-client/src/client/telemetry.d.ts +1 -1
- package/dist-client/src/client/telemetry.js +2 -1
- package/dist-client/src/client/usage-signal.d.ts +10 -2
- package/dist-client/src/client/usage-signal.js +11 -0
- package/package.json +2 -2
|
@@ -46,7 +46,7 @@ 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, refreshPrePushHook } from "./hook.js";
|
|
49
|
+
import { clearGitLocationEnvironment, 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 { worktreeChangeSuspected } from "./report.js";
|
|
52
52
|
import { submitObservation } from "./submit.js";
|
|
@@ -1698,6 +1698,9 @@ function maybeShowFeedbackPrompt(flags, env) {
|
|
|
1698
1698
|
markFeedbackPromptShown(env);
|
|
1699
1699
|
}
|
|
1700
1700
|
async function main() {
|
|
1701
|
+
// Before anything runs git or a test: a hook's GIT_DIR would point every git command, the tests' own
|
|
1702
|
+
// temporary repositories included, at the pushing worktree's repository (hook.ts, GIT_LOCATION_ENV).
|
|
1703
|
+
clearGitLocationEnvironment(process.env);
|
|
1701
1704
|
// This stateless command deliberately bypasses shared flag handling, telemetry and feedback.
|
|
1702
1705
|
if (process.argv[2] === "check-plan") {
|
|
1703
1706
|
process.exitCode = runCheckPlanCommand(process.argv.slice(3));
|
|
@@ -29,6 +29,19 @@
|
|
|
29
29
|
* reporting from the push keeps that data. It runs after verification and can never block the push.
|
|
30
30
|
*/
|
|
31
31
|
export declare const HOOK_MARKER = "# diffci:managed pre-push hook";
|
|
32
|
+
/**
|
|
33
|
+
* Git's repository-location variables (2026-11-23), as `git rev-parse --local-env-vars` lists them, minus the
|
|
34
|
+
* GIT_CONFIG_* ones CI uses for authentication.
|
|
35
|
+
*
|
|
36
|
+
* WHY. Git runs a hook in a linked worktree with GIT_DIR set to that worktree's git directory. DiffCI then ran
|
|
37
|
+
* the test suite with it, so a test's `git init` in a temporary directory re-initialised the real repository:
|
|
38
|
+
* pushing from a DentalPresence worktree wrote `core.bare = true` into the shared .git/config, and every
|
|
39
|
+
* session's `git status` failed with "must be run in a work tree". DiffCI always finds the repository from
|
|
40
|
+
* --repo or the working directory, so it needs none of these, and neither do the commands it runs.
|
|
41
|
+
*/
|
|
42
|
+
export declare const GIT_LOCATION_ENV: readonly ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR", "GIT_OBJECT_DIRECTORY", "GIT_ALTERNATE_OBJECT_DIRECTORIES", "GIT_PREFIX", "GIT_IMPLICIT_WORK_TREE", "GIT_GRAFT_FILE", "GIT_SHALLOW_FILE", "GIT_NO_REPLACE_OBJECTS", "GIT_REPLACE_REF_BASE", "GIT_INTERNAL_SUPER_PREFIX"];
|
|
43
|
+
/** Removes git's repository-location variables from `env`; returns the ones that were set. */
|
|
44
|
+
export declare function clearGitLocationEnvironment(env: NodeJS.ProcessEnv): string[];
|
|
32
45
|
export declare function prePushHook(command: string): string;
|
|
33
46
|
/** What to tell someone whose checkout cannot run DiffCI, by the command the hook was written for. */
|
|
34
47
|
export declare function installHint(command: string): string;
|
|
@@ -32,12 +32,37 @@ import { dirname, isAbsolute, join, relative } from "node:path";
|
|
|
32
32
|
* reporting from the push keeps that data. It runs after verification and can never block the push.
|
|
33
33
|
*/
|
|
34
34
|
export const HOOK_MARKER = "# diffci:managed pre-push hook";
|
|
35
|
+
/**
|
|
36
|
+
* Git's repository-location variables (2026-11-23), as `git rev-parse --local-env-vars` lists them, minus the
|
|
37
|
+
* GIT_CONFIG_* ones CI uses for authentication.
|
|
38
|
+
*
|
|
39
|
+
* WHY. Git runs a hook in a linked worktree with GIT_DIR set to that worktree's git directory. DiffCI then ran
|
|
40
|
+
* the test suite with it, so a test's `git init` in a temporary directory re-initialised the real repository:
|
|
41
|
+
* pushing from a DentalPresence worktree wrote `core.bare = true` into the shared .git/config, and every
|
|
42
|
+
* session's `git status` failed with "must be run in a work tree". DiffCI always finds the repository from
|
|
43
|
+
* --repo or the working directory, so it needs none of these, and neither do the commands it runs.
|
|
44
|
+
*/
|
|
45
|
+
export const GIT_LOCATION_ENV = [
|
|
46
|
+
"GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR", "GIT_OBJECT_DIRECTORY", "GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
47
|
+
"GIT_PREFIX", "GIT_IMPLICIT_WORK_TREE", "GIT_GRAFT_FILE", "GIT_SHALLOW_FILE", "GIT_NO_REPLACE_OBJECTS", "GIT_REPLACE_REF_BASE",
|
|
48
|
+
"GIT_INTERNAL_SUPER_PREFIX",
|
|
49
|
+
];
|
|
50
|
+
/** Removes git's repository-location variables from `env`; returns the ones that were set. */
|
|
51
|
+
export function clearGitLocationEnvironment(env) {
|
|
52
|
+
const cleared = GIT_LOCATION_ENV.filter((name) => env[name] !== undefined);
|
|
53
|
+
for (const name of cleared)
|
|
54
|
+
delete env[name];
|
|
55
|
+
return cleared;
|
|
56
|
+
}
|
|
35
57
|
export function prePushHook(command) {
|
|
36
58
|
const install = installHint(command);
|
|
37
59
|
return `#!/bin/sh
|
|
38
60
|
${HOOK_MARKER}
|
|
39
61
|
# Verifies the commits being pushed with DiffCI's affected tests. Skip once: git push --no-verify
|
|
40
62
|
# Block when DiffCI cannot verify, not only when tests fail: DIFFCI_HOOK_STRICT=1
|
|
63
|
+
# In a linked worktree Git sets GIT_DIR for the hook; DiffCI and the tests it runs find the repository
|
|
64
|
+
# from the working directory, and a test's own git commands must not reach this repository through it.
|
|
65
|
+
unset ${GIT_LOCATION_ENV.join(" ")}
|
|
41
66
|
remote="$1"
|
|
42
67
|
zero=0000000000000000000000000000000000000000
|
|
43
68
|
head=$(git rev-parse HEAD)
|
|
@@ -4,7 +4,12 @@ import { dirname, join, resolve } from "node:path";
|
|
|
4
4
|
import { StringDecoder } from "node:string_decoder";
|
|
5
5
|
import { agentChangedFiles, agentScopedSelection, agentSelection, selectionInstruction } from "./agent-selection.js";
|
|
6
6
|
import { requireDiffciPackageIdentity } from "./package-identity.js";
|
|
7
|
+
import { recordUsage } from "./telemetry.js";
|
|
8
|
+
import { mcpClientName, verificationSelection } from "./usage-signal.js";
|
|
7
9
|
const SERVER_INFO = { name: "diffci-mcp", version: requireDiffciPackageIdentity().version };
|
|
10
|
+
// Counted like the CLI tools this server starts (docs/telemetry.md): surface local-mcp, same opt-outs.
|
|
11
|
+
const usageEnv = { ...process.env, DIFFCI_MCP: "1" };
|
|
12
|
+
let startCounted = false;
|
|
8
13
|
const tools = [
|
|
9
14
|
...["diffci_changed_files", "diffci_select_tests", "diffci_explain_selection", "diffci_run_affected_tests"].map((name) => ({
|
|
10
15
|
name,
|
|
@@ -224,6 +229,12 @@ async function handle(request) {
|
|
|
224
229
|
capabilities: { tools: {} },
|
|
225
230
|
serverInfo: SERVER_INFO,
|
|
226
231
|
});
|
|
232
|
+
// One start per server process: an agent installed DiffCI and connected, whether or not it calls a tool.
|
|
233
|
+
if (!startCounted) {
|
|
234
|
+
startCounted = true;
|
|
235
|
+
const clientInfo = request.params?.clientInfo;
|
|
236
|
+
void recordUsage("mcp", "started", SERVER_INFO.version, {}, usageEnv, process.cwd(), undefined, undefined, mcpClientName(clientInfo?.name));
|
|
237
|
+
}
|
|
227
238
|
return;
|
|
228
239
|
case "notifications/initialized":
|
|
229
240
|
return;
|
|
@@ -274,6 +285,9 @@ async function handle(request) {
|
|
|
274
285
|
: scope === "paths" ? await agentScopedSelection(repo, { kind: "paths", paths: paths.map((path) => path.replace(/\\/g, "/")) })
|
|
275
286
|
: await agentSelection(repo);
|
|
276
287
|
success(id, { content: [{ type: "text", text: `${selectionInstruction(plan)}\n\n${JSON.stringify(plan)}` }], structuredContent: plan, isError: plan.status === "blocked" });
|
|
288
|
+
// In-process plans never start the CLI, so they are counted here (before 0.3.65 they were not counted at all).
|
|
289
|
+
const blocked = plan.status === "blocked";
|
|
290
|
+
void recordUsage("plan", blocked ? "error" : plan.selection === "full" ? "full" : "selective", SERVER_INFO.version, {}, usageEnv, repo, blocked ? undefined : verificationSelection(plan));
|
|
277
291
|
return;
|
|
278
292
|
}
|
|
279
293
|
const run = await runCli(commandForTool(params.name, args));
|
|
@@ -29,5 +29,5 @@ export declare function normaliseRemote(remote: string): string | undefined;
|
|
|
29
29
|
export declare function repositoryName(repoPath: string | undefined, env: NodeJS.ProcessEnv): string | undefined;
|
|
30
30
|
export declare function telemetryNotice(mode: TelemetryMode): string;
|
|
31
31
|
/** Best effort: never throws and never changes the exit code. `flags` are read for --internal-usage only. */
|
|
32
|
-
export declare function recordUsage(command: UsageCommand, outcome: UsageOutcome, version: string, flags: Flags, env: NodeJS.ProcessEnv, repoPath?: string, selection?: UsageSelection, streak?: UsageStreak): Promise<void>;
|
|
32
|
+
export declare function recordUsage(command: UsageCommand, outcome: UsageOutcome, version: string, flags: Flags, env: NodeJS.ProcessEnv, repoPath?: string, selection?: UsageSelection, streak?: UsageStreak, client?: string): Promise<void>;
|
|
33
33
|
export {};
|
|
@@ -114,7 +114,7 @@ export function telemetryNotice(mode) {
|
|
|
114
114
|
: `DiffCI counts runs without repository names or content. DO_NOT_TRACK=1 stops counting. ${TELEMETRY_DOCS}`;
|
|
115
115
|
}
|
|
116
116
|
/** Best effort: never throws and never changes the exit code. `flags` are read for --internal-usage only. */
|
|
117
|
-
export async function recordUsage(command, outcome, version, flags, env, repoPath, selection, streak) {
|
|
117
|
+
export async function recordUsage(command, outcome, version, flags, env, repoPath, selection, streak, client) {
|
|
118
118
|
try {
|
|
119
119
|
if (usageCountingDisabled(env))
|
|
120
120
|
return;
|
|
@@ -135,6 +135,7 @@ export async function recordUsage(command, outcome, version, flags, env, repoPat
|
|
|
135
135
|
...(repository ? { repository } : {}),
|
|
136
136
|
...(selection ? { selection } : {}),
|
|
137
137
|
...(streak ? { streak } : {}),
|
|
138
|
+
...(client ? { client } : {}),
|
|
138
139
|
});
|
|
139
140
|
}
|
|
140
141
|
catch { /* usage counting never affects a run */ }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Best-effort usage signal. Carries a repository name only when given one; never content, paths or machine details. */
|
|
2
|
-
|
|
3
|
-
export type
|
|
2
|
+
/** "mcp": the local MCP server was initialized by an agent client (outcome "started"). */
|
|
3
|
+
export type UsageCommand = "check" | "observe" | "verify" | "plan" | "mcp";
|
|
4
|
+
export type UsageOutcome = "observed" | "refused" | "error" | "passed" | "failed" | "blocked" | "selective" | "full" | "started";
|
|
4
5
|
export type UsageSurface = "cli" | "local-mcp" | "github-action" | "gitlab-component" | "azure-devops-task";
|
|
5
6
|
/**
|
|
6
7
|
* How much of the suite a run chose: counts only, never test names. `baselineTestsSelected` is what a simple
|
|
@@ -32,6 +33,8 @@ export interface UsageSignal {
|
|
|
32
33
|
repository?: string;
|
|
33
34
|
selection?: UsageSelection;
|
|
34
35
|
streak?: UsageStreak;
|
|
36
|
+
/** "mcp" only: the agent client's name from MCP initialize, normalised by mcpClientName. */
|
|
37
|
+
client?: string;
|
|
35
38
|
endpoint?: string;
|
|
36
39
|
fetchImpl?: typeof fetch;
|
|
37
40
|
}
|
|
@@ -39,6 +42,11 @@ export interface DeliveryResult {
|
|
|
39
42
|
status: "delivered" | "accepted" | "failed" | "timed-out";
|
|
40
43
|
httpStatus?: number;
|
|
41
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* An MCP client's self-reported clientInfo.name as a short lower-case product name ("Claude Code" -> "claude code"),
|
|
47
|
+
* or undefined. It names the agent application, never the person or machine.
|
|
48
|
+
*/
|
|
49
|
+
export declare function mcpClientName(name: unknown): string | undefined;
|
|
42
50
|
/** From an observation result (observe, check). No result, or no tests found: nothing to count. */
|
|
43
51
|
export declare function observationSelection(result: {
|
|
44
52
|
mode: "SELECTIVE" | "FULL";
|
|
@@ -20,6 +20,16 @@ function streakFields(command, outcome, streak) {
|
|
|
20
20
|
return { failed_before: streak.failedBefore,
|
|
21
21
|
...(count(streak.fixSeconds) && streak.fixSeconds <= MAX_FIX_SECONDS ? { fix_seconds: streak.fixSeconds } : {}) };
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* An MCP client's self-reported clientInfo.name as a short lower-case product name ("Claude Code" -> "claude code"),
|
|
25
|
+
* or undefined. It names the agent application, never the person or machine.
|
|
26
|
+
*/
|
|
27
|
+
export function mcpClientName(name) {
|
|
28
|
+
if (typeof name !== "string")
|
|
29
|
+
return undefined;
|
|
30
|
+
const value = name.trim().toLowerCase().replace(/[^a-z0-9 ._-]+/g, "-").replace(/^[^a-z0-9]+/, "").slice(0, 48).trim();
|
|
31
|
+
return /^[a-z0-9][a-z0-9 ._-]{0,47}$/.test(value) ? value : undefined;
|
|
32
|
+
}
|
|
23
33
|
/** From an observation result (observe, check). No result, or no tests found: nothing to count. */
|
|
24
34
|
export function observationSelection(result) {
|
|
25
35
|
if (!result || !(result.totalTestCount > 0))
|
|
@@ -60,6 +70,7 @@ export async function deliverUsageSignal(input) {
|
|
|
60
70
|
...(input.repository ? { repository: input.repository } : {}),
|
|
61
71
|
...selectionFields(input.selection),
|
|
62
72
|
...streakFields(input.command, input.outcome, input.streak),
|
|
73
|
+
...(input.command === "mcp" && input.client ? { client: input.client } : {}),
|
|
63
74
|
}),
|
|
64
75
|
signal: AbortSignal.timeout(3000),
|
|
65
76
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diffci.com/diffci",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.65",
|
|
4
4
|
"description": "Verification for AI coding agents: runs the tests and checks a change affects, with full fallback and a receipt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"bundleDependencies": [
|
|
89
89
|
"@diffci.com/core"
|
|
90
90
|
],
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "ac880fa5814a2e3cc3e1d1bc28516792a626778a"
|
|
92
92
|
}
|