@diffci.com/diffci 0.2.5 → 0.2.6

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@0c4178e86cc462a7a6afaf906ca5076a47f69fee
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.6` 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@0c4178e86cc462a7a6afaf906ca5076a47f69fee
299
310
  ```
300
311
 
301
312
  ```bash
@@ -30,6 +30,7 @@ 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";
34
35
  import { formatVerifySavingsSummary, measureCommand, runVerifySavings, writeVerifySavingsReport } from "./verify-savings.js";
35
36
  import { auditWorkflows, isNonInterfering } from "./workflow-guard.js";
@@ -194,9 +195,29 @@ function runInit(flags, env) {
194
195
  ];
195
196
  if (includeWorkflow)
196
197
  writes.push(writeInitFile(repoPath, ".github/workflows/diffci.yml", diffciWorkflow(identity.version), force));
198
+ let installed;
199
+ if (flags.install === true) {
200
+ const { plan, result } = installDiffci(repoPath, identity.version);
201
+ if (result.error)
202
+ throw result.error;
203
+ if (result.status !== 0) {
204
+ const detail = result.stderr.trim() || result.stdout.trim() || `${plan.manager} exited with status ${result.status ?? "unknown"}`;
205
+ throw new Error(`could not install ${plan.packageSpec}: ${detail}`);
206
+ }
207
+ const scripts = addDiffciPackageScripts(repoPath);
208
+ installed = `installed ${plan.packageSpec} as an exact dev dependency with ${plan.manager}`;
209
+ if (scripts.added.length > 0)
210
+ installed += `; added package scripts ${scripts.added.join(", ")}`;
211
+ if (scripts.kept.length > 0)
212
+ installed += `; kept existing package scripts ${scripts.kept.join(", ")}`;
213
+ }
197
214
  console.log(`DiffCI initialized for AI coding agents in ${repoPath}`);
198
215
  for (const write of writes)
199
216
  console.log(` ${write}`);
217
+ if (installed)
218
+ console.log(` ${installed}`);
219
+ else
220
+ console.log(" skipped package installation (pass --install to add an exact dev dependency)");
200
221
  if (!includeWorkflow)
201
222
  console.log(" skipped .github/workflows/diffci.yml (pass --workflow to add it)");
202
223
  console.log("\nDefault agent command: npx @diffci.com/diffci@latest check");
@@ -588,7 +609,7 @@ async function runPilot(flags, env) {
588
609
  const USAGE = `diffci - change-aware CI analysis and paired timing
589
610
 
590
611
  Usage:
591
- diffci init [--repo <path>] [--workflow] [--force]
612
+ diffci init [--repo <path>] [--workflow] [--install] [--force]
592
613
  diffci mcp
593
614
  diffci check [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
594
615
  [--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>]
@@ -603,6 +624,9 @@ Usage:
603
624
  diffci version
604
625
 
605
626
  init writes AGENTS.md, CLAUDE.md, Cursor rules, Copilot instructions, and diffci.config.json.
627
+ --workflow adds a separate non-blocking observation workflow. --install detects npm, pnpm, Yarn,
628
+ or Bun, installs this DiffCI version as an exact dev dependency, updates the manager's lockfile,
629
+ and adds diffci:check and diffci:observe package scripts without replacing existing scripts.
606
630
  mcp runs the stdio MCP server for native agent integrations.
607
631
  check analyzes the change, runs inferred full and selected commands, and shows measured savings.
608
632
  pilot runs observe and verify-savings together, writing reports to ../diffci-output by default.
@@ -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
+ }
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.6",
4
4
  "description": "DiffCI - deterministic change-aware CI planning",
5
5
  "keywords": [
6
6
  "ci",
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.6",
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.6",
17
17
  "transport": {
18
18
  "type": "stdio"
19
19
  },