@getcodesentinel/codesentinel 1.31.0 → 1.32.0
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/dist/index.js +154 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5794,6 +5794,101 @@ var analyzeRepositoryEvolution = (input, historyProvider, onProgress) => {
|
|
|
5794
5794
|
onProgress?.({ stage: "analysis_completed", available: summary.available });
|
|
5795
5795
|
return summary;
|
|
5796
5796
|
};
|
|
5797
|
+
var normalizePath3 = (pathValue) => pathValue.replaceAll("\\", "/");
|
|
5798
|
+
var findWorkspaceForFile2 = (filePath, workspaces) => {
|
|
5799
|
+
let match = null;
|
|
5800
|
+
for (const workspace of workspaces) {
|
|
5801
|
+
if (filePath === workspace.path || filePath.startsWith(`${workspace.path}/`)) {
|
|
5802
|
+
if (match === null || workspace.path.length > match.path.length) {
|
|
5803
|
+
match = workspace;
|
|
5804
|
+
}
|
|
5805
|
+
}
|
|
5806
|
+
}
|
|
5807
|
+
return match;
|
|
5808
|
+
};
|
|
5809
|
+
var enrichEvolutionSummaryWithWorkspaces = (structural, evolution) => {
|
|
5810
|
+
if (!evolution.available || structural.workspaces === void 0) {
|
|
5811
|
+
return evolution;
|
|
5812
|
+
}
|
|
5813
|
+
const workspaces = structural.workspaces;
|
|
5814
|
+
const workspaceByFile = /* @__PURE__ */ new Map();
|
|
5815
|
+
const structuralWorkspacePaths = new Set(workspaces.map((workspace) => workspace.path));
|
|
5816
|
+
for (const file of evolution.files) {
|
|
5817
|
+
const workspace = findWorkspaceForFile2(normalizePath3(file.filePath), workspaces);
|
|
5818
|
+
if (workspace !== null) {
|
|
5819
|
+
workspaceByFile.set(normalizePath3(file.filePath), workspace);
|
|
5820
|
+
}
|
|
5821
|
+
}
|
|
5822
|
+
const internalCouplingPairCountByWorkspace = /* @__PURE__ */ new Map();
|
|
5823
|
+
const incomingCouplingPairCountByWorkspace = /* @__PURE__ */ new Map();
|
|
5824
|
+
const outgoingCouplingPairCountByWorkspace = /* @__PURE__ */ new Map();
|
|
5825
|
+
for (const pair of evolution.coupling.pairs) {
|
|
5826
|
+
const fromWorkspace = workspaceByFile.get(normalizePath3(pair.fileA));
|
|
5827
|
+
const toWorkspace = workspaceByFile.get(normalizePath3(pair.fileB));
|
|
5828
|
+
if (fromWorkspace === void 0 && toWorkspace === void 0) {
|
|
5829
|
+
continue;
|
|
5830
|
+
}
|
|
5831
|
+
if (fromWorkspace?.path === toWorkspace?.path && fromWorkspace !== void 0) {
|
|
5832
|
+
internalCouplingPairCountByWorkspace.set(
|
|
5833
|
+
fromWorkspace.path,
|
|
5834
|
+
(internalCouplingPairCountByWorkspace.get(fromWorkspace.path) ?? 0) + 1
|
|
5835
|
+
);
|
|
5836
|
+
continue;
|
|
5837
|
+
}
|
|
5838
|
+
if (fromWorkspace !== void 0) {
|
|
5839
|
+
outgoingCouplingPairCountByWorkspace.set(
|
|
5840
|
+
fromWorkspace.path,
|
|
5841
|
+
(outgoingCouplingPairCountByWorkspace.get(fromWorkspace.path) ?? 0) + 1
|
|
5842
|
+
);
|
|
5843
|
+
}
|
|
5844
|
+
if (toWorkspace !== void 0) {
|
|
5845
|
+
incomingCouplingPairCountByWorkspace.set(
|
|
5846
|
+
toWorkspace.path,
|
|
5847
|
+
(incomingCouplingPairCountByWorkspace.get(toWorkspace.path) ?? 0) + 1
|
|
5848
|
+
);
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5851
|
+
const workspaceSummaries = workspaces.filter((workspace) => structuralWorkspacePaths.has(workspace.path)).map((workspace) => {
|
|
5852
|
+
const files = evolution.files.filter(
|
|
5853
|
+
(file) => workspaceByFile.get(normalizePath3(file.filePath))?.path === workspace.path
|
|
5854
|
+
).sort((a, b) => a.filePath.localeCompare(b.filePath));
|
|
5855
|
+
const commitCount = files.reduce((sum, file) => sum + file.commitCount, 0);
|
|
5856
|
+
const recentCommitCount = files.reduce((sum, file) => sum + file.recentCommitCount, 0);
|
|
5857
|
+
const churnAdded = files.reduce((sum, file) => sum + file.churnAdded, 0);
|
|
5858
|
+
const churnDeleted = files.reduce((sum, file) => sum + file.churnDeleted, 0);
|
|
5859
|
+
const churnTotal = churnAdded + churnDeleted;
|
|
5860
|
+
const topAuthorShareByCommits = files.length === 0 ? 0 : Math.max(...files.map((file) => file.topAuthorShareByCommits));
|
|
5861
|
+
const busFactorByCommits = files.length === 0 ? 0 : Math.min(...files.map((file) => file.busFactorByCommits));
|
|
5862
|
+
const topHotspots = evolution.hotspots.filter(
|
|
5863
|
+
(hotspot) => workspaceByFile.get(normalizePath3(hotspot.filePath))?.path === workspace.path
|
|
5864
|
+
);
|
|
5865
|
+
return {
|
|
5866
|
+
name: workspace.name,
|
|
5867
|
+
path: workspace.path,
|
|
5868
|
+
kind: workspace.kind,
|
|
5869
|
+
fileCount: files.length,
|
|
5870
|
+
commitCount,
|
|
5871
|
+
churnAdded,
|
|
5872
|
+
churnDeleted,
|
|
5873
|
+
churnTotal,
|
|
5874
|
+
recentCommitCount,
|
|
5875
|
+
recentVolatility: commitCount === 0 ? 0 : Number((recentCommitCount / commitCount).toFixed(4)),
|
|
5876
|
+
topAuthorShareByCommits,
|
|
5877
|
+
busFactorByCommits,
|
|
5878
|
+
hotspotCount: topHotspots.length,
|
|
5879
|
+
topHotspots,
|
|
5880
|
+
internalCouplingPairCount: internalCouplingPairCountByWorkspace.get(workspace.path) ?? 0,
|
|
5881
|
+
incomingCouplingPairCount: incomingCouplingPairCountByWorkspace.get(workspace.path) ?? 0,
|
|
5882
|
+
outgoingCouplingPairCount: outgoingCouplingPairCountByWorkspace.get(workspace.path) ?? 0
|
|
5883
|
+
};
|
|
5884
|
+
}).sort(
|
|
5885
|
+
(a, b) => b.commitCount - a.commitCount || b.churnTotal - a.churnTotal || a.path.localeCompare(b.path)
|
|
5886
|
+
);
|
|
5887
|
+
return {
|
|
5888
|
+
...evolution,
|
|
5889
|
+
workspaces: workspaceSummaries
|
|
5890
|
+
};
|
|
5891
|
+
};
|
|
5797
5892
|
var GitCommandError = class extends Error {
|
|
5798
5893
|
args;
|
|
5799
5894
|
constructor(message, args) {
|
|
@@ -6070,9 +6165,9 @@ var createDimensionTrace = (dimension, health, factors) => ({
|
|
|
6070
6165
|
factors: factors.map((factor) => toFactorTrace(factor))
|
|
6071
6166
|
});
|
|
6072
6167
|
var filePaths = (structural) => structural.files.map((file) => file.relativePath);
|
|
6073
|
-
var
|
|
6168
|
+
var normalizePath4 = (value) => value.replaceAll("\\", "/").toLowerCase();
|
|
6074
6169
|
var isTestPath = (path) => {
|
|
6075
|
-
const normalized =
|
|
6170
|
+
const normalized = normalizePath4(path);
|
|
6076
6171
|
return normalized.includes("/__tests__/") || normalized.includes("/tests/") || normalized.includes("/test/") || normalized.includes(".test.") || normalized.includes(".spec.");
|
|
6077
6172
|
};
|
|
6078
6173
|
var isSourcePath = (path) => {
|
|
@@ -6082,7 +6177,7 @@ var isSourcePath = (path) => {
|
|
|
6082
6177
|
return !isTestPath(path);
|
|
6083
6178
|
};
|
|
6084
6179
|
var hasTestDirectory = (paths) => paths.some((path) => {
|
|
6085
|
-
const normalized =
|
|
6180
|
+
const normalized = normalizePath4(path);
|
|
6086
6181
|
return normalized.includes("/__tests__/") || normalized.includes("/tests/") || normalized.includes("/test/");
|
|
6087
6182
|
});
|
|
6088
6183
|
var moduleNameFromPath = (path) => {
|
|
@@ -6972,7 +7067,7 @@ var normalizeWithScale = (value, scale) => {
|
|
|
6972
7067
|
}
|
|
6973
7068
|
return toUnitInterval((value - scale.lower) / (scale.upper - scale.lower));
|
|
6974
7069
|
};
|
|
6975
|
-
var
|
|
7070
|
+
var normalizePath5 = (path) => path.replaceAll("\\", "/");
|
|
6976
7071
|
var computeAggregatorAttenuation = (input) => {
|
|
6977
7072
|
const { fanIn, fanOut, inCycle, evolutionMetrics, config } = input;
|
|
6978
7073
|
if (!config.enabled || inCycle > 0) {
|
|
@@ -7047,7 +7142,7 @@ var computeEvolutionHistoryConfidence = (structural, evolution, evolutionByFile)
|
|
|
7047
7142
|
}
|
|
7048
7143
|
let coveredFiles = 0;
|
|
7049
7144
|
for (const file of structural.files) {
|
|
7050
|
-
if (evolutionByFile.has(
|
|
7145
|
+
if (evolutionByFile.has(normalizePath5(file.id))) {
|
|
7051
7146
|
coveredFiles += 1;
|
|
7052
7147
|
}
|
|
7053
7148
|
}
|
|
@@ -7241,7 +7336,7 @@ var mapEvolutionByFile = (evolution) => {
|
|
|
7241
7336
|
return /* @__PURE__ */ new Map();
|
|
7242
7337
|
}
|
|
7243
7338
|
return new Map(
|
|
7244
|
-
evolution.files.map((fileMetrics) => [
|
|
7339
|
+
evolution.files.map((fileMetrics) => [normalizePath5(fileMetrics.filePath), fileMetrics])
|
|
7245
7340
|
);
|
|
7246
7341
|
};
|
|
7247
7342
|
var computeEvolutionScales = (evolutionByFile, config) => {
|
|
@@ -7265,7 +7360,7 @@ var computeEvolutionScales = (evolutionByFile, config) => {
|
|
|
7265
7360
|
};
|
|
7266
7361
|
};
|
|
7267
7362
|
var inferModuleName = (filePath, config) => {
|
|
7268
|
-
const normalized =
|
|
7363
|
+
const normalized = normalizePath5(filePath);
|
|
7269
7364
|
const parts = normalized.split("/").filter((part) => part.length > 0);
|
|
7270
7365
|
if (parts.length <= 1) {
|
|
7271
7366
|
return config.module.rootLabel;
|
|
@@ -7286,7 +7381,7 @@ var buildFragileClusters = (structural, evolution, fileScoresByFile, config) =>
|
|
|
7286
7381
|
const clusters = [];
|
|
7287
7382
|
let cycleClusterCount = 0;
|
|
7288
7383
|
for (const cycle of structural.cycles) {
|
|
7289
|
-
const files = [...new Set(cycle.nodes.map((node) =>
|
|
7384
|
+
const files = [...new Set(cycle.nodes.map((node) => normalizePath5(node)))].filter(
|
|
7290
7385
|
(filePath) => fileScoresByFile.has(filePath)
|
|
7291
7386
|
);
|
|
7292
7387
|
if (files.length < 2) {
|
|
@@ -7318,8 +7413,8 @@ var buildFragileClusters = (structural, evolution, fileScoresByFile, config) =>
|
|
|
7318
7413
|
)
|
|
7319
7414
|
);
|
|
7320
7415
|
const selectedPairs = candidates.filter((pair) => pair.couplingScore >= threshold).map((pair) => ({
|
|
7321
|
-
fileA:
|
|
7322
|
-
fileB:
|
|
7416
|
+
fileA: normalizePath5(pair.fileA),
|
|
7417
|
+
fileB: normalizePath5(pair.fileB),
|
|
7323
7418
|
couplingScore: pair.couplingScore
|
|
7324
7419
|
})).filter(
|
|
7325
7420
|
(pair) => pair.fileA !== pair.fileB && fileScoresByFile.has(pair.fileA) && fileScoresByFile.has(pair.fileB)
|
|
@@ -7385,6 +7480,49 @@ var buildFragileClusters = (structural, evolution, fileScoresByFile, config) =>
|
|
|
7385
7480
|
(a, b) => b.score - a.score || a.kind.localeCompare(b.kind) || a.id.localeCompare(b.id)
|
|
7386
7481
|
);
|
|
7387
7482
|
};
|
|
7483
|
+
var buildWorkspaceRiskScores = (structural, fileScoresByFile) => {
|
|
7484
|
+
if (structural.workspaces === void 0 || structural.workspaces.length === 0) {
|
|
7485
|
+
return [];
|
|
7486
|
+
}
|
|
7487
|
+
const maxIncomingEdges = structural.workspaces.reduce(
|
|
7488
|
+
(max, workspace) => Math.max(max, workspace.incomingEdgeCount),
|
|
7489
|
+
0
|
|
7490
|
+
);
|
|
7491
|
+
const maxOutgoingEdges = structural.workspaces.reduce(
|
|
7492
|
+
(max, workspace) => Math.max(max, workspace.outgoingEdgeCount),
|
|
7493
|
+
0
|
|
7494
|
+
);
|
|
7495
|
+
return structural.workspaces.map((workspace) => {
|
|
7496
|
+
const workspaceFileScores = [...fileScoresByFile.values()].filter(
|
|
7497
|
+
(fileScore) => fileScore.file === workspace.path || fileScore.file.startsWith(`${workspace.path}/`)
|
|
7498
|
+
).sort((a, b) => b.score - a.score || a.file.localeCompare(b.file));
|
|
7499
|
+
const averageFileRisk = average3(
|
|
7500
|
+
workspaceFileScores.map((fileScore) => fileScore.normalizedScore)
|
|
7501
|
+
);
|
|
7502
|
+
const peakFileRisk = workspaceFileScores.reduce(
|
|
7503
|
+
(max, fileScore) => Math.max(max, fileScore.normalizedScore),
|
|
7504
|
+
0
|
|
7505
|
+
);
|
|
7506
|
+
const incomingPressure = maxIncomingEdges <= 0 ? 0 : toUnitInterval(workspace.incomingEdgeCount / maxIncomingEdges);
|
|
7507
|
+
const outgoingPressure = maxOutgoingEdges <= 0 ? 0 : toUnitInterval(workspace.outgoingEdgeCount / maxOutgoingEdges);
|
|
7508
|
+
const structuralPressure = toUnitInterval(incomingPressure * 0.7 + outgoingPressure * 0.3);
|
|
7509
|
+
const normalizedScore = toUnitInterval(
|
|
7510
|
+
averageFileRisk * 0.5 + peakFileRisk * 0.3 + structuralPressure * 0.2
|
|
7511
|
+
);
|
|
7512
|
+
return {
|
|
7513
|
+
...workspace,
|
|
7514
|
+
score: round46(normalizedScore * 100),
|
|
7515
|
+
normalizedScore: round46(normalizedScore),
|
|
7516
|
+
averageFileRisk: round46(averageFileRisk),
|
|
7517
|
+
peakFileRisk: round46(peakFileRisk),
|
|
7518
|
+
topFiles: workspaceFileScores.slice(0, 5).map((fileScore) => ({
|
|
7519
|
+
file: fileScore.file,
|
|
7520
|
+
score: fileScore.score,
|
|
7521
|
+
factors: fileScore.factors
|
|
7522
|
+
}))
|
|
7523
|
+
};
|
|
7524
|
+
}).sort((a, b) => b.score - a.score || a.path.localeCompare(b.path));
|
|
7525
|
+
};
|
|
7388
7526
|
var computeRiskSummary = (structural, evolution, external, config, traceCollector) => {
|
|
7389
7527
|
const collector = traceCollector;
|
|
7390
7528
|
const dependencyComputation = computeDependencyScores(external, config);
|
|
@@ -7397,7 +7535,7 @@ var computeRiskSummary = (structural, evolution, external, config, traceCollecto
|
|
|
7397
7535
|
);
|
|
7398
7536
|
const evolutionScales = computeEvolutionScales(evolutionByFile, config);
|
|
7399
7537
|
const cycleFileSet = new Set(
|
|
7400
|
-
structural.cycles.flatMap((cycle) => cycle.nodes.map((node) =>
|
|
7538
|
+
structural.cycles.flatMap((cycle) => cycle.nodes.map((node) => normalizePath5(node)))
|
|
7401
7539
|
);
|
|
7402
7540
|
const fanInScale = buildQuantileScale(
|
|
7403
7541
|
structural.files.map((file) => logScale(file.fanIn)),
|
|
@@ -7420,7 +7558,7 @@ var computeRiskSummary = (structural, evolution, external, config, traceCollecto
|
|
|
7420
7558
|
external: external.available
|
|
7421
7559
|
});
|
|
7422
7560
|
const fileRiskContexts = structural.files.map((file) => {
|
|
7423
|
-
const filePath =
|
|
7561
|
+
const filePath = normalizePath5(file.id);
|
|
7424
7562
|
const inCycle = cycleFileSet.has(filePath) ? 1 : 0;
|
|
7425
7563
|
const fanInRisk = normalizeWithScale(logScale(file.fanIn), fanInScale);
|
|
7426
7564
|
const fanOutRisk = normalizeWithScale(logScale(file.fanOut), fanOutScale);
|
|
@@ -7689,6 +7827,7 @@ var computeRiskSummary = (structural, evolution, external, config, traceCollecto
|
|
|
7689
7827
|
collector.record(buildTargetTrace("module", module, totalScore, normalizedScore, factors));
|
|
7690
7828
|
}
|
|
7691
7829
|
}
|
|
7830
|
+
const workspaceScores = buildWorkspaceRiskScores(structural, fileScoresByFile);
|
|
7692
7831
|
const fragileClusters = buildFragileClusters(structural, evolution, fileScoresByFile, config);
|
|
7693
7832
|
const externalPressures = fileScores.map((fileScore) => fileScore.factors.external);
|
|
7694
7833
|
const pressureThreshold = Math.max(
|
|
@@ -7919,6 +8058,7 @@ var computeRiskSummary = (structural, evolution, external, config, traceCollecto
|
|
|
7919
8058
|
dependencyAmplificationZones,
|
|
7920
8059
|
fileScores,
|
|
7921
8060
|
moduleScores,
|
|
8061
|
+
workspaceScores,
|
|
7922
8062
|
dependencyScores: dependencyComputation.dependencyScores
|
|
7923
8063
|
};
|
|
7924
8064
|
};
|
|
@@ -8186,7 +8326,7 @@ var collectAnalysisInputs = async (inputPath, authorIdentityMode, options = {},
|
|
|
8186
8326
|
`structural metrics: nodes=${structural.metrics.nodeCount}, edges=${structural.metrics.edgeCount}, cycles=${structural.metrics.cycleCount}`
|
|
8187
8327
|
);
|
|
8188
8328
|
logger.info(`analyzing git evolution (author identity: ${authorIdentityMode})`);
|
|
8189
|
-
const
|
|
8329
|
+
const repositoryEvolution = analyzeRepositoryEvolutionFromGit(
|
|
8190
8330
|
{
|
|
8191
8331
|
repositoryPath: targetPath,
|
|
8192
8332
|
config: {
|
|
@@ -8196,6 +8336,7 @@ var collectAnalysisInputs = async (inputPath, authorIdentityMode, options = {},
|
|
|
8196
8336
|
},
|
|
8197
8337
|
createEvolutionProgressReporter(logger)
|
|
8198
8338
|
);
|
|
8339
|
+
const evolution = enrichEvolutionSummaryWithWorkspaces(structural, repositoryEvolution);
|
|
8199
8340
|
if (evolution.available) {
|
|
8200
8341
|
logger.debug(
|
|
8201
8342
|
`evolution metrics: commits=${evolution.metrics.totalCommits}, files=${evolution.metrics.totalFiles}, hotspotThreshold=${evolution.metrics.hotspotThresholdCommitCount}`
|