@diffci.com/diffci 0.3.14 → 0.3.16

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.
Files changed (100) hide show
  1. package/LICENSE +20 -661
  2. package/README.md +1 -1
  3. package/dist-client/src/client/agent-selection.js +20 -0
  4. package/dist-client/src/client/cli.js +155 -12
  5. package/dist-client/src/client/context.js +1 -1
  6. package/dist-client/src/client/enforce-misses-collect.js +157 -0
  7. package/dist-client/src/client/enforce-misses.js +229 -0
  8. package/dist-client/src/client/enforce-policy.js +169 -0
  9. package/dist-client/src/client/feedback-prompt.js +42 -0
  10. package/dist-client/src/client/hook.js +94 -0
  11. package/dist-client/src/client/mcp.js +12 -4
  12. package/dist-client/src/client/observe.js +8 -3
  13. package/dist-client/src/client/telemetry.js +46 -0
  14. package/dist-client/src/client/usage-signal.js +17 -10
  15. package/dist-client/src/client/verify.js +48 -6
  16. package/node_modules/@diffci.com/core/LICENSE +21 -661
  17. package/node_modules/@diffci.com/core/NOTICE +2 -2
  18. package/node_modules/@diffci.com/core/README.md +21 -3
  19. package/node_modules/@diffci.com/core/dist/analyze.js +1 -1
  20. package/node_modules/@diffci.com/core/dist/analyze.js.map +1 -1
  21. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +1 -1
  22. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
  23. package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js +1 -1
  24. package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js.map +1 -1
  25. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +1 -1
  26. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
  27. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +1 -1
  28. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
  29. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +1 -1
  30. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
  31. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +1 -1
  32. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
  33. package/node_modules/@diffci.com/core/dist/ci-inference/schema.js +1 -1
  34. package/node_modules/@diffci.com/core/dist/ci-inference/schema.js.map +1 -1
  35. package/node_modules/@diffci.com/core/dist/cli.js +1 -1
  36. package/node_modules/@diffci.com/core/dist/cli.js.map +1 -1
  37. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +29 -4
  38. package/node_modules/@diffci.com/core/dist/git/git-diff.js +136 -22
  39. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  40. package/node_modules/@diffci.com/core/dist/git/types.d.ts +7 -0
  41. package/node_modules/@diffci.com/core/dist/index.js +1 -1
  42. package/node_modules/@diffci.com/core/dist/index.js.map +1 -1
  43. package/node_modules/@diffci.com/core/dist/measurement.js +1 -1
  44. package/node_modules/@diffci.com/core/dist/measurement.js.map +1 -1
  45. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js +1 -1
  46. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js.map +1 -1
  47. package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +32 -0
  48. package/node_modules/@diffci.com/core/dist/repo/file-references.js +180 -9
  49. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
  50. package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +4 -0
  51. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +19 -0
  52. package/node_modules/@diffci.com/core/dist/repo/impact.js +105 -3
  53. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  54. package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.d.ts +27 -0
  55. package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.js +116 -0
  56. package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.js.map +1 -0
  57. package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
  58. package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
  59. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +1 -1
  60. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
  61. package/node_modules/@diffci.com/core/dist/repo/workspaces.js +1 -1
  62. package/node_modules/@diffci.com/core/dist/repo/workspaces.js.map +1 -1
  63. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +1 -1
  64. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
  65. package/node_modules/@diffci.com/core/dist/research/baseline/test-activity.js +1 -1
  66. package/node_modules/@diffci.com/core/dist/research/baseline/test-activity.js.map +1 -1
  67. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +1 -1
  68. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
  69. package/node_modules/@diffci.com/core/package.json +1 -1
  70. package/node_modules/@diffci.com/core/src/analyze.ts +1 -1
  71. package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +1 -1
  72. package/node_modules/@diffci.com/core/src/ci-inference/causal.ts +1 -1
  73. package/node_modules/@diffci.com/core/src/ci-inference/evidence.ts +1 -1
  74. package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +1 -1
  75. package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +1 -1
  76. package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +1 -1
  77. package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +1 -1
  78. package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +1 -1
  79. package/node_modules/@diffci.com/core/src/ci-inference/reference-graph.ts +1 -1
  80. package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +1 -1
  81. package/node_modules/@diffci.com/core/src/ci-inference/schema.ts +1 -1
  82. package/node_modules/@diffci.com/core/src/cli.ts +1 -1
  83. package/node_modules/@diffci.com/core/src/git/git-diff.ts +127 -21
  84. package/node_modules/@diffci.com/core/src/git/types.ts +7 -0
  85. package/node_modules/@diffci.com/core/src/index.ts +1 -1
  86. package/node_modules/@diffci.com/core/src/measurement.ts +1 -1
  87. package/node_modules/@diffci.com/core/src/repo/compiled-projects.ts +1 -1
  88. package/node_modules/@diffci.com/core/src/repo/file-references.ts +170 -9
  89. package/node_modules/@diffci.com/core/src/repo/impact-types.ts +4 -0
  90. package/node_modules/@diffci.com/core/src/repo/impact.ts +115 -2
  91. package/node_modules/@diffci.com/core/src/repo/npm-lockfile.ts +109 -0
  92. package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
  93. package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +1 -1
  94. package/node_modules/@diffci.com/core/src/repo/workspaces.ts +1 -1
  95. package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +1 -1
  96. package/node_modules/@diffci.com/core/src/research/baseline/path-baseline.ts +1 -1
  97. package/node_modules/@diffci.com/core/src/research/baseline/registry.ts +1 -1
  98. package/node_modules/@diffci.com/core/src/research/baseline/test-activity.ts +1 -1
  99. package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +1 -1
  100. package/package.json +6 -4
@@ -8,7 +8,7 @@ import { refineConfidenceForDelta } from "./graph.js";
8
8
  import { repositoryLayout, UNKNOWN_REPOSITORY_LAYOUT, type RepositoryLayout } from "./layout.js";
9
9
  import { DEFAULT_TEST_FILE_MATCHER, matchesGlob as matchesTestGlob, testDiscoveryErrors, testFileMatcherForProfile } from "./test-discovery.js";
10
10
  import { resolveTestFixtureOwners } from "./test-fixture-ownership.js";
11
- import { infrastructureRole, isImplicitlyLoadedFile, resolveFileReferences } from "./file-references.js";
11
+ import { infrastructureRole, isImplicitlyLoadedFile, resolveFileReferences, testScriptClosure } from "./file-references.js";
12
12
  import { workflowFeedsTests } from "./workflow-test-steps.js";
13
13
  import { modelTestScriptUniverse, type ScriptUniverse } from "./script-universe.js";
14
14
  import { compiledProjects, type CompiledProject } from "./compiled-projects.js";
@@ -192,6 +192,9 @@ export interface ImpactAnalyzeOptions {
192
192
  * `repositoryFiles` it enables resolving the readers of non-code files by reference
193
193
  * (src/repo/file-references.ts). Omitting it keeps such files unknown, exactly as before. */
194
194
  readRepositoryFile?: (path: string) => string | undefined;
195
+ /** Let a file the root test script runs directly be covered by running that phase
196
+ * (ImpactResult.testPhases) instead of falling back. Only for callers that execute the phases. */
197
+ selectTestPhases?: boolean;
195
198
  }
196
199
 
197
200
  function changedFileReasons(file: ChangedFile): ImpactReason[] {
@@ -252,6 +255,8 @@ export class ImpactAnalyzer {
252
255
  private sortedRepositoryFiles: string[] = [];
253
256
  private compiledProjectCache: CompiledProject[] | undefined;
254
257
  private goEmbedPaths = new Set<string>();
258
+ private selectTestPhases = false;
259
+ private testPhases = new Set<string>();
255
260
  constructor(alwaysRunChecks: AlwaysRunCheck[] = DEFAULT_ALWAYS_RUN_CHECKS) { this.alwaysRunChecks = alwaysRunChecks; }
256
261
 
257
262
  analyze(delta: GitDelta, graphResult: DependencyGraphResult, profile: RepositoryProfile, options: ImpactAnalyzeOptions = {}): ImpactResult {
@@ -260,6 +265,8 @@ export class ImpactAnalyzer {
260
265
  this.isTestFile = testFileMatcherForProfile(profile);
261
266
  this.layout = repositoryLayout(profile);
262
267
  this.repositoryFiles = options.repositoryFiles;
268
+ this.selectTestPhases = options.selectTestPhases === true;
269
+ this.testPhases = new Set();
263
270
  this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
264
271
  this.compiledProjectCache = undefined;
265
272
  // One read per file per analysis, however many changed files ask who reads them.
@@ -348,6 +355,8 @@ export class ImpactAnalyzer {
348
355
  }
349
356
  }
350
357
 
358
+ this.collectTestScriptAdditions(delta, graph, affectedTests, evidence, riskSignals, fallbackReasons);
359
+ this.collectDependencyChangeTests(delta, graphResult, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, riskSignals, fallbackReasons);
351
360
  this.handleStructuralNextLayout(changedImpacts, profile, affectedEntryPoints, affectedSources, evidence);
352
361
  this.handleAddedEntryPoints(delta, affectedEntryPoints, affectedSources, affectedTests, evidence, fallbackReasons);
353
362
  this.collectAlwaysRunTests(profile, graph, affectedTests, evidence, graphResult.profile.vueRuntimeAlwaysRunPaths ?? []);
@@ -396,6 +405,7 @@ export class ImpactAnalyzer {
396
405
  fullSuiteTestCount: fullSuite.tests.length,
397
406
  testsOutsideFullSuite: testsOutsideFullSuite.sort((a, b) => a.path.localeCompare(b.path)),
398
407
  } : {}),
408
+ ...(this.testPhases.size ? { testPhases: [...this.testPhases].sort() } : {}),
399
409
  affectedEntryPoints: Array.from(affectedEntryPoints.values()).sort((a, b) => a.path.localeCompare(b.path)),
400
410
  affectedScripts: Array.from(affectedScripts.keys()).sort(),
401
411
  riskSignals: dedupedRiskSignals,
@@ -431,6 +441,97 @@ export class ImpactAnalyzer {
431
441
  }
432
442
  }
433
443
 
444
+ /** A test file a test-list edit added to the test script now runs as part of the suite, whether or
445
+ * not it changed (src/git/git-diff.ts, testListEdit). One that is missing at HEAD would make the
446
+ * script fail, so it falls back. */
447
+ private collectTestScriptAdditions(delta: GitDelta, graph: DependencyGraph, affectedTests: Map<string, TestImpact>, evidence: ImpactEvidence[], riskSignals: ImpactRiskSignal[], fallbackReasons: string[]): void {
448
+ for (const path of delta.analysis.testScriptAddedPaths ?? []) {
449
+ if (this.repositoryFiles && !this.repositoryFiles.has(path)) {
450
+ const message = `package.json test script now lists ${path}, which does not exist; full validation required`;
451
+ riskSignals.push({ level: "critical", reason: "DEPENDENCY_MANIFEST", message, paths: ["package.json"] });
452
+ if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
453
+ continue;
454
+ }
455
+ this.addAffectedTest("package.json", path, graph, affectedTests, "NEW_TEST_FILE", evidence);
456
+ evidence.push(makeEvidence("NEW_TEST_FILE", "package.json", `package.json test script now runs ${path}`, path));
457
+ }
458
+ }
459
+
460
+ /**
461
+ * Selects the tests that load each direct dependency whose installed tree changed
462
+ * (GitDeltaAnalysis.changedDependencies, 2026-10-28). A package reaches a test only by being loaded:
463
+ * imported by graph code, which selects the importer's dependent tests; imported by code outside the
464
+ * graph, whose own readers are resolved by reference; or loaded by tooling, which this cannot see.
465
+ * So the change falls back when no repository code imports the package (a CLI, a plugin, `@types/*`),
466
+ * when a test-closure script names it, or when a file tooling loads implicitly names it (a config
467
+ * that registers a plugin or a preset).
468
+ */
469
+ private collectDependencyChangeTests(
470
+ delta: GitDelta,
471
+ graphResult: DependencyGraphResult,
472
+ profile: RepositoryProfile,
473
+ affectedSources: Map<string, ImpactEvidence[]>,
474
+ affectedEntryPoints: Map<string, EntryPointImpact>,
475
+ affectedTests: Map<string, TestImpact>,
476
+ affectedScripts: Map<string, ImpactEvidence[]>,
477
+ evidence: ImpactEvidence[],
478
+ riskSignals: ImpactRiskSignal[],
479
+ fallbackReasons: string[],
480
+ ): void {
481
+ const packages = delta.analysis.changedDependencies;
482
+ if (!packages || packages.length === 0) return;
483
+ const { graph } = graphResult;
484
+ const fail = (message: string) => {
485
+ riskSignals.push({ level: "critical", reason: "DEPENDENCY_MANIFEST", message, paths: ["package.json"] });
486
+ if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
487
+ };
488
+ // Typecheck and build tasks still see a dependency change (planner globalRiskTriggers).
489
+ riskSignals.push({ level: "info", reason: "DEPENDENCY_MANIFEST", message: `Dependencies changed: ${packages.join(", ")}`, paths: ["package.json"] });
490
+ if (!this.repositoryFiles || !this.readRepositoryFile) {
491
+ fail(`Dependency change (${packages.join(", ")}) cannot be traced without repository contents; full validation required`);
492
+ return;
493
+ }
494
+ const packageRoot = (specifier: string) => {
495
+ const parts = specifier.split("/");
496
+ return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]!;
497
+ };
498
+ const scripts = profile.packageJson.scripts;
499
+ const closureBodies = [...testScriptClosure(scripts)].map((name) => scripts[name] ?? "");
500
+ for (const name of packages) {
501
+ const importers = [...new Set(graphResult.references
502
+ .filter((ref) => ref.resolution === "external-package" && packageRoot(ref.specifier) === name)
503
+ .map((ref) => ref.importer))].sort();
504
+ if (importers.length === 0) {
505
+ fail(`Dependency ${name} changed and no repository source imports it; full validation required`);
506
+ continue;
507
+ }
508
+ const quoted = new RegExp(`["'\`]${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:/[^"'\`]*)?["'\`]`);
509
+ const bare = new RegExp(`(?:^|[\\s"'=])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?=$|[\\s"'/@])`);
510
+ if (closureBodies.some((body) => bare.test(body))) {
511
+ fail(`Dependency ${name} changed and the test script runs it; full validation required`);
512
+ continue;
513
+ }
514
+ const toolingReader = this.sortedRepositoryFiles.find((path) => isImplicitlyLoadedFile(path) && !isLockfile(path) && quoted.test(this.readRepositoryFile!(path) ?? ""));
515
+ if (toolingReader) {
516
+ fail(`Dependency ${name} changed and ${toolingReader} loads it; full validation required`);
517
+ continue;
518
+ }
519
+ for (const importer of importers) {
520
+ evidence.push(makeEvidence("DEPENDENCY", "package.json", `${importer} imports changed dependency ${name}`, importer));
521
+ if (this.isTestFile(importer)) this.addAffectedTest("package.json", importer, graph, affectedTests, "DEPENDENCY", evidence);
522
+ this.processSourceChange(importer, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
523
+ }
524
+ // Code outside the graph that loads the package reaches the suite only if something runs it.
525
+ for (const path of this.sortedRepositoryFiles) {
526
+ if (!isSourceFilePath(path) || hasNode(graph, path) || !quoted.test(this.readRepositoryFile(path) ?? "")) continue;
527
+ if (!this.resolveByReference(path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) {
528
+ fail(`Dependency ${name} changed and ${path}, which loads it, is outside the dependency graph; full validation required`);
529
+ break;
530
+ }
531
+ }
532
+ }
533
+ }
534
+
434
535
  private processChangedPath(
435
536
  changedPath: string,
436
537
  changedImpact: ChangedImpact,
@@ -500,7 +601,12 @@ export class ImpactAnalyzer {
500
601
  return;
501
602
  }
502
603
  if (infrastructureRole(changedPath) === "code" && !hasNode(graph, changedPath) && changedImpact.file.changeType !== "deleted") {
503
- // Code under ops/ is classified like code anywhere else only while the graph can see it.
604
+ // Code under ops/ is classified like code anywhere else only while the graph can see it. Outside
605
+ // the graph, a test can still reach it only by naming it - one dogfood repository's tests read the Worker
606
+ // entry point `ops/cloudflare/src/index.js` as text (2026-10-28: 7 of 42 replayed fallbacks) - so
607
+ // its readers are resolved like any other non-code file. A deployment definition that names it
608
+ // (wrangler.*, Dockerfile) runs it without naming anything a test would, so that stays global.
609
+ if (this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { implicitReadersUnresolvable: true })) return;
504
610
  const message = `Infrastructure code ${changedPath} is outside the dependency graph; full validation required`;
505
611
  evidence.push(makeEvidence("INFRASTRUCTURE_GLOBAL", changedPath, message));
506
612
  riskSignals.push({ level: "critical", reason: "INFRASTRUCTURE_GLOBAL", message, paths: [changedPath] });
@@ -567,6 +673,7 @@ export class ImpactAnalyzer {
567
673
  affectedTests: Map<string, TestImpact>,
568
674
  affectedScripts: Map<string, ImpactEvidence[]>,
569
675
  evidence: ImpactEvidence[],
676
+ { implicitReadersUnresolvable = false }: { implicitReadersUnresolvable?: boolean } = {},
570
677
  ): boolean {
571
678
  if (!this.repositoryFiles || !this.readRepositoryFile || isImplicitlyLoadedFile(changedPath)) return false;
572
679
  const layout = this.layout;
@@ -580,6 +687,8 @@ export class ImpactAnalyzer {
580
687
  isCodeFile: isSourceFilePath,
581
688
  workflowFeedsTests: (content, names) => workflowFeedsTests(content, names, scripts),
582
689
  contentCleared: this.contentCleared,
690
+ implicitReadersUnresolvable,
691
+ testPhases: this.selectTestPhases,
583
692
  });
584
693
  if (resolution.unresolvable.length > 0) {
585
694
  evidence.push(makeEvidence("UNKNOWN_FILE", changedPath, `References to ${changedPath} could not be resolved: ${resolution.unresolvable[0]}`));
@@ -590,6 +699,10 @@ export class ImpactAnalyzer {
590
699
  evidence.push(makeEvidence("FILE_REFERENCE", changedPath, `${reader.path} names ${reader.via}`, reader.path));
591
700
  }
592
701
  for (const test of resolution.tests) this.addAffectedTest(changedPath, test, graph, affectedTests, "FILE_REFERENCE", evidence);
702
+ for (const phase of resolution.phases) {
703
+ this.testPhases.add(phase);
704
+ evidence.push(makeEvidence("FILE_REFERENCE", changedPath, `the test script runs \`${phase}\`, which reads ${changedPath}`));
705
+ }
593
706
  for (const code of resolution.code) {
594
707
  if (!affectedSources.has(code)) affectedSources.set(code, []);
595
708
  affectedSources.get(code)!.push(makeEvidence("FILE_REFERENCE", changedPath, `${code} reads ${changedPath}`, code));
@@ -0,0 +1,109 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * Which direct dependencies did a package-lock.json change reach? (2026-10-28.)
4
+ *
5
+ * WHY. A dependency bump changes package.json and the lockfile together, and each used to force the
6
+ * full suite. In one dogfood repository's paired experiment those two signals were behind 19 of 40 runs.
7
+ * A bump can only change the behaviour of code that loads the bumped package, and code loads a
8
+ * transitive package only through a direct dependency. So the question for selection is which direct
9
+ * dependencies now resolve to a different installed tree; the impact analyzer then selects the tests
10
+ * that import those packages, and falls back when a package is not imported by any repository file.
11
+ *
12
+ * THE MODEL. npm lockfiles v2 and v3 list every installed package under `packages`, keyed by its
13
+ * install path (`node_modules/a`, `node_modules/a/node_modules/b`). An entry whose content changed, or
14
+ * which was added or removed, is a changed install. Each install's own `dependencies`,
15
+ * `optionalDependencies` and `peerDependencies` are resolved the way Node does, by walking up the
16
+ * install path. A direct dependency is affected when its closure, in the old or the new lockfile,
17
+ * contains a changed install.
18
+ *
19
+ * FAILING CLOSED. Anything this does not model returns undefined, and the caller keeps the global
20
+ * lockfile signal: lockfile v1, an unparseable file, workspace or linked entries (keys outside
21
+ * `node_modules/`), or a changed install no direct dependency reaches (a hoisting change the model
22
+ * cannot attribute).
23
+ */
24
+
25
+ interface LockEntry {
26
+ dependencies?: Record<string, string>;
27
+ optionalDependencies?: Record<string, string>;
28
+ peerDependencies?: Record<string, string>;
29
+ link?: boolean;
30
+ }
31
+
32
+ interface Lockfile {
33
+ lockfileVersion?: number;
34
+ packages?: Record<string, LockEntry>;
35
+ }
36
+
37
+ function parse(content: string | undefined): Record<string, LockEntry> | undefined {
38
+ if (content === undefined) return undefined;
39
+ let lock: Lockfile;
40
+ try { lock = JSON.parse(content) as Lockfile; } catch { return undefined; }
41
+ if (!lock || typeof lock !== "object" || typeof lock.lockfileVersion !== "number" || lock.lockfileVersion < 2) return undefined;
42
+ if (!lock.packages || typeof lock.packages !== "object") return undefined;
43
+ return lock.packages;
44
+ }
45
+
46
+ /** The install path a package named `name`, required from `fromKey`, resolves to. */
47
+ function resolveInstall(packages: Record<string, LockEntry>, fromKey: string, name: string): string | undefined {
48
+ let base = fromKey;
49
+ while (true) {
50
+ const candidate = base ? `${base}/node_modules/${name}` : `node_modules/${name}`;
51
+ if (packages[candidate]) return candidate;
52
+ if (!base) return undefined;
53
+ const index = base.lastIndexOf("/node_modules/");
54
+ base = index === -1 ? "" : base.slice(0, index);
55
+ }
56
+ }
57
+
58
+ function closure(packages: Record<string, LockEntry>, root: string): Set<string> {
59
+ const seen = new Set<string>();
60
+ const queue = [root];
61
+ while (queue.length > 0) {
62
+ const key = queue.pop()!;
63
+ if (seen.has(key) || !packages[key]) continue;
64
+ seen.add(key);
65
+ const entry = packages[key]!;
66
+ for (const field of [entry.dependencies, entry.optionalDependencies, entry.peerDependencies]) {
67
+ for (const name of Object.keys(field ?? {})) {
68
+ const resolved = resolveInstall(packages, key, name);
69
+ if (resolved && !seen.has(resolved)) queue.push(resolved);
70
+ }
71
+ }
72
+ }
73
+ return seen;
74
+ }
75
+
76
+ /**
77
+ * The direct dependencies (names from the root package.json, old and new) whose installed tree
78
+ * differs between two package-lock.json contents, or undefined when the change cannot be attributed.
79
+ */
80
+ export function npmLockAffectedDependencies(oldContent: string | undefined, newContent: string | undefined, directDependencies: readonly string[]): string[] | undefined {
81
+ const before = parse(oldContent);
82
+ const after = parse(newContent);
83
+ if (!before || !after) return undefined;
84
+ const changed = new Set<string>();
85
+ for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
86
+ if (key === "") continue; // the root entry mirrors package.json, which the caller compares itself
87
+ if (!key.startsWith("node_modules/")) return undefined;
88
+ if (before[key]?.link || after[key]?.link) return undefined;
89
+ if (JSON.stringify(before[key]) !== JSON.stringify(after[key])) changed.add(key);
90
+ }
91
+ const affected = new Set<string>();
92
+ const attributed = new Set<string>();
93
+ for (const name of directDependencies) {
94
+ for (const packages of [before, after]) {
95
+ const root = `node_modules/${name}`;
96
+ if (!packages[root]) {
97
+ if (changed.has(root)) { affected.add(name); attributed.add(root); }
98
+ continue;
99
+ }
100
+ for (const key of closure(packages, root)) {
101
+ if (!changed.has(key)) continue;
102
+ affected.add(name);
103
+ attributed.add(key);
104
+ }
105
+ }
106
+ }
107
+ if ([...changed].some((key) => !attributed.has(key))) return undefined;
108
+ return [...affected].sort();
109
+ }
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  /**
3
3
  * Which discovered test files does `npm test` actually run? (2026-10-21, dogfood telemetry.)
4
4
  *
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  /**
3
3
  * Can this GitHub Actions workflow run the repository's tests? (2026-10-21.)
4
4
  *
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  import { existsSync, readFileSync, readdirSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { parse } from "yaml";
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  function expandBraces(pattern: string): string[] {
3
3
  const match = /\{([^{}]*)\}/.exec(pattern);
4
4
  if (!match) return [pattern];
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  import type { TaskRegistry } from "../../planner/task-registry.js";
3
3
  import { matchesAny } from "./matcher.js";
4
4
  import type { ChangedFile } from "../../git/types.js";
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  import type { RepositoryProfile } from "../../repo/types.js";
3
3
  import type { CITaskDefinition, TaskRegistry } from "../../planner/task-registry.js";
4
4
  import { createTaskRegistry } from "../../planner/task-registry.js";
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  /**
3
3
  * Stage 2C measurement-pipeline repair (2026-08-21, docs/research/2026-08-21-stage2c-*.md). Root cause:
4
4
  * inferCategory() (workflow-parser.ts) only ever looked at a job's `name:` field (or its YAML key) and
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  import { readFileSync } from "node:fs";
3
3
  import { resolve } from "node:path";
4
4
  import YAML from "yaml";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffci.com/diffci",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "description": "Fail-closed, change-aware verification for AI coding agents with conservative affected-test selection",
5
5
  "keywords": [
6
6
  "ci",
@@ -20,7 +20,7 @@
20
20
  "affected-tests",
21
21
  "github-actions"
22
22
  ],
23
- "license": "AGPL-3.0-only",
23
+ "license": "MIT",
24
24
  "mcpName": "io.github.DiffCI/diffci",
25
25
  "repository": {
26
26
  "type": "git",
@@ -55,14 +55,16 @@
55
55
  "build:client": "tsc -p tsconfig.client.json && node scripts/ensure-client-executables.mjs",
56
56
  "prepack": "npm run build:client",
57
57
  "package:check": "node scripts/check-package-boundary.mjs",
58
- "package:smoke": "node scripts/package-smoke.mjs"
58
+ "package:smoke": "node scripts/package-smoke.mjs",
59
+ "test": "node scripts/run-tests.mjs"
59
60
  },
60
61
  "dependencies": {
61
- "@diffci.com/core": "git+https://github.com/DiffCI/core.git#e7ffdaf103800e71d74375afe4bc82604953bf19",
62
+ "@diffci.com/core": "git+https://github.com/DiffCI/core.git#8d832eb5a0a56bf57847e6425bc313ea9e575f59",
62
63
  "yaml": "^2.9.0"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@types/node": "^22.15.12",
67
+ "tsx": "^4.23.15",
66
68
  "typescript": "^5.8.3"
67
69
  },
68
70
  "bundleDependencies": [