@getcodesentinel/codesentinel 1.33.0 → 1.33.1

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.
@@ -14,7 +14,7 @@
14
14
  href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&display=swap"
15
15
  rel="stylesheet"
16
16
  />
17
- <script type="module" crossorigin src="./assets/index-CH1ayI_3.js"></script>
17
+ <script type="module" crossorigin src="./assets/index-Byv8gMRD.js"></script>
18
18
  <link rel="stylesheet" crossorigin href="./assets/index-Dkq-kKM9.css">
19
19
  </head>
20
20
  <body>
package/dist/index.js CHANGED
@@ -15,6 +15,14 @@ import { mkdir, readdir, readFile, rename, stat, unlink, writeFile } from "fs/pr
15
15
  import { join as join3 } from "path";
16
16
  import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync2, statSync } from "fs";
17
17
  import { basename, join as join5, relative, resolve } from "path";
18
+ var DEFAULT_EXTERNAL_ANALYSIS_CONFIG = {
19
+ abandonedDaysThreshold: 540,
20
+ deepChainThreshold: 6,
21
+ fanOutHighThreshold: 25,
22
+ centralityTopN: 20,
23
+ maxHighRiskDependencies: 100,
24
+ metadataRequestConcurrency: 8
25
+ };
18
26
  var round4 = (value) => Number(value.toFixed(4));
19
27
  var normalizeNodes = (nodes) => {
20
28
  const byName = /* @__PURE__ */ new Map();
@@ -345,14 +353,6 @@ var buildExternalAnalysisSummary = (targetPath, extraction, metadataByKey, confi
345
353
  centralityRanking
346
354
  };
347
355
  };
348
- var DEFAULT_EXTERNAL_ANALYSIS_CONFIG = {
349
- abandonedDaysThreshold: 540,
350
- deepChainThreshold: 6,
351
- fanOutHighThreshold: 25,
352
- centralityTopN: 20,
353
- maxHighRiskDependencies: 100,
354
- metadataRequestConcurrency: 8
355
- };
356
356
  var mapWithConcurrency = async (values, limit, handler) => {
357
357
  const effectiveLimit = Math.max(1, limit);
358
358
  const workerCount = Math.min(effectiveLimit, values.length);
@@ -395,6 +395,25 @@ var collectDependencyMetadata = async (extraction, metadataProvider, concurrency
395
395
  return result;
396
396
  });
397
397
  };
398
+ var buildDependencyExposureSummary = async (input) => {
399
+ const metadataEntries = await collectDependencyMetadata(
400
+ input.extraction,
401
+ input.metadataProvider,
402
+ input.config.metadataRequestConcurrency,
403
+ input.onMetadataProgress
404
+ );
405
+ const metadataByKey = /* @__PURE__ */ new Map();
406
+ for (const entry of metadataEntries) {
407
+ metadataByKey.set(entry.key, entry.metadata);
408
+ }
409
+ return buildExternalAnalysisSummary(
410
+ input.targetPath,
411
+ input.extraction,
412
+ metadataByKey,
413
+ input.config,
414
+ input.workspaceManifests ?? []
415
+ );
416
+ };
398
417
  var LOCKFILE_CANDIDATES = [
399
418
  { fileName: "pnpm-lock.yaml", kind: "pnpm" },
400
419
  { fileName: "package-lock.json", kind: "npm" },
@@ -1641,7 +1660,7 @@ var withDefaults = (overrides) => ({
1641
1660
  ...DEFAULT_EXTERNAL_ANALYSIS_CONFIG,
1642
1661
  ...overrides
1643
1662
  });
1644
- var analyzeDependencyExposure = async (input, metadataProvider, onProgress) => {
1663
+ var analyzeDependencyExposure = async (input, metadataProvider, onProgress, loadWorkspaceManifests = loadWorkspaceDependencyManifests) => {
1645
1664
  const config = withDefaults(input.config);
1646
1665
  try {
1647
1666
  const prepared = await prepareDependencyExtraction(input.repositoryPath);
@@ -1661,29 +1680,20 @@ var analyzeDependencyExposure = async (input, metadataProvider, onProgress) => {
1661
1680
  directDependencies: extraction.directDependencies.length
1662
1681
  });
1663
1682
  onProgress?.({ stage: "metadata_fetch_started", total: extraction.nodes.length });
1664
- const metadataEntries = await collectDependencyMetadata(
1683
+ const summary = await buildDependencyExposureSummary({
1684
+ targetPath: input.repositoryPath,
1665
1685
  extraction,
1666
1686
  metadataProvider,
1667
- config.metadataRequestConcurrency,
1668
- (event) => onProgress?.({
1687
+ config,
1688
+ workspaceManifests: loadWorkspaceManifests(input.repositoryPath),
1689
+ onMetadataProgress: (event) => onProgress?.({
1669
1690
  stage: "metadata_fetch_progress",
1670
1691
  completed: event.completed,
1671
1692
  total: event.total,
1672
1693
  packageName: event.packageName
1673
1694
  })
1674
- );
1695
+ });
1675
1696
  onProgress?.({ stage: "metadata_fetch_completed", total: extraction.nodes.length });
1676
- const metadataByKey = /* @__PURE__ */ new Map();
1677
- for (const entry of metadataEntries) {
1678
- metadataByKey.set(entry.key, entry.metadata);
1679
- }
1680
- const summary = buildExternalAnalysisSummary(
1681
- input.repositoryPath,
1682
- extraction,
1683
- metadataByKey,
1684
- config,
1685
- loadWorkspaceDependencyManifests(input.repositoryPath)
1686
- );
1687
1697
  if (summary.available) {
1688
1698
  onProgress?.({
1689
1699
  stage: "summary_built",
@@ -1742,29 +1752,6 @@ var parseDependencySpec = (value) => {
1742
1752
  }
1743
1753
  return { name, requested };
1744
1754
  };
1745
- var mapWithConcurrency2 = async (values, limit, handler) => {
1746
- const effectiveLimit = Math.max(1, limit);
1747
- const workerCount = Math.min(effectiveLimit, values.length);
1748
- const UNSET = /* @__PURE__ */ Symbol("map_with_concurrency_unset");
1749
- const results = new Array(values.length).fill(UNSET);
1750
- let index = 0;
1751
- const workers = Array.from({ length: workerCount }, async () => {
1752
- while (true) {
1753
- const current = index;
1754
- index += 1;
1755
- if (current >= values.length) {
1756
- return;
1757
- }
1758
- const value = values[current];
1759
- results[current] = await handler(value);
1760
- }
1761
- });
1762
- await Promise.all(workers);
1763
- if (results.some((value) => value === UNSET)) {
1764
- throw new Error("map_with_concurrency_incomplete_results");
1765
- }
1766
- return results;
1767
- };
1768
1755
  var analyzeDependencyCandidate = async (input, metadataProvider) => {
1769
1756
  const parsed = parseDependencySpec(input.dependency);
1770
1757
  if (parsed === null) {
@@ -1795,20 +1782,6 @@ var analyzeDependencyCandidate = async (input, metadataProvider) => {
1795
1782
  dependency: input.dependency
1796
1783
  };
1797
1784
  }
1798
- const metadataEntries = await mapWithConcurrency2(
1799
- graph.nodes,
1800
- config.metadataRequestConcurrency,
1801
- async (node) => ({
1802
- key: `${node.name}@${node.version}`,
1803
- metadata: await metadataProvider.getMetadata(node.name, node.version, {
1804
- directDependency: node.name === parsed.name
1805
- })
1806
- })
1807
- );
1808
- const metadataByKey = /* @__PURE__ */ new Map();
1809
- for (const entry of metadataEntries) {
1810
- metadataByKey.set(entry.key, entry.metadata);
1811
- }
1812
1785
  const extraction = {
1813
1786
  kind: "npm",
1814
1787
  directDependencies: [
@@ -1820,12 +1793,12 @@ var analyzeDependencyCandidate = async (input, metadataProvider) => {
1820
1793
  ],
1821
1794
  nodes: graph.nodes
1822
1795
  };
1823
- const external = buildExternalAnalysisSummary(
1824
- `npm:${parsed.name}`,
1796
+ const external = await buildDependencyExposureSummary({
1797
+ targetPath: `npm:${parsed.name}`,
1825
1798
  extraction,
1826
- metadataByKey,
1799
+ metadataProvider,
1827
1800
  config
1828
- );
1801
+ });
1829
1802
  return {
1830
1803
  available: true,
1831
1804
  dependency: {
@@ -4864,6 +4837,35 @@ ${PROMPT_PADDING}Command exited with code ${exitCode}.
4864
4837
  // src/application/run-analyze-command.ts
4865
4838
  import { resolve as resolve4 } from "path";
4866
4839
 
4840
+ // ../core/dist/index.js
4841
+ var normalizeWorkspacePath = (pathValue) => pathValue.replaceAll("\\", "/");
4842
+ var fileBelongsToWorkspace = (filePath, workspace) => {
4843
+ const normalizedFilePath = normalizeWorkspacePath(filePath);
4844
+ const normalizedWorkspacePath = normalizeWorkspacePath(workspace.path);
4845
+ return normalizedFilePath === normalizedWorkspacePath || normalizedFilePath.startsWith(`${normalizedWorkspacePath}/`);
4846
+ };
4847
+ var findWorkspaceForFile = (filePath, workspaces) => {
4848
+ let match = null;
4849
+ for (const workspace of workspaces) {
4850
+ if (fileBelongsToWorkspace(filePath, workspace)) {
4851
+ if (match === null || workspace.path.length > match.path.length) {
4852
+ match = workspace;
4853
+ }
4854
+ }
4855
+ }
4856
+ return match;
4857
+ };
4858
+ var createWorkspaceByFile = (filePaths2, workspaces) => {
4859
+ const workspaceByFile = /* @__PURE__ */ new Map();
4860
+ for (const filePath of filePaths2) {
4861
+ const workspace = findWorkspaceForFile(filePath, workspaces);
4862
+ if (workspace !== null) {
4863
+ workspaceByFile.set(filePath, workspace);
4864
+ }
4865
+ }
4866
+ return workspaceByFile;
4867
+ };
4868
+
4867
4869
  // ../code-graph/dist/index.js
4868
4870
  import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
4869
4871
  import { extname, isAbsolute, join as join8, relative as relative2, resolve as resolve3 } from "path";
@@ -5064,26 +5066,11 @@ var computeCyclesAndDepth = (graph) => {
5064
5066
  cycles
5065
5067
  };
5066
5068
  };
5067
- var findWorkspaceForFile = (filePath, workspaces) => {
5068
- let match = null;
5069
- for (const workspace of workspaces) {
5070
- if (filePath === workspace.path || filePath.startsWith(`${workspace.path}/`)) {
5071
- if (match === null || workspace.path.length > match.path.length) {
5072
- match = workspace;
5073
- }
5074
- }
5075
- }
5076
- return match;
5077
- };
5078
- var createWorkspaceByFile = (graph, workspaces) => {
5079
- const workspaceByFile = /* @__PURE__ */ new Map();
5080
- for (const node of graph.nodes) {
5081
- const workspace = findWorkspaceForFile(node.id, workspaces);
5082
- if (workspace !== null) {
5083
- workspaceByFile.set(node.id, workspace);
5084
- }
5085
- }
5086
- return workspaceByFile;
5069
+ var createWorkspaceByFile2 = (graph, workspaces) => {
5070
+ return createWorkspaceByFile(
5071
+ graph.nodes.map((node) => node.id),
5072
+ workspaces
5073
+ );
5087
5074
  };
5088
5075
  var createCrossWorkspaceEdges = (graph, workspaceByFile) => {
5089
5076
  const edges = [];
@@ -5199,7 +5186,7 @@ var createGraphAnalysisSummary = (targetPath, graph, workspaces = []) => {
5199
5186
  maxFanIn,
5200
5187
  maxFanOut
5201
5188
  };
5202
- const workspaceByFile = createWorkspaceByFile(graph, workspaces);
5189
+ const workspaceByFile = createWorkspaceByFile2(graph, workspaces);
5203
5190
  return {
5204
5191
  targetPath,
5205
5192
  nodes: graph.nodes,
@@ -6233,37 +6220,22 @@ var analyzeRepositoryEvolution = (input, historyProvider, onProgress) => {
6233
6220
  onProgress?.({ stage: "analysis_completed", available: summary.available });
6234
6221
  return summary;
6235
6222
  };
6236
- var normalizePath3 = (pathValue) => pathValue.replaceAll("\\", "/");
6237
- var findWorkspaceForFile2 = (filePath, workspaces) => {
6238
- let match = null;
6239
- for (const workspace of workspaces) {
6240
- if (filePath === workspace.path || filePath.startsWith(`${workspace.path}/`)) {
6241
- if (match === null || workspace.path.length > match.path.length) {
6242
- match = workspace;
6243
- }
6244
- }
6245
- }
6246
- return match;
6247
- };
6248
6223
  var enrichEvolutionSummaryWithWorkspaces = (structural, evolution) => {
6249
6224
  if (!evolution.available || structural.workspaces === void 0) {
6250
6225
  return evolution;
6251
6226
  }
6252
6227
  const workspaces = structural.workspaces;
6253
- const workspaceByFile = /* @__PURE__ */ new Map();
6228
+ const workspaceByFile = createWorkspaceByFile(
6229
+ evolution.files.map((file) => normalizeWorkspacePath(file.filePath)),
6230
+ workspaces
6231
+ );
6254
6232
  const structuralWorkspacePaths = new Set(workspaces.map((workspace) => workspace.path));
6255
- for (const file of evolution.files) {
6256
- const workspace = findWorkspaceForFile2(normalizePath3(file.filePath), workspaces);
6257
- if (workspace !== null) {
6258
- workspaceByFile.set(normalizePath3(file.filePath), workspace);
6259
- }
6260
- }
6261
6233
  const internalCouplingPairCountByWorkspace = /* @__PURE__ */ new Map();
6262
6234
  const incomingCouplingPairCountByWorkspace = /* @__PURE__ */ new Map();
6263
6235
  const outgoingCouplingPairCountByWorkspace = /* @__PURE__ */ new Map();
6264
6236
  for (const pair of evolution.coupling.pairs) {
6265
- const fromWorkspace = workspaceByFile.get(normalizePath3(pair.fileA));
6266
- const toWorkspace = workspaceByFile.get(normalizePath3(pair.fileB));
6237
+ const fromWorkspace = workspaceByFile.get(normalizeWorkspacePath(pair.fileA));
6238
+ const toWorkspace = workspaceByFile.get(normalizeWorkspacePath(pair.fileB));
6267
6239
  if (fromWorkspace === void 0 && toWorkspace === void 0) {
6268
6240
  continue;
6269
6241
  }
@@ -6289,7 +6261,7 @@ var enrichEvolutionSummaryWithWorkspaces = (structural, evolution) => {
6289
6261
  }
6290
6262
  const workspaceSummaries = workspaces.filter((workspace) => structuralWorkspacePaths.has(workspace.path)).map((workspace) => {
6291
6263
  const files = evolution.files.filter(
6292
- (file) => workspaceByFile.get(normalizePath3(file.filePath))?.path === workspace.path
6264
+ (file) => workspaceByFile.get(normalizeWorkspacePath(file.filePath))?.path === workspace.path
6293
6265
  ).sort((a, b) => a.filePath.localeCompare(b.filePath));
6294
6266
  const commitCount = files.reduce((sum, file) => sum + file.commitCount, 0);
6295
6267
  const recentCommitCount = files.reduce((sum, file) => sum + file.recentCommitCount, 0);
@@ -6299,7 +6271,7 @@ var enrichEvolutionSummaryWithWorkspaces = (structural, evolution) => {
6299
6271
  const topAuthorShareByCommits = files.length === 0 ? 0 : Math.max(...files.map((file) => file.topAuthorShareByCommits));
6300
6272
  const busFactorByCommits = files.length === 0 ? 0 : Math.min(...files.map((file) => file.busFactorByCommits));
6301
6273
  const topHotspots = evolution.hotspots.filter(
6302
- (hotspot) => workspaceByFile.get(normalizePath3(hotspot.filePath))?.path === workspace.path
6274
+ (hotspot) => workspaceByFile.get(normalizeWorkspacePath(hotspot.filePath))?.path === workspace.path
6303
6275
  );
6304
6276
  return {
6305
6277
  name: workspace.name,
@@ -6604,9 +6576,9 @@ var createDimensionTrace = (dimension, health, factors) => ({
6604
6576
  factors: factors.map((factor) => toFactorTrace(factor))
6605
6577
  });
6606
6578
  var filePaths = (structural) => structural.files.map((file) => file.relativePath);
6607
- var normalizePath4 = (value) => value.replaceAll("\\", "/").toLowerCase();
6579
+ var normalizePath3 = (value) => value.replaceAll("\\", "/").toLowerCase();
6608
6580
  var isTestPath = (path) => {
6609
- const normalized = normalizePath4(path);
6581
+ const normalized = normalizePath3(path);
6610
6582
  return normalized.includes("/__tests__/") || normalized.includes("/tests/") || normalized.includes("/test/") || normalized.includes(".test.") || normalized.includes(".spec.");
6611
6583
  };
6612
6584
  var isSourcePath = (path) => {
@@ -6616,7 +6588,7 @@ var isSourcePath = (path) => {
6616
6588
  return !isTestPath(path);
6617
6589
  };
6618
6590
  var hasTestDirectory = (paths) => paths.some((path) => {
6619
- const normalized = normalizePath4(path);
6591
+ const normalized = normalizePath3(path);
6620
6592
  return normalized.includes("/__tests__/") || normalized.includes("/tests/") || normalized.includes("/test/");
6621
6593
  });
6622
6594
  var moduleNameFromPath = (path) => {
@@ -7506,7 +7478,7 @@ var normalizeWithScale = (value, scale) => {
7506
7478
  }
7507
7479
  return toUnitInterval((value - scale.lower) / (scale.upper - scale.lower));
7508
7480
  };
7509
- var normalizePath5 = (path) => path.replaceAll("\\", "/");
7481
+ var normalizePath4 = (path) => path.replaceAll("\\", "/");
7510
7482
  var computeAggregatorAttenuation = (input) => {
7511
7483
  const { fanIn, fanOut, inCycle, evolutionMetrics, config } = input;
7512
7484
  if (!config.enabled || inCycle > 0) {
@@ -7581,7 +7553,7 @@ var computeEvolutionHistoryConfidence = (structural, evolution, evolutionByFile)
7581
7553
  }
7582
7554
  let coveredFiles = 0;
7583
7555
  for (const file of structural.files) {
7584
- if (evolutionByFile.has(normalizePath5(file.id))) {
7556
+ if (evolutionByFile.has(normalizePath4(file.id))) {
7585
7557
  coveredFiles += 1;
7586
7558
  }
7587
7559
  }
@@ -7775,7 +7747,7 @@ var mapEvolutionByFile = (evolution) => {
7775
7747
  return /* @__PURE__ */ new Map();
7776
7748
  }
7777
7749
  return new Map(
7778
- evolution.files.map((fileMetrics) => [normalizePath5(fileMetrics.filePath), fileMetrics])
7750
+ evolution.files.map((fileMetrics) => [normalizePath4(fileMetrics.filePath), fileMetrics])
7779
7751
  );
7780
7752
  };
7781
7753
  var computeEvolutionScales = (evolutionByFile, config) => {
@@ -7799,7 +7771,7 @@ var computeEvolutionScales = (evolutionByFile, config) => {
7799
7771
  };
7800
7772
  };
7801
7773
  var inferModuleName = (filePath, config) => {
7802
- const normalized = normalizePath5(filePath);
7774
+ const normalized = normalizePath4(filePath);
7803
7775
  const parts = normalized.split("/").filter((part) => part.length > 0);
7804
7776
  if (parts.length <= 1) {
7805
7777
  return config.module.rootLabel;
@@ -7820,7 +7792,7 @@ var buildFragileClusters = (structural, evolution, fileScoresByFile, config) =>
7820
7792
  const clusters = [];
7821
7793
  let cycleClusterCount = 0;
7822
7794
  for (const cycle of structural.cycles) {
7823
- const files = [...new Set(cycle.nodes.map((node) => normalizePath5(node)))].filter(
7795
+ const files = [...new Set(cycle.nodes.map((node) => normalizePath4(node)))].filter(
7824
7796
  (filePath) => fileScoresByFile.has(filePath)
7825
7797
  );
7826
7798
  if (files.length < 2) {
@@ -7852,8 +7824,8 @@ var buildFragileClusters = (structural, evolution, fileScoresByFile, config) =>
7852
7824
  )
7853
7825
  );
7854
7826
  const selectedPairs = candidates.filter((pair) => pair.couplingScore >= threshold).map((pair) => ({
7855
- fileA: normalizePath5(pair.fileA),
7856
- fileB: normalizePath5(pair.fileB),
7827
+ fileA: normalizePath4(pair.fileA),
7828
+ fileB: normalizePath4(pair.fileB),
7857
7829
  couplingScore: pair.couplingScore
7858
7830
  })).filter(
7859
7831
  (pair) => pair.fileA !== pair.fileB && fileScoresByFile.has(pair.fileA) && fileScoresByFile.has(pair.fileB)
@@ -7932,9 +7904,7 @@ var buildWorkspaceRiskScores = (structural, fileScoresByFile) => {
7932
7904
  0
7933
7905
  );
7934
7906
  return structural.workspaces.map((workspace) => {
7935
- const workspaceFileScores = [...fileScoresByFile.values()].filter(
7936
- (fileScore) => fileScore.file === workspace.path || fileScore.file.startsWith(`${workspace.path}/`)
7937
- ).sort((a, b) => b.score - a.score || a.file.localeCompare(b.file));
7907
+ const workspaceFileScores = [...fileScoresByFile.values()].filter((fileScore) => fileBelongsToWorkspace(fileScore.file, workspace)).sort((a, b) => b.score - a.score || a.file.localeCompare(b.file));
7938
7908
  const averageFileRisk = average3(
7939
7909
  workspaceFileScores.map((fileScore) => fileScore.normalizedScore)
7940
7910
  );
@@ -7974,7 +7944,7 @@ var computeRiskSummary = (structural, evolution, external, config, traceCollecto
7974
7944
  );
7975
7945
  const evolutionScales = computeEvolutionScales(evolutionByFile, config);
7976
7946
  const cycleFileSet = new Set(
7977
- structural.cycles.flatMap((cycle) => cycle.nodes.map((node) => normalizePath5(node)))
7947
+ structural.cycles.flatMap((cycle) => cycle.nodes.map((node) => normalizePath4(node)))
7978
7948
  );
7979
7949
  const fanInScale = buildQuantileScale(
7980
7950
  structural.files.map((file) => logScale(file.fanIn)),
@@ -7997,7 +7967,7 @@ var computeRiskSummary = (structural, evolution, external, config, traceCollecto
7997
7967
  external: external.available
7998
7968
  });
7999
7969
  const fileRiskContexts = structural.files.map((file) => {
8000
- const filePath = normalizePath5(file.id);
7970
+ const filePath = normalizePath4(file.id);
8001
7971
  const inCycle = cycleFileSet.has(filePath) ? 1 : 0;
8002
7972
  const fanInRisk = normalizeWithScale(logScale(file.fanIn), fanInScale);
8003
7973
  const fanOutRisk = normalizeWithScale(logScale(file.fanOut), fanOutScale);