@diffci.com/diffci 0.3.64 → 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.
@@ -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
- export type UsageCommand = "check" | "observe" | "verify" | "plan";
3
- export type UsageOutcome = "observed" | "refused" | "error" | "passed" | "failed" | "blocked" | "selective" | "full";
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.64",
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": "822f9514d8051c84d284c2b769b3c1a6fa0ab4aa"
91
+ "gitHead": "ac880fa5814a2e3cc3e1d1bc28516792a626778a"
92
92
  }