@diffci.com/diffci 0.3.36 → 0.3.38

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 (34) hide show
  1. package/dist-client/src/client/check-plan-junit.js +12 -3
  2. package/dist-client/src/client/command-batches.d.ts +6 -0
  3. package/dist-client/src/client/command-batches.js +7 -1
  4. package/dist-client/src/client/context.d.ts +13 -0
  5. package/dist-client/src/client/context.js +27 -0
  6. package/dist-client/src/client/hook.d.ts +7 -0
  7. package/dist-client/src/client/hook.js +34 -3
  8. package/dist-client/src/client/node-bin-launch.d.ts +10 -0
  9. package/dist-client/src/client/node-bin-launch.js +71 -0
  10. package/dist-client/src/client/observe.js +4 -3
  11. package/dist-client/src/client/verify-savings.js +18 -11
  12. package/node_modules/@diffci.com/core/README.md +42 -6
  13. package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
  14. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +1 -1
  15. package/node_modules/@diffci.com/core/dist/cache/vue-analysis-cache.js +2 -0
  16. package/node_modules/@diffci.com/core/dist/cache/vue-analysis-cache.js.map +1 -1
  17. package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +5 -0
  18. package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
  19. package/node_modules/@diffci.com/core/dist/repo/adapters/vue.js +25 -3
  20. package/node_modules/@diffci.com/core/dist/repo/adapters/vue.js.map +1 -1
  21. package/node_modules/@diffci.com/core/dist/repo/graph.d.ts +5 -1
  22. package/node_modules/@diffci.com/core/dist/repo/graph.js +185 -6
  23. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  24. package/node_modules/@diffci.com/core/dist/repo/impact.js +6 -1
  25. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  26. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +12 -0
  27. package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +1 -1
  28. package/node_modules/@diffci.com/core/src/cache/vue-analysis-cache.ts +1 -0
  29. package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +2 -0
  30. package/node_modules/@diffci.com/core/src/repo/adapters/vue.ts +15 -3
  31. package/node_modules/@diffci.com/core/src/repo/graph.ts +152 -6
  32. package/node_modules/@diffci.com/core/src/repo/impact.ts +5 -1
  33. package/node_modules/@diffci.com/core/src/repo/types.ts +13 -0
  34. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  import { type AnalyzeRepositoryOptions } from "./analyzer.js";
2
- import type { DependencyGraph, DependencyGraphResult, GraphConfidence, GraphIntegrityReport } from "./types.js";
2
+ import type { DependencyGraph, DependencyGraphResult, GraphConfidence, GraphIntegrityReport, ScopedAdapterBlocker } from "./types.js";
3
3
  /** Restores a cached graph. `testPatterns` (from the cached profile) keeps isTest flags consistent with
4
4
  * the test universe the graph was built under; without it the pre-2026-08-23 defaults apply. */
5
5
  export declare function hydrateDependencyGraph(graph: DependencyGraph, repoPath: string, testPatterns?: readonly string[]): DependencyGraph;
@@ -72,6 +72,10 @@ export declare function validateDependencyGraph(graph: DependencyGraph): GraphIn
72
72
  * narrowing only applies when unresolved/dynamic-unresolved imports are the actual reason, never when
73
73
  * sourceFileCount or integrity triggered it. */
74
74
  export declare function refineConfidenceForDelta(result: DependencyGraphResult, changedFiles: string[]): GraphConfidence;
75
+ /** The scoped blockers a delta reaches: a changed file, or a file the changed files depend on or that
76
+ * depends on them, lies inside one of the blocker's package directories. A missing edge starts at a file
77
+ * inside that directory, so this is stricter than the per-importer narrowing of unresolved imports. */
78
+ export declare function relevantScopedAdapterBlockers(result: DependencyGraphResult, changedFiles: string[]): ScopedAdapterBlocker[];
75
79
  /** Why the graph's own confidence is below COMPLETE, in counts only (no paths), so a report can say why a
76
80
  * repository-wide UNSAFE did not decide this change's verdict. 2026-11-06: every LobeHub receipt read
77
81
  * "UNSAFE" beside "safe to propose" with nothing connecting the two. Empty when the graph is COMPLETE. */
@@ -7,6 +7,7 @@ import { adapterFiles, REPOSITORY_ADAPTERS } from "./adapters/index.js";
7
7
  import { pythonAdapter } from "./adapters/python.js";
8
8
  import { analyzeRepository } from "./analyzer.js";
9
9
  import { applyVueScope, inVuePackage } from "./vue-scope.js";
10
+ import { declaredWorkspaceRoots } from "./workspaces.js";
10
11
  /** Test-runner calls whose literal first argument names a module the test depends on. */
11
12
  const MOCK_MODULE_CALLS = new Set([
12
13
  "vi.mock", "vi.doMock", "vi.unmock", "vi.doUnmock", "vi.importActual", "vi.importMock",
@@ -811,14 +812,37 @@ export async function buildDependencyGraph(options = {}) {
811
812
  ? cachedVue(context, options.vueAnalysisCache.directory, options.vueAnalysisCache.version) : adapter.analyze(context));
812
813
  markPhase("adapters");
813
814
  const adapterBlockers = [...scopeBlockers, ...contributions.flatMap((item) => item.blockers)];
815
+ // The directories each narrowable blocker is confined to ("" when one of its files is not confined).
816
+ // Outside a declared Vue suite, a blocker confined to directories only is scoped to them below.
817
+ const blockerScopes = new Map();
818
+ const addScope = (reason, directory) => {
819
+ if (scope)
820
+ return;
821
+ let scopes = blockerScopes.get(reason);
822
+ if (!scopes)
823
+ blockerScopes.set(reason, scopes = new Set());
824
+ scopes.add(directory);
825
+ };
826
+ const packageDirectories = new Map();
827
+ const packageScope = (path) => nearestPackageDirectory(repoPath, path, packageDirectories);
828
+ const workspaceRoots = new Set(declaredWorkspaceRoots(repoPath));
829
+ for (const item of contributions)
830
+ for (const { path, reason } of [...(item.fileBlockers ?? []), ...(item.subjectBlockers ?? [])])
831
+ addScope(reason, packageScope(path));
814
832
  if (profile.diffciConfig?.configurationError && !adapterBlockers.includes(profile.diffciConfig.configurationError))
815
833
  adapterBlockers.push(profile.diffciConfig.configurationError);
816
834
  if (contributions.some((item) => item.id === "go") && files.some((file) => /\.(?:[cm]?[jt]sx?|vue)$/.test(file))) {
817
835
  adapterBlockers.push("Mixed Go/JavaScript repositories require explicit cross-language dependencies; full validation required");
818
836
  }
819
837
  const pythonModeled = contributions.some((item) => item.id === "python");
820
- if (contributions.length && files.some((file) => (!pythonModeled && /\.py$/.test(file)) || /\.(?:rs|cs|svelte|astro)$/.test(file) || !contributions.some((item) => item.id === "maven") && /\.(?:java|kt)$/.test(file))) {
821
- adapterBlockers.push("Unmodeled languages alongside an adapter require full validation");
838
+ const unmodeledLanguageFiles = contributions.length ? files.filter((file) => (!pythonModeled && /\.py$/.test(file)) || /\.(?:rs|cs|svelte|astro)$/.test(file) || !contributions.some((item) => item.id === "maven") && /\.(?:java|kt)$/.test(file)) : [];
839
+ if (unmodeledLanguageFiles.length) {
840
+ const reason = "Unmodeled languages alongside an adapter require full validation";
841
+ adapterBlockers.push(reason);
842
+ // Files in a top-level dot-directory outside every package (agent skills, editor tooling) are confined
843
+ // to that directory: no package's sources or tests can load them.
844
+ for (const file of unmodeledLanguageFiles)
845
+ addScope(reason, packageScope(file) || (/^\.[^/]+\//.test(file) && !file.startsWith(".github/") ? file.slice(0, file.indexOf("/")) : ""));
822
846
  }
823
847
  profile.adapters = contributions.map(({ id, version, blockers }) => ({ id, version, blockers }));
824
848
  profile.goTestPackages = Object.assign({}, ...contributions.map((item) => item.testPackages));
@@ -1024,7 +1048,14 @@ export async function buildDependencyGraph(options = {}) {
1024
1048
  const invalid = !parsed || errors.some(error => error.code !== 18003)
1025
1049
  && !hasUnavailableExternalBase(read.config, errors);
1026
1050
  if (invalid) {
1027
- adapterBlockers.push(`Invalid importer TypeScript configuration: ${toRelativeInternal(repoPath, config)}`);
1051
+ const configRel = toRelativeInternal(repoPath, config);
1052
+ const reason = `Invalid importer TypeScript configuration: ${configRel}`;
1053
+ adapterBlockers.push(reason);
1054
+ // Only the files this configuration governs resolve with the wrong options. That is confined
1055
+ // to a nested package only when no workspace package links to it by name and nothing the
1056
+ // configuration states points outside the package (an alias there would hide its edges).
1057
+ if (configRel)
1058
+ addScope(reason, read.error ? "" : confinedConfigScope(repoPath, configRel, read.config, packageScope(configRel), workspaceRoots));
1028
1059
  projectOptions.set(config, compilerOptions);
1029
1060
  }
1030
1061
  else {
@@ -1226,14 +1257,20 @@ export async function buildDependencyGraph(options = {}) {
1226
1257
  Object.assign(vue.performance.counts, { verifiedSuiteRoots: roots.length, reachablePaths: reachable.size, outOfSuiteBlockers, runtimeAlwaysRunTests: profile.vueRuntimeAlwaysRunPaths?.length ?? 0 });
1227
1258
  }
1228
1259
  }
1229
- if (unresolved.some((ref) => ref.importer.endsWith(".vue") || stripImportQuery(ref.specifier).endsWith(".vue"))) {
1230
- adapterBlockers.push("Unresolved Vue dependencies require full validation");
1260
+ const unresolvedVue = unresolved.filter((ref) => ref.importer.endsWith(".vue") || stripImportQuery(ref.specifier).endsWith(".vue"));
1261
+ if (unresolvedVue.length) {
1262
+ const reason = "Unresolved Vue dependencies require full validation";
1263
+ adapterBlockers.push(reason);
1264
+ for (const ref of unresolvedVue)
1265
+ addScope(reason, packageScope(ref.importer));
1231
1266
  }
1232
1267
  filesParsed = sourceFiles.length;
1233
1268
  if (scope && unresolved.length)
1234
1269
  adapterBlockers.push("Unresolved dependencies in the declared Vue suite require full validation");
1235
1270
  if (scope && edges.some(edge => outsideScope(edge.from) || outsideScope(edge.to)))
1236
1271
  adapterBlockers.push("Vue asset or macro dependency crosses the declared package boundary");
1272
+ const scopedAdapterBlockers = scopeAdapterBlockers(adapterBlockers, blockerScopes);
1273
+ scopedAdapterBlockers.push(...uninstalledWorkspaceBlockers(repoPath, references, workspaceRoots));
1237
1274
  profile.adapterBlockers = [...adapterBlockers];
1238
1275
  markPhase("importExtractionAndResolution");
1239
1276
  // Nested-package test visibility (2026-08-24, biomejs/biome finding): `internalSourcePaths` above is
@@ -1278,7 +1315,9 @@ export async function buildDependencyGraph(options = {}) {
1278
1315
  profile.stats.testFiles = graph.nodes.filter((n) => n.isTest).length;
1279
1316
  const integrity = validateDependencyGraph(graph);
1280
1317
  const dynamicUnresolvedCount = unresolved.filter((u) => u.dynamic).length;
1281
- const confidence = adapterBlockers.length ? "UNSAFE" : computeConfidence(unresolved.length, dynamicUnresolvedCount, integrity.criticalCount, profile.stats.sourceFiles, resolvedViaProjectReferences);
1318
+ const confidenceWithoutScopedBlockers = adapterBlockers.length ? "UNSAFE" : computeConfidence(unresolved.length, dynamicUnresolvedCount, integrity.criticalCount, profile.stats.sourceFiles, resolvedViaProjectReferences);
1319
+ // The graph's own confidence still counts scoped blockers; only a delta can rule them out.
1320
+ const confidence = scopedAdapterBlockers.length ? "UNSAFE" : confidenceWithoutScopedBlockers;
1282
1321
  const internalAssetEdges = edges.filter((e) => e.kind === "asset").length;
1283
1322
  const externalReferences = references.filter((r) => r.resolution === "external-package").length;
1284
1323
  const platformBuiltinReferences = references.filter((r) => r.resolution === "platform-builtin").length;
@@ -1303,6 +1342,7 @@ export async function buildDependencyGraph(options = {}) {
1303
1342
  return {
1304
1343
  graph,
1305
1344
  adapterBlockers,
1345
+ ...(scopedAdapterBlockers.length ? { scopedAdapterBlockers, confidenceWithoutScopedBlockers } : {}),
1306
1346
  profile,
1307
1347
  unresolved,
1308
1348
  references,
@@ -1568,6 +1608,39 @@ function computeConfidence(unresolvedCount, dynamicUnresolvedCount, integrityCri
1568
1608
  export function refineConfidenceForDelta(result, changedFiles) {
1569
1609
  if (result.adapterBlockers?.length)
1570
1610
  return "UNSAFE";
1611
+ if (result.scopedAdapterBlockers?.length) {
1612
+ if (relevantScopedAdapterBlockers(result, changedFiles).length)
1613
+ return "UNSAFE";
1614
+ // An older result without the unscoped confidence fails closed.
1615
+ return refineUnscopedConfidence({ ...result, confidence: result.confidenceWithoutScopedBlockers ?? "UNSAFE" }, changedFiles);
1616
+ }
1617
+ return refineUnscopedConfidence(result, changedFiles);
1618
+ }
1619
+ /** The scoped blockers a delta reaches: a changed file, or a file the changed files depend on or that
1620
+ * depends on them, lies inside one of the blocker's package directories. A missing edge starts at a file
1621
+ * inside that directory, so this is stricter than the per-importer narrowing of unresolved imports. */
1622
+ export function relevantScopedAdapterBlockers(result, changedFiles) {
1623
+ const blockers = result.scopedAdapterBlockers ?? [];
1624
+ if (!blockers.length)
1625
+ return [];
1626
+ const touched = new Set(changedFiles);
1627
+ for (const file of changedFiles) {
1628
+ for (const dep of result.graph.transitiveDependenciesOf(file))
1629
+ touched.add(dep);
1630
+ for (const dep of result.graph.transitiveDependentsOf(file))
1631
+ touched.add(dep);
1632
+ }
1633
+ const directories = new Set();
1634
+ for (const path of touched) {
1635
+ let index = path.lastIndexOf("/");
1636
+ while (index > 0) {
1637
+ directories.add(path.slice(0, index));
1638
+ index = path.lastIndexOf("/", index - 1);
1639
+ }
1640
+ }
1641
+ return blockers.filter((blocker) => blocker.directories.some((directory) => directories.has(directory)));
1642
+ }
1643
+ function refineUnscopedConfidence(result, changedFiles) {
1571
1644
  // A computed runtime target can be any file, so its missing edge proves nothing about which changed
1572
1645
  // file it loads. It cannot, however, change the behaviour of a test that never runs the importer:
1573
1646
  // ImpactAnalyzer selects every test that does (COMPUTED_IMPORT) and falls back when the importer is
@@ -1626,6 +1699,110 @@ export function refineConfidenceForDelta(result, changedFiles) {
1626
1699
  // project-references cap, exactly as computeConfidence()'s own final two branches do).
1627
1700
  return result.resolvedViaProjectReferences ? "PARTIAL" : "COMPLETE";
1628
1701
  }
1702
+ /** Nearest directory holding a package.json, relative to the repository; "" is the repository root. */
1703
+ function nearestPackageDirectory(repoPath, path, cache) {
1704
+ const visited = [];
1705
+ let directory = path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
1706
+ let found = "";
1707
+ while (directory) {
1708
+ const cached = cache.get(directory);
1709
+ if (cached !== undefined) {
1710
+ found = cached;
1711
+ break;
1712
+ }
1713
+ visited.push(directory);
1714
+ if (existsSync(join(repoPath, directory, "package.json"))) {
1715
+ found = directory;
1716
+ break;
1717
+ }
1718
+ directory = directory.includes("/") ? directory.slice(0, directory.lastIndexOf("/")) : "";
1719
+ }
1720
+ for (const item of visited)
1721
+ cache.set(item, found);
1722
+ return found;
1723
+ }
1724
+ /** The package directory an invalid importer tsconfig is confined to, or "" when it is not: the package
1725
+ * is the repository root or a declared workspace member, or a path the configuration states leaves it. */
1726
+ function confinedConfigScope(repoPath, configRel, config, directory, workspaceRoots) {
1727
+ if (!directory || workspaceRoots.has(directory) || [...workspaceRoots].some((root) => root.startsWith(`${directory}/`)))
1728
+ return "";
1729
+ const configDirectory = resolve(repoPath, dirname(configRel));
1730
+ const packageRoot = resolve(repoPath, directory);
1731
+ const strings = [];
1732
+ const collect = (value) => {
1733
+ if (typeof value === "string")
1734
+ strings.push(value);
1735
+ else if (Array.isArray(value))
1736
+ value.forEach(collect);
1737
+ else if (value && typeof value === "object")
1738
+ for (const [key, item] of Object.entries(value)) {
1739
+ strings.push(key);
1740
+ collect(item);
1741
+ }
1742
+ };
1743
+ collect(config);
1744
+ for (const value of strings) {
1745
+ if (!value.includes("..") && !value.startsWith("/") && !/^[A-Za-z]:/.test(value))
1746
+ continue;
1747
+ const target = relative(packageRoot, resolve(configDirectory, value.replace(/\*.*$/, "")));
1748
+ if (target === ".." || target.startsWith(`..${sep}`) || target.startsWith("../") || /^[A-Za-z]:|^[\\/]/.test(target))
1749
+ return "";
1750
+ }
1751
+ return directory;
1752
+ }
1753
+ /** Moves blockers confined to directories out of `adapterBlockers` and returns them scoped to those
1754
+ * directories (2026-11-08: Sentry's JavaScript SDK keeps 19 Nuxt, SvelteKit and Vue E2E applications whose
1755
+ * tsconfig extends generated `.nuxt/`/`.svelte-kit/` files; they made every change in its SDK packages fall
1756
+ * back to full validation, although no package imports them). A blocker with any unconfined file, or with
1757
+ * no recorded files, stays global. */
1758
+ function scopeAdapterBlockers(adapterBlockers, scopes) {
1759
+ const scoped = new Map();
1760
+ for (const reason of new Set(adapterBlockers)) {
1761
+ const directories = scopes.get(reason);
1762
+ if (!directories?.size || directories.has(""))
1763
+ continue;
1764
+ scoped.set(reason, directories);
1765
+ }
1766
+ for (let i = adapterBlockers.length - 1; i >= 0; i--)
1767
+ if (scoped.has(adapterBlockers[i]))
1768
+ adapterBlockers.splice(i, 1);
1769
+ return [...scoped].map(([reason, directories]) => ({ reason, directories: [...directories].sort() }));
1770
+ }
1771
+ /** A declared workspace package imported by name that resolves to no repository file, typically because
1772
+ * dependencies are not installed, hides every edge into that package (2026-11-08: in an uninstalled
1773
+ * Sentry checkout, 18 packages import `@sentry/server-utils`, and none of those edges existed). A change
1774
+ * reaching the package then falls back instead of skipping its dependents. */
1775
+ function uninstalledWorkspaceBlockers(repoPath, references, workspaceRoots) {
1776
+ const external = references.filter((ref) => ref.resolution === "external-package");
1777
+ if (!external.length)
1778
+ return [];
1779
+ const packages = new Map();
1780
+ for (const root of workspaceRoots) {
1781
+ try {
1782
+ const name = JSON.parse(readFileSync(join(repoPath, root, "package.json"), "utf8"))?.name;
1783
+ if (typeof name === "string" && name)
1784
+ packages.set(name, root);
1785
+ }
1786
+ catch { /* an unreadable manifest names no package */ }
1787
+ }
1788
+ if (!packages.size)
1789
+ return [];
1790
+ const importers = new Map();
1791
+ for (const ref of external) {
1792
+ const parts = ref.specifier.split("/");
1793
+ const name = ref.specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
1794
+ if (!packages.has(name))
1795
+ continue;
1796
+ let set = importers.get(name);
1797
+ if (!set)
1798
+ importers.set(name, set = new Set());
1799
+ set.add(ref.importer);
1800
+ }
1801
+ return [...importers].sort(([a], [b]) => a.localeCompare(b)).map(([name, files]) => ({
1802
+ reason: `Workspace package ${name} is imported by ${files.size} file${files.size === 1 ? "" : "s"} but does not resolve to its repository sources; install and link dependencies before analysis`,
1803
+ directories: [packages.get(name)],
1804
+ }));
1805
+ }
1629
1806
  /** Why the graph's own confidence is below COMPLETE, in counts only (no paths), so a report can say why a
1630
1807
  * repository-wide UNSAFE did not decide this change's verdict. 2026-11-06: every LobeHub receipt read
1631
1808
  * "UNSAFE" beside "safe to propose" with nothing connecting the two. Empty when the graph is COMPLETE. */
@@ -1638,6 +1815,8 @@ export function explainGraphConfidence(result) {
1638
1815
  reasons.push(`${plural(result.integrity.criticalCount, "graph integrity problem")}; every change falls back to full validation`);
1639
1816
  if (result.adapterBlockers?.length)
1640
1817
  reasons.push(`${plural(result.adapterBlockers.length, "unsupported framework or language relationship")}; every change falls back to full validation`);
1818
+ if (result.scopedAdapterBlockers?.length)
1819
+ reasons.push(`${plural(result.scopedAdapterBlockers.length, "unsupported relationship")} confined to package directories; a change that reaches one falls back to full validation`);
1641
1820
  const computed = result.unresolved.filter((ref) => ref.computed);
1642
1821
  const staticRefs = result.unresolved.filter((ref) => !ref.computed);
1643
1822
  if (computed.length) {