@diffci.com/diffci 0.2.5 → 0.2.7

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/README.md CHANGED
@@ -30,6 +30,17 @@ To add instructions for coding agents, run:
30
30
  npx @diffci.com/diffci@latest init
31
31
  ```
32
32
 
33
+ To also pin DiffCI as a development dependency and update the detected npm, pnpm, Yarn, or Bun
34
+ lockfile, pass `--install`. Add `--workflow` for a separate non-blocking observation job:
35
+
36
+ ```bash
37
+ npx @diffci.com/diffci@latest init --install --workflow
38
+ ```
39
+
40
+ `--install` also adds `diffci:check` and `diffci:observe` package scripts. It preserves same-named
41
+ scripts that the project already owns. After installation, CI or contributors can run
42
+ `npm run diffci:check` or `npm run diffci:observe` without knowing the package name or version.
43
+
33
44
  On Windows PowerShell, quote the package name:
34
45
 
35
46
  ```powershell
@@ -93,13 +104,13 @@ jobs:
93
104
  - uses: actions/checkout@v4
94
105
  with:
95
106
  fetch-depth: 0
96
- - uses: DiffCI/DiffCI.com@3aa76a84919691cf7e8f9d1f1f6a80399325d1ae
107
+ - uses: DiffCI/DiffCI.com@e852523fade14bf5e0457a6331e97c8a76eedc2b
97
108
  ```
98
109
 
99
110
  Then check the workflow locally with `npx @diffci.com/diffci@latest verify-workflow`. Keep the observer
100
111
  out of required checks and other jobs' `needs` lists. The Action adds a job summary and a
101
112
  `diffci-observation` artifact to the run; it does not alter which tests your other jobs execute.
102
- The example pins release `v0.2.2` to its full commit SHA for reproducibility.
113
+ The example pins release `v0.2.7` to its qualified feature commit SHA for reproducibility.
103
114
 
104
115
  The CLI sends no report with `--no-send`. The Action uploads a GitHub artifact by default; sending to
105
116
  DiffCI's hosted service requires an explicitly configured endpoint and token.
@@ -295,7 +306,7 @@ npm run research:sandbox:deploy
295
306
  DiffCI is intended to be installable as infrastructure, not only as a hosted shadow experiment:
296
307
 
297
308
  ```yaml
298
- - uses: DiffCI/DiffCI.com@3aa76a84919691cf7e8f9d1f1f6a80399325d1ae
309
+ - uses: DiffCI/DiffCI.com@e852523fade14bf5e0457a6331e97c8a76eedc2b
299
310
  ```
300
311
 
301
312
  ```bash
@@ -30,7 +30,9 @@ import { tmpdir } from "node:os";
30
30
  import { basename, dirname, join, resolve } from "node:path";
31
31
  import { observe, isInsideRepository } from "./observe.js";
32
32
  import { inferFullCommand, inferSelectedCommand } from "./full-command.js";
33
+ import { addDiffciPackageScripts, installDiffci } from "./install.js";
33
34
  import { submitObservation } from "./submit.js";
35
+ import { sendUsageSignal } from "./usage-signal.js";
34
36
  import { formatVerifySavingsSummary, measureCommand, runVerifySavings, writeVerifySavingsReport } from "./verify-savings.js";
35
37
  import { auditWorkflows, isNonInterfering } from "./workflow-guard.js";
36
38
  function parseArgs(argv) {
@@ -194,9 +196,29 @@ function runInit(flags, env) {
194
196
  ];
195
197
  if (includeWorkflow)
196
198
  writes.push(writeInitFile(repoPath, ".github/workflows/diffci.yml", diffciWorkflow(identity.version), force));
199
+ let installed;
200
+ if (flags.install === true) {
201
+ const { plan, result } = installDiffci(repoPath, identity.version);
202
+ if (result.error)
203
+ throw result.error;
204
+ if (result.status !== 0) {
205
+ const detail = result.stderr.trim() || result.stdout.trim() || `${plan.manager} exited with status ${result.status ?? "unknown"}`;
206
+ throw new Error(`could not install ${plan.packageSpec}: ${detail}`);
207
+ }
208
+ const scripts = addDiffciPackageScripts(repoPath);
209
+ installed = `installed ${plan.packageSpec} as an exact dev dependency with ${plan.manager}`;
210
+ if (scripts.added.length > 0)
211
+ installed += `; added package scripts ${scripts.added.join(", ")}`;
212
+ if (scripts.kept.length > 0)
213
+ installed += `; kept existing package scripts ${scripts.kept.join(", ")}`;
214
+ }
197
215
  console.log(`DiffCI initialized for AI coding agents in ${repoPath}`);
198
216
  for (const write of writes)
199
217
  console.log(` ${write}`);
218
+ if (installed)
219
+ console.log(` ${installed}`);
220
+ else
221
+ console.log(" skipped package installation (pass --install to add an exact dev dependency)");
200
222
  if (!includeWorkflow)
201
223
  console.log(" skipped .github/workflows/diffci.yml (pass --workflow to add it)");
202
224
  console.log("\nDefault agent command: npx @diffci.com/diffci@latest check");
@@ -281,6 +303,9 @@ async function runCheck(flags, env) {
281
303
  if (observationCode !== 0)
282
304
  return observationCode;
283
305
  const observation = JSON.parse(readFileSync(reportPath, "utf8"));
306
+ if ((flags["share-usage"] === true || env.DIFFCI_SHARE_USAGE === "1") && flags["no-send"] !== true) {
307
+ await sendUsageSignal({ command: "check", outcome: observation.status === "OBSERVED" ? "observed" : observation.status === "REFUSED" ? "refused" : "error", version: observerIdentity().version });
308
+ }
284
309
  const print = (message) => { if (flags.quiet !== true && flags.json !== true)
285
310
  console.log(message); };
286
311
  print(summarise(observation, true));
@@ -394,6 +419,9 @@ async function runObserve(flags, env) {
394
419
  });
395
420
  mkdirSync(dirname(reportPath), { recursive: true });
396
421
  writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`, "utf8");
422
+ if ((flags["share-usage"] === true || env.DIFFCI_SHARE_USAGE === "1") && flags["no-send"] !== true) {
423
+ await sendUsageSignal({ command: "observe", outcome: report.status === "OBSERVED" ? "observed" : report.status === "REFUSED" ? "refused" : "error", version: identity.version });
424
+ }
397
425
  const summary = summarise(report);
398
426
  if (flags.json === true) {
399
427
  console.log(JSON.stringify(report, null, 2));
@@ -588,14 +616,14 @@ async function runPilot(flags, env) {
588
616
  const USAGE = `diffci - change-aware CI analysis and paired timing
589
617
 
590
618
  Usage:
591
- diffci init [--repo <path>] [--workflow] [--force]
619
+ diffci init [--repo <path>] [--workflow] [--install] [--force]
592
620
  diffci mcp
593
621
  diffci check [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
594
- [--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>]
622
+ [--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>] [--share-usage]
595
623
  diffci pilot --full <command> [--repo <path>] [--out-dir <dir>] [--label <name>]
596
624
  diffci observe [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
597
625
  [--redact-paths] [--json] [--quiet] [--fail-on-error]
598
- [--api-url <url> --api-token <token>] [--no-send]
626
+ [--api-url <url> --api-token <token>] [--no-send] [--share-usage]
599
627
  diffci verify-savings --repo <path> --full <command>
600
628
  (--selected <command> | --selected-from-report <file>)
601
629
  --out <file> [--markdown <file>] [--label <name>]
@@ -603,6 +631,9 @@ Usage:
603
631
  diffci version
604
632
 
605
633
  init writes AGENTS.md, CLAUDE.md, Cursor rules, Copilot instructions, and diffci.config.json.
634
+ --workflow adds a separate non-blocking observation workflow. --install detects npm, pnpm, Yarn,
635
+ or Bun, installs this DiffCI version as an exact dev dependency, updates the manager's lockfile,
636
+ and adds diffci:check and diffci:observe package scripts without replacing existing scripts.
606
637
  mcp runs the stdio MCP server for native agent integrations.
607
638
  check analyzes the change, runs inferred full and selected commands, and shows measured savings.
608
639
  pilot runs observe and verify-savings together, writing reports to ../diffci-output by default.
@@ -613,6 +644,8 @@ verify-workflow checks that the job running DiffCI cannot affect any other job,
613
644
  The report is sent only when both --api-url and --api-token are given (or DIFFCI_API_URL and
614
645
  DIFFCI_TOKEN are set). A failed send is reported and never fails the step - the report is on disk
615
646
  either way. Plain http is refused; the token is never printed.
647
+ --share-usage (or DIFFCI_SHARE_USAGE=1) sends only command, outcome, and version to DiffCI.
648
+ No repository, commit, test, report, or persistent identifier is sent. --no-send disables it.
616
649
  `;
617
650
  async function main() {
618
651
  const { command, flags } = parseArgs(process.argv);
@@ -0,0 +1,101 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ const DIFFCI_SCRIPTS = {
5
+ "diffci:check": "diffci check",
6
+ "diffci:observe": "diffci observe --no-send",
7
+ };
8
+ const LOCKFILES = [
9
+ ["pnpm", "pnpm-lock.yaml"],
10
+ ["yarn", "yarn.lock"],
11
+ ["bun", "bun.lock"],
12
+ ["bun", "bun.lockb"],
13
+ ["npm", "package-lock.json"],
14
+ ["npm", "npm-shrinkwrap.json"],
15
+ ];
16
+ function declaredPackageManager(repoPath) {
17
+ const packagePath = join(repoPath, "package.json");
18
+ if (!existsSync(packagePath))
19
+ throw new Error("--install requires a package.json in the repository root");
20
+ const pkg = JSON.parse(readFileSync(packagePath, "utf8"));
21
+ if (typeof pkg.packageManager !== "string")
22
+ return undefined;
23
+ const name = pkg.packageManager.split("@", 1)[0];
24
+ if (["npm", "pnpm", "yarn", "bun"].includes(name))
25
+ return name;
26
+ throw new Error(`unsupported packageManager ${JSON.stringify(pkg.packageManager)}; supported managers are npm, pnpm, yarn, and bun`);
27
+ }
28
+ export function detectPackageManager(repoPath) {
29
+ const declared = declaredPackageManager(repoPath);
30
+ if (declared)
31
+ return declared;
32
+ const detected = new Set();
33
+ for (const [manager, lockfile] of LOCKFILES) {
34
+ if (existsSync(join(repoPath, lockfile)))
35
+ detected.add(manager);
36
+ }
37
+ if (detected.size > 1) {
38
+ throw new Error(`multiple package-manager lockfiles found (${[...detected].join(", ")}); set packageManager in package.json to choose one`);
39
+ }
40
+ return detected.values().next().value ?? "npm";
41
+ }
42
+ export function installPlan(repoPath, version, platform = process.platform) {
43
+ const manager = detectPackageManager(repoPath);
44
+ const packageSpec = `@diffci.com/diffci@${version}`;
45
+ const managerCommand = platform === "win32" ? `${manager}.cmd` : manager;
46
+ const argsByManager = {
47
+ npm: ["install", "--save-dev", "--save-exact", "--ignore-scripts", packageSpec],
48
+ pnpm: ["add", "--save-dev", "--save-exact", "--ignore-scripts", packageSpec],
49
+ yarn: ["add", "--dev", "--exact", "--ignore-scripts", packageSpec],
50
+ bun: ["add", "--dev", "--exact", "--ignore-scripts", packageSpec],
51
+ };
52
+ const managerArgs = argsByManager[manager];
53
+ if (platform === "win32") {
54
+ // npm/pnpm/yarn/bun are .cmd shims on Windows. Node does not execute those reliably without
55
+ // cmd.exe, so use its explicit /d /s /c form. Every token is generated here (not user input).
56
+ return { manager, command: process.env.ComSpec ?? "cmd.exe", args: ["/d", "/s", "/c", [managerCommand, ...managerArgs].join(" ")], packageSpec };
57
+ }
58
+ return { manager, command: managerCommand, args: managerArgs, packageSpec };
59
+ }
60
+ export function installDiffci(repoPath, version, run = spawnSync, packageSpecOverride) {
61
+ const basePlan = installPlan(repoPath, version);
62
+ const plan = packageSpecOverride === undefined
63
+ ? basePlan
64
+ : {
65
+ ...basePlan,
66
+ packageSpec: packageSpecOverride,
67
+ args: basePlan.args.map((arg) => arg.replace(basePlan.packageSpec, packageSpecOverride)),
68
+ };
69
+ const result = run(plan.command, plan.args, {
70
+ cwd: repoPath,
71
+ encoding: "utf8",
72
+ stdio: ["inherit", "pipe", "pipe"],
73
+ windowsHide: true,
74
+ });
75
+ return { plan, result };
76
+ }
77
+ export function addDiffciPackageScripts(repoPath) {
78
+ const packagePath = join(repoPath, "package.json");
79
+ const source = readFileSync(packagePath, "utf8");
80
+ const manifest = JSON.parse(source);
81
+ if (manifest.scripts !== undefined && (typeof manifest.scripts !== "object" || manifest.scripts === null || Array.isArray(manifest.scripts))) {
82
+ throw new Error("package.json scripts must be an object before DiffCI scripts can be added");
83
+ }
84
+ const scripts = (manifest.scripts ?? {});
85
+ const added = [];
86
+ const kept = [];
87
+ for (const [name, command] of Object.entries(DIFFCI_SCRIPTS)) {
88
+ if (name in scripts) {
89
+ kept.push(name);
90
+ continue;
91
+ }
92
+ scripts[name] = command;
93
+ added.push(name);
94
+ }
95
+ manifest.scripts = scripts;
96
+ if (added.length > 0) {
97
+ const newline = source.includes("\r\n") ? "\r\n" : "\n";
98
+ writeFileSync(packagePath, `${JSON.stringify(manifest, null, 2)}${newline}`, "utf8");
99
+ }
100
+ return { added, kept };
101
+ }
@@ -0,0 +1,18 @@
1
+ /** Explicit, best-effort aggregate usage signal. No repository or machine identifier is sent. */
2
+ export async function sendUsageSignal(input) {
3
+ const url = new URL(input.endpoint ?? "https://app.diffci.com/v1/usage-events");
4
+ if (url.protocol !== "https:")
5
+ return false;
6
+ try {
7
+ const response = await (input.fetchImpl ?? fetch)(url, {
8
+ method: "POST",
9
+ headers: { "Content-Type": "application/json" },
10
+ body: JSON.stringify({ schema: "diffci.usage.v1", command: input.command, outcome: input.outcome, version: input.version }),
11
+ signal: AbortSignal.timeout(2500),
12
+ });
13
+ return response.ok;
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
@@ -2,6 +2,21 @@
2
2
 
3
3
  Track adoption weekly after each outreach batch.
4
4
 
5
+ ## Opt-in CLI usage
6
+
7
+ Users can run `diffci check --share-usage` or set `DIFFCI_SHARE_USAGE=1` for `check` and
8
+ `observe`. `--no-send` overrides the opt-in. The CLI sends one HTTPS event after analysis to
9
+ `https://app.diffci.com/v1/usage-events` with only the command (`check` or `observe`), analysis
10
+ outcome (`observed`, `refused`, or `error`), and package version. It sends no repository identity,
11
+ paths, commits, test names, report, token, or stable installation identifier. Delivery failure is
12
+ best effort and cannot fail validation. The product Worker records `cli_usage_opt_in` in PostHog
13
+ when its existing `POSTHOG_API_KEY` is configured.
14
+
15
+ Count these events as **opted-in executions**, not unique users or repositories. Report the opt-in
16
+ count separately from npm downloads and external merged integrations. Because there is no stable
17
+ identifier, repeated runs by one user cannot be deduplicated. Network providers may still observe
18
+ connection metadata such as IP address.
19
+
5
20
  ## Package
6
21
 
7
22
  - npm latest version: `npm view "@diffci.com/diffci" version`
@@ -30,7 +30,7 @@ jobs:
30
30
  - uses: actions/checkout@v4
31
31
  with:
32
32
  fetch-depth: 0
33
- - uses: DiffCI/DiffCI.com@3aa76a84919691cf7e8f9d1f1f6a80399325d1ae # v0.2.2
33
+ - uses: DiffCI/DiffCI.com@e852523fade14bf5e0457a6331e97c8a76eedc2b # v0.2.7
34
34
  ```
35
35
 
36
36
  Run `npx @diffci.com/diffci@latest verify-workflow` before starting a pilot. The Action uploads a
@@ -48,7 +48,7 @@ and the [DiffCI submission packet](tidelift-submission.md).
48
48
 
49
49
  ## GitHub App
50
50
 
51
- The DiffCI Shadow GitHub App is the lowest-friction research and design-partner path. It receives
51
+ The unified read-only DiffCI GitHub App is the lowest-friction research and design-partner path. It receives
52
52
  repository events, runs shadow analysis outside the repository's CI jobs, and reconciles predictions
53
53
  against real CI outcomes. Use it when a maintainer wants observation without adding a workflow step.
54
54
 
@@ -68,10 +68,10 @@ jobs:
68
68
  - uses: actions/checkout@v4
69
69
  with:
70
70
  fetch-depth: 0
71
- - uses: DiffCI/DiffCI.com@3aa76a84919691cf7e8f9d1f1f6a80399325d1ae
71
+ - uses: DiffCI/DiffCI.com@e852523fade14bf5e0457a6331e97c8a76eedc2b
72
72
  ```
73
73
 
74
- The example pins release `v0.2.2` to its full commit SHA. `npx @diffci.com/diffci@latest verify-workflow`
74
+ The example pins release `v0.2.7` to its qualified feature commit SHA. `npx @diffci.com/diffci@latest verify-workflow`
75
75
  checks that the job is dedicated, read-only, not required by other jobs, and unable to alter the rest
76
76
  of CI.
77
77
 
@@ -106,7 +106,7 @@ Estimated CO2 xxx kg
106
106
  Estimated water xxx L
107
107
  ```
108
108
 
109
- That makes the open-source proposition explicit: install DiffCI Shadow, change nothing in CI, and learn
109
+ That makes the open-source proposition explicit: install DiffCI, change nothing in CI, and learn
110
110
  how much compute may be wasted.
111
111
 
112
112
  ## Future Package Managers
@@ -7,6 +7,17 @@ DiffCI's npm package should be promoted as a low-risk CI observer:
7
7
 
8
8
  ## Install
9
9
 
10
+ For a pinned project dependency, run the initializer from the repository root. It detects npm, pnpm,
11
+ Yarn, or Bun, adds the current DiffCI version as an exact development dependency, and updates the
12
+ corresponding lockfile:
13
+
14
+ ```bash
15
+ npx @diffci.com/diffci@latest init --install
16
+ ```
17
+
18
+ Add `--workflow` to also create the separate, non-blocking GitHub Actions observation job. Installation
19
+ is explicit: plain `init` never changes `package.json` or a lockfile.
20
+
10
21
  Use the npm CLI when someone wants to try DiffCI locally or inside an existing CI step:
11
22
 
12
23
  ```bash
@@ -27,7 +38,7 @@ jobs:
27
38
  - uses: actions/checkout@v4
28
39
  with:
29
40
  fetch-depth: 0
30
- - uses: DiffCI/DiffCI.com@dee4f7b938a7720d077c1124ef2ea050aa2625d6
41
+ - uses: DiffCI/DiffCI.com@e852523fade14bf5e0457a6331e97c8a76eedc2b
31
42
  ```
32
43
 
33
44
  ## Outreach Copy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffci.com/diffci",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "DiffCI - deterministic change-aware CI planning",
5
5
  "keywords": [
6
6
  "ci",
@@ -65,7 +65,7 @@
65
65
  "typecheck": "tsc --noEmit",
66
66
  "build": "tsc",
67
67
  "test": "tsx --test \"tests/**/*.test.ts\"",
68
- "check": "npm run typecheck && npm run test",
68
+ "check": "npm run check:public-metadata && npm run typecheck && npm run test",
69
69
  "prepack": "npm run build:client",
70
70
  "package:smoke": "node scripts/package-smoke.mjs",
71
71
  "diffci": "tsx scripts/diffci.ts",
@@ -127,7 +127,8 @@
127
127
  "corpus:register": "tsx scripts/register-corpus-entry.ts",
128
128
  "ci:benchmark": "tsx scripts/ci-inference-benchmark.ts",
129
129
  "ci:reproduce": "tsx scripts/ci-reproduction.ts",
130
- "check:oss-boundary": "node scripts/check-oss-boundary.mjs"
130
+ "check:oss-boundary": "node scripts/check-oss-boundary.mjs",
131
+ "check:public-metadata": "node scripts/check-public-metadata.mjs"
131
132
  },
132
133
  "dependencies": {
133
134
  "@diffci.com/core": "git+https://github.com/DiffCI/core.git#db1d637dfcca8d8f7fa047500dfe0027d0d018a7",
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.adityankale190895/diffci",
4
4
  "title": "DiffCI",
5
5
  "description": "Observation-only CI/CD validation for AI coding agents.",
6
- "version": "0.2.5",
6
+ "version": "0.2.7",
7
7
  "websiteUrl": "https://diffci.com/docs/ai-agents.html",
8
8
  "repository": {
9
9
  "url": "https://github.com/DiffCI/DiffCI.com",
@@ -13,7 +13,7 @@
13
13
  {
14
14
  "registryType": "npm",
15
15
  "identifier": "@diffci.com/diffci",
16
- "version": "0.2.5",
16
+ "version": "0.2.7",
17
17
  "transport": {
18
18
  "type": "stdio"
19
19
  },