@getcodesentinel/codesentinel 1.27.2 → 1.28.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.
@@ -14,8 +14,8 @@
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-B6QA_23j.js"></script>
18
- <link rel="stylesheet" crossorigin href="./assets/index-DFl7wYWG.css">
17
+ <script type="module" crossorigin src="./assets/index-DSc-PQ_4.js"></script>
18
+ <link rel="stylesheet" crossorigin href="./assets/index-B_4tFxtt.css">
19
19
  </head>
20
20
  <body>
21
21
  <div id="root"></div>
package/dist/index.js CHANGED
@@ -2092,6 +2092,8 @@ var MODULE_KNOWLEDGE_LABEL_PRIORITY = {
2092
2092
  sparse: 1,
2093
2093
  distributed: 2
2094
2094
  };
2095
+ var clamp01 = (value) => Math.max(0, Math.min(1, value));
2096
+ var MIN_FRAGILE_AREA_TOTAL_COMMITS = 3;
2095
2097
  var fileOwnershipItems = (files) => {
2096
2098
  const labelPriority = {
2097
2099
  singleMaintainer: 0,
@@ -2117,32 +2119,7 @@ var fileOwnershipItems = (files) => {
2117
2119
  (a, b) => labelPriority[a.ownershipLabel] - labelPriority[b.ownershipLabel] || b.topAuthorShareByCommits - a.topAuthorShareByCommits || b.commitCount - a.commitCount || a.filePath.localeCompare(b.filePath)
2118
2120
  );
2119
2121
  };
2120
- var changeOwnershipSummary = (snapshot) => {
2121
- if (!snapshot.analysis.evolution.available) {
2122
- return {
2123
- available: false,
2124
- reason: snapshot.analysis.evolution.reason
2125
- };
2126
- }
2127
- const evolution = snapshot.analysis.evolution;
2128
- const files = evolution.files;
2129
- const ownershipReadyFiles = files.filter(
2130
- (file) => file.topAuthorShareByCommits !== null && file.authorDistributionByCommits.length > 0
2131
- );
2132
- const sharedOwnershipCount = ownershipReadyFiles.filter(
2133
- (file) => file.authorDistributionByCommits.length >= 2 && file.topAuthorShareByCommits <= 0.6
2134
- ).length;
2135
- const concentratedOwnershipCount = ownershipReadyFiles.filter(
2136
- (file) => file.authorDistributionByCommits.length >= 2 && file.topAuthorShareByCommits > 0.6
2137
- ).length;
2138
- const singleMaintainerCount = ownershipReadyFiles.filter(
2139
- (file) => file.authorDistributionByCommits.length <= 1
2140
- ).length;
2141
- const headCommitTimestamp = evolution.metrics.headCommitTimestamp;
2142
- const legacyNoActiveOwnerCount = ownershipReadyFiles.filter(
2143
- (file) => file.commitCount > 0 && file.lastCommitTimestamp !== null && headCommitTimestamp !== null && headCommitTimestamp - file.lastCommitTimestamp >= LEGACY_NO_ACTIVE_OWNER_DAYS * 86400
2144
- ).length;
2145
- const ownershipDivisor = ownershipReadyFiles.length || 0;
2122
+ var moduleKnowledgeItems = (files) => {
2146
2123
  const moduleKnowledgeMap = /* @__PURE__ */ new Map();
2147
2124
  for (const file of files) {
2148
2125
  const module = toPosixDirname(file.filePath);
@@ -2163,7 +2140,7 @@ var changeOwnershipSummary = (snapshot) => {
2163
2140
  current.weight += Math.max(1, file.commitCount);
2164
2141
  moduleKnowledgeMap.set(module, current);
2165
2142
  }
2166
- const moduleKnowledge = [...moduleKnowledgeMap.values()].map((entry) => {
2143
+ return [...moduleKnowledgeMap.values()].map((entry) => {
2167
2144
  const topAuthorShareByCommits = entry.weight <= 0 ? 0 : round43(entry.weightedTopAuthorShare / entry.weight);
2168
2145
  const activeAuthors = entry.authors.size;
2169
2146
  const ownershipLabel = activeAuthors <= 1 || topAuthorShareByCommits >= 0.85 ? "siloed" : activeAuthors <= 2 || topAuthorShareByCommits >= 0.65 ? "sparse" : "distributed";
@@ -2177,7 +2154,163 @@ var changeOwnershipSummary = (snapshot) => {
2177
2154
  };
2178
2155
  }).sort(
2179
2156
  (a, b) => MODULE_KNOWLEDGE_LABEL_PRIORITY[a.ownershipLabel] - MODULE_KNOWLEDGE_LABEL_PRIORITY[b.ownershipLabel] || b.totalCommits - a.totalCommits || a.module.localeCompare(b.module)
2157
+ );
2158
+ };
2159
+ var ownershipPosture = (fileOwnership, moduleKnowledge, metrics) => {
2160
+ const authorTouchCounts = /* @__PURE__ */ new Map();
2161
+ for (const file of fileOwnership) {
2162
+ for (const author of file.authorDistributionByCommits) {
2163
+ authorTouchCounts.set(
2164
+ author.authorId,
2165
+ (authorTouchCounts.get(author.authorId) ?? 0) + author.commits
2166
+ );
2167
+ }
2168
+ }
2169
+ const totalTouches = [...authorTouchCounts.values()].reduce((sum, value) => sum + value, 0);
2170
+ const largestContributorSharePercent = totalTouches <= 0 ? null : round43(Math.max(...authorTouchCounts.values()) / totalTouches * 100);
2171
+ const activeContributors = authorTouchCounts.size;
2172
+ const dominatedModules = moduleKnowledge.filter(
2173
+ (module) => module.ownershipLabel === "siloed" || module.topAuthorShareByCommits >= 0.8
2174
+ ).length;
2175
+ const singleOwnerModulesPercent = moduleKnowledge.length === 0 ? null : round43(dominatedModules / moduleKnowledge.length * 100);
2176
+ const concentratedOrSingle = (metrics.concentratedOwnershipPercent ?? 0) + (metrics.singleMaintainerPercent ?? 0);
2177
+ const legacyPercent = metrics.legacyNoActiveOwnerPercent ?? 0;
2178
+ const singleMaintainerPercent = metrics.singleMaintainerPercent ?? 0;
2179
+ let status = "balanced";
2180
+ if (legacyPercent >= 25) {
2181
+ status = "legacyHeavy";
2182
+ } else if (singleMaintainerPercent >= 35 || (singleOwnerModulesPercent ?? 0) >= 35 || (largestContributorSharePercent ?? 0) >= 55) {
2183
+ status = "siloed";
2184
+ } else if (concentratedOrSingle >= 45 || (largestContributorSharePercent ?? 0) >= 30) {
2185
+ status = "concentrated";
2186
+ }
2187
+ const titleByStatus = {
2188
+ balanced: "Balanced Ownership",
2189
+ concentrated: "Concentrated Ownership",
2190
+ siloed: "Siloed Ownership",
2191
+ legacyHeavy: "Legacy-Heavy Ownership"
2192
+ };
2193
+ const summaryByStatus = {
2194
+ balanced: `Knowledge is broadly distributed across the repository. ${metrics.sharedOwnershipPercent ?? 0}% of ownership-ready files are shared, with limited module concentration.`,
2195
+ concentrated: `The repository still depends on a narrow set of contributors in key paths. ${round43(concentratedOrSingle)}% of ownership-ready files are concentrated or single-maintainer.`,
2196
+ siloed: `Knowledge silos are material. Single-maintainer files or module dominance are high enough that handoff risk is no longer isolated.`,
2197
+ legacyHeavy: `A meaningful slice of owned files has gone cold. Legacy areas without an active owner are large enough to distort the repo's operating posture.`
2198
+ };
2199
+ return {
2200
+ status,
2201
+ title: titleByStatus[status],
2202
+ summary: summaryByStatus[status],
2203
+ activeContributors,
2204
+ largestContributorSharePercent,
2205
+ singleOwnerModulesPercent
2206
+ };
2207
+ };
2208
+ var ownershipContributors = (fileOwnership) => {
2209
+ const commitTouchesByAuthor = /* @__PURE__ */ new Map();
2210
+ let totalCommitTouches = 0;
2211
+ let totalChurn = 0;
2212
+ const contributorMap = /* @__PURE__ */ new Map();
2213
+ for (const file of fileOwnership) {
2214
+ for (const author of file.authorDistributionByCommits) {
2215
+ commitTouchesByAuthor.set(
2216
+ author.authorId,
2217
+ (commitTouchesByAuthor.get(author.authorId) ?? 0) + author.commits
2218
+ );
2219
+ totalCommitTouches += author.commits;
2220
+ }
2221
+ for (const author of file.authorDistributionByChurn) {
2222
+ totalChurn += author.churnTotal;
2223
+ }
2224
+ const dominantAuthor = file.authorDistributionByCommits[0];
2225
+ if (dominantAuthor === void 0) {
2226
+ continue;
2227
+ }
2228
+ const current = contributorMap.get(dominantAuthor.authorId) ?? {
2229
+ authorId: dominantAuthor.authorId,
2230
+ singleMaintainerFiles: 0,
2231
+ concentratedFiles: 0,
2232
+ ownedFiles: 0,
2233
+ totalCommitTouches: 0,
2234
+ ownedChurnTotal: 0
2235
+ };
2236
+ current.ownedFiles += 1;
2237
+ current.totalCommitTouches += dominantAuthor.commits;
2238
+ const dominantChurnShare = file.authorDistributionByChurn.find(
2239
+ (entry) => entry.authorId === dominantAuthor.authorId
2240
+ );
2241
+ current.ownedChurnTotal += dominantChurnShare?.churnTotal ?? 0;
2242
+ if (file.ownershipLabel === "singleMaintainer") {
2243
+ current.singleMaintainerFiles += 1;
2244
+ } else if (file.ownershipLabel === "concentrated") {
2245
+ current.concentratedFiles += 1;
2246
+ }
2247
+ contributorMap.set(dominantAuthor.authorId, current);
2248
+ }
2249
+ return [...contributorMap.values()].map((entry) => ({
2250
+ authorId: entry.authorId,
2251
+ singleMaintainerFiles: entry.singleMaintainerFiles,
2252
+ concentratedFiles: entry.concentratedFiles,
2253
+ ownedFiles: entry.ownedFiles,
2254
+ totalCommitTouches: entry.totalCommitTouches,
2255
+ totalCommitShare: totalCommitTouches === 0 ? 0 : round43(entry.totalCommitTouches / totalCommitTouches * 100),
2256
+ ownedChurnShare: totalChurn === 0 ? 0 : round43(entry.ownedChurnTotal / totalChurn * 100)
2257
+ })).sort(
2258
+ (a, b) => b.singleMaintainerFiles - a.singleMaintainerFiles || b.concentratedFiles - a.concentratedFiles || b.ownedFiles - a.ownedFiles || b.totalCommitShare - a.totalCommitShare || a.authorId.localeCompare(b.authorId)
2180
2259
  ).slice(0, 8);
2260
+ };
2261
+ var ownershipFragilityScore = (module) => {
2262
+ const severityBase = module.ownershipLabel === "siloed" ? 0.85 : module.ownershipLabel === "sparse" ? 0.55 : 0.2;
2263
+ const severity = clamp01(severityBase + Math.max(0, module.topAuthorShareByCommits - 0.6));
2264
+ const activityWeight = clamp01(module.recentCommits / 6) * 0.65 + clamp01(module.totalCommits / 20) * 0.35;
2265
+ return round43(severity * activityWeight);
2266
+ };
2267
+ var changeOwnershipSummary = (snapshot) => {
2268
+ if (!snapshot.analysis.evolution.available) {
2269
+ return {
2270
+ available: false,
2271
+ reason: snapshot.analysis.evolution.reason
2272
+ };
2273
+ }
2274
+ const evolution = snapshot.analysis.evolution;
2275
+ const files = evolution.files;
2276
+ const ownershipReadyFiles = files.filter(
2277
+ (file) => file.topAuthorShareByCommits !== null && file.authorDistributionByCommits.length > 0
2278
+ );
2279
+ const sharedOwnershipCount = ownershipReadyFiles.filter(
2280
+ (file) => file.authorDistributionByCommits.length >= 2 && file.topAuthorShareByCommits <= 0.6
2281
+ ).length;
2282
+ const concentratedOwnershipCount = ownershipReadyFiles.filter(
2283
+ (file) => file.authorDistributionByCommits.length >= 2 && file.topAuthorShareByCommits > 0.6
2284
+ ).length;
2285
+ const singleMaintainerCount = ownershipReadyFiles.filter(
2286
+ (file) => file.authorDistributionByCommits.length <= 1
2287
+ ).length;
2288
+ const headCommitTimestamp = evolution.metrics.headCommitTimestamp;
2289
+ const legacyNoActiveOwnerCount = ownershipReadyFiles.filter(
2290
+ (file) => file.commitCount > 0 && file.lastCommitTimestamp !== null && headCommitTimestamp !== null && headCommitTimestamp - file.lastCommitTimestamp >= LEGACY_NO_ACTIVE_OWNER_DAYS * 86400
2291
+ ).length;
2292
+ const ownershipDivisor = ownershipReadyFiles.length || 0;
2293
+ const metrics = {
2294
+ totalCommits: evolution.metrics.totalCommits,
2295
+ totalFiles: evolution.metrics.totalFiles,
2296
+ recentWindowDays: evolution.metrics.recentWindowDays,
2297
+ meanBusFactorByCommits: average(
2298
+ files.map((file) => file.busFactorByCommits).filter((value) => value !== null)
2299
+ ),
2300
+ averageRecentVolatility: average(files.map((file) => toPercent(file.recentVolatility))),
2301
+ sharedOwnershipPercent: ownershipDivisor === 0 ? null : round43(sharedOwnershipCount / ownershipDivisor * 100),
2302
+ concentratedOwnershipPercent: ownershipDivisor === 0 ? null : round43(concentratedOwnershipCount / ownershipDivisor * 100),
2303
+ singleMaintainerPercent: ownershipDivisor === 0 ? null : round43(singleMaintainerCount / ownershipDivisor * 100),
2304
+ legacyNoActiveOwnerPercent: ownershipDivisor === 0 ? null : round43(legacyNoActiveOwnerCount / ownershipDivisor * 100)
2305
+ };
2306
+ const fileOwnership = fileOwnershipItems(files);
2307
+ const allModuleKnowledge = moduleKnowledgeItems(files);
2308
+ const posture = ownershipPosture(fileOwnership, allModuleKnowledge, metrics);
2309
+ const contributorOwnership = ownershipContributors(fileOwnership);
2310
+ const moduleKnowledge = allModuleKnowledge.slice(0, 8);
2311
+ const fragileAreas = allModuleKnowledge.slice().filter((module) => module.totalCommits >= MIN_FRAGILE_AREA_TOTAL_COMMITS).sort(
2312
+ (a, b) => ownershipFragilityScore(b) - ownershipFragilityScore(a) || b.topAuthorShareByCommits - a.topAuthorShareByCommits || b.recentCommits - a.recentCommits || b.totalCommits - a.totalCommits || a.module.localeCompare(b.module)
2313
+ ).slice(0, 5);
2181
2314
  const coChangePairs = [...evolution.coupling.pairs].sort(
2182
2315
  (a, b) => b.couplingScore - a.couplingScore || b.coChangeCommits - a.coChangeCommits || a.fileA.localeCompare(b.fileA) || a.fileB.localeCompare(b.fileB)
2183
2316
  ).slice(0, 5).map((pair) => ({
@@ -2188,23 +2321,14 @@ var changeOwnershipSummary = (snapshot) => {
2188
2321
  }));
2189
2322
  return {
2190
2323
  available: true,
2191
- metrics: {
2192
- totalCommits: evolution.metrics.totalCommits,
2193
- totalFiles: evolution.metrics.totalFiles,
2194
- recentWindowDays: evolution.metrics.recentWindowDays,
2195
- meanBusFactorByCommits: average(
2196
- files.map((file) => file.busFactorByCommits).filter((value) => value !== null)
2197
- ),
2198
- averageRecentVolatility: average(files.map((file) => toPercent(file.recentVolatility))),
2199
- sharedOwnershipPercent: ownershipDivisor === 0 ? null : round43(sharedOwnershipCount / ownershipDivisor * 100),
2200
- concentratedOwnershipPercent: ownershipDivisor === 0 ? null : round43(concentratedOwnershipCount / ownershipDivisor * 100),
2201
- singleMaintainerPercent: ownershipDivisor === 0 ? null : round43(singleMaintainerCount / ownershipDivisor * 100),
2202
- legacyNoActiveOwnerPercent: ownershipDivisor === 0 ? null : round43(legacyNoActiveOwnerCount / ownershipDivisor * 100)
2203
- },
2324
+ metrics,
2325
+ posture,
2204
2326
  recentActivity: evolution.recentActivity ?? [],
2205
2327
  coChangePairs,
2206
2328
  moduleKnowledge,
2207
- fileOwnership: fileOwnershipItems(files)
2329
+ fragileAreas,
2330
+ contributorOwnership,
2331
+ fileOwnership
2208
2332
  };
2209
2333
  };
2210
2334
  var riskyDependencies = (snapshot) => {
@@ -2390,6 +2514,21 @@ var renderTextReport = (report) => {
2390
2514
  lines.push(" - none");
2391
2515
  }
2392
2516
  lines.push("");
2517
+ lines.push("Ownership Posture");
2518
+ if (!report.changeOwnership.available) {
2519
+ lines.push(` unavailable: ${report.changeOwnership.reason}`);
2520
+ } else {
2521
+ lines.push(` status: ${report.changeOwnership.posture.title}`);
2522
+ lines.push(` summary: ${report.changeOwnership.posture.summary}`);
2523
+ lines.push(` activeContributors: ${report.changeOwnership.posture.activeContributors}`);
2524
+ lines.push(
2525
+ ` largestContributorSharePercent: ${report.changeOwnership.posture.largestContributorSharePercent ?? "n/a"}`
2526
+ );
2527
+ lines.push(
2528
+ ` singleOwnerModulesPercent: ${report.changeOwnership.posture.singleOwnerModulesPercent ?? "n/a"}`
2529
+ );
2530
+ }
2531
+ lines.push("");
2393
2532
  lines.push("Top Hotspots");
2394
2533
  for (const hotspot of report.hotspots) {
2395
2534
  lines.push(` - ${hotspot.target} | score=${hotspot.score}`);
@@ -2485,6 +2624,21 @@ var renderMarkdownReport = (report) => {
2485
2624
  }
2486
2625
  }
2487
2626
  lines.push("");
2627
+ lines.push("## Ownership Posture");
2628
+ if (!report.changeOwnership.available) {
2629
+ lines.push(`- unavailable: \`${report.changeOwnership.reason}\``);
2630
+ } else {
2631
+ lines.push(`- status: \`${report.changeOwnership.posture.title}\``);
2632
+ lines.push(`- summary: ${report.changeOwnership.posture.summary}`);
2633
+ lines.push(`- active contributors: \`${report.changeOwnership.posture.activeContributors}\``);
2634
+ lines.push(
2635
+ `- largest contributor share percent: \`${report.changeOwnership.posture.largestContributorSharePercent ?? "n/a"}\``
2636
+ );
2637
+ lines.push(
2638
+ `- single-owner modules percent: \`${report.changeOwnership.posture.singleOwnerModulesPercent ?? "n/a"}\``
2639
+ );
2640
+ }
2641
+ lines.push("");
2488
2642
  lines.push("## Top Hotspots");
2489
2643
  for (const hotspot of report.hotspots) {
2490
2644
  lines.push(`- **${hotspot.target}** (score: \`${hotspot.score}\`)`);
@@ -5417,7 +5571,7 @@ var analyzeRepositoryEvolutionFromGit = (input, onProgress) => {
5417
5571
  };
5418
5572
 
5419
5573
  // ../health-engine/dist/index.js
5420
- var clamp01 = (value) => {
5574
+ var clamp012 = (value) => {
5421
5575
  if (!Number.isFinite(value)) {
5422
5576
  return 0;
5423
5577
  }
@@ -5453,7 +5607,7 @@ var concentration = (rawValues) => {
5453
5607
  }, 0);
5454
5608
  const minHhi = 1 / count;
5455
5609
  const normalized = (hhi - minHhi) / (1 - minHhi);
5456
- return clamp01(normalized);
5610
+ return clamp012(normalized);
5457
5611
  };
5458
5612
  var DIMENSION_WEIGHTS = {
5459
5613
  modularity: 0.35,
@@ -5462,24 +5616,24 @@ var DIMENSION_WEIGHTS = {
5462
5616
  ownershipDistribution: 0.15
5463
5617
  };
5464
5618
  var HEALTH_TRACE_VERSION = "1";
5465
- var toPercentage = (normalizedHealth) => round45(clamp01(normalizedHealth) * 100);
5619
+ var toPercentage = (normalizedHealth) => round45(clamp012(normalizedHealth) * 100);
5466
5620
  var dampenForSmallSamples = (penalty, sampleSize, warmupSize, minimumWeight = 0.35) => {
5467
- const reliability = clamp01(sampleSize / Math.max(1, warmupSize));
5621
+ const reliability = clamp012(sampleSize / Math.max(1, warmupSize));
5468
5622
  const dampeningWeight = minimumWeight + (1 - minimumWeight) * reliability;
5469
- return clamp01(penalty) * dampeningWeight;
5623
+ return clamp012(penalty) * dampeningWeight;
5470
5624
  };
5471
5625
  var topPercentShare = (values, fraction) => {
5472
5626
  const positive = values.filter((value) => value > 0).sort((a, b) => b - a);
5473
5627
  if (positive.length === 0) {
5474
5628
  return 0;
5475
5629
  }
5476
- const topCount = Math.max(1, Math.ceil(positive.length * clamp01(fraction)));
5630
+ const topCount = Math.max(1, Math.ceil(positive.length * clamp012(fraction)));
5477
5631
  const total = positive.reduce((sum, value) => sum + value, 0);
5478
5632
  const topTotal = positive.slice(0, topCount).reduce((sum, value) => sum + value, 0);
5479
5633
  if (total <= 0) {
5480
5634
  return 0;
5481
5635
  }
5482
- return clamp01(topTotal / total);
5636
+ return clamp012(topTotal / total);
5483
5637
  };
5484
5638
  var normalizedEntropy = (weights) => {
5485
5639
  const positive = weights.filter((value) => value > 0);
@@ -5494,7 +5648,7 @@ var normalizedEntropy = (weights) => {
5494
5648
  const p = value / total;
5495
5649
  return sum - p * Math.log(p);
5496
5650
  }, 0);
5497
- return clamp01(entropy / Math.log(positive.length));
5651
+ return clamp012(entropy / Math.log(positive.length));
5498
5652
  };
5499
5653
  var toFactorTrace = (spec) => ({
5500
5654
  factorId: spec.factorId,
@@ -5507,7 +5661,7 @@ var toFactorTrace = (spec) => ({
5507
5661
  });
5508
5662
  var createDimensionTrace = (dimension, health, factors) => ({
5509
5663
  dimension,
5510
- normalizedScore: round45(clamp01(health)),
5664
+ normalizedScore: round45(clamp012(health)),
5511
5665
  score: toPercentage(health),
5512
5666
  factors: factors.map((factor) => toFactorTrace(factor))
5513
5667
  });
@@ -5538,9 +5692,9 @@ var pushIssue = (issues, issue) => {
5538
5692
  severity: issue.severity ?? "warn"
5539
5693
  });
5540
5694
  };
5541
- var weightedPenalty = (factors) => clamp01(factors.reduce((sum, factor) => sum + factor.penalty * factor.weight, 0));
5695
+ var weightedPenalty = (factors) => clamp012(factors.reduce((sum, factor) => sum + factor.penalty * factor.weight, 0));
5542
5696
  var computeRepositoryHealthSummary = (input) => {
5543
- const ownershipPenaltyMultiplier = clamp01(input.config?.ownershipPenaltyMultiplier ?? 1);
5697
+ const ownershipPenaltyMultiplier = clamp012(input.config?.ownershipPenaltyMultiplier ?? 1);
5544
5698
  const issues = [];
5545
5699
  const sourceFileSet = new Set(input.structural.files.map((file) => file.relativePath));
5546
5700
  const sourceFileCount = Math.max(1, input.structural.files.length);
@@ -5555,10 +5709,10 @@ var computeRepositoryHealthSummary = (input) => {
5555
5709
  const edgesInsideCycles = structuralEdges.filter(
5556
5710
  (edge) => cycleSets.some((cycleSet) => cycleSet.has(edge.from) && cycleSet.has(edge.to))
5557
5711
  ).length;
5558
- const cycleEdgeRatio = structuralEdges.length === 0 ? 0 : clamp01(edgesInsideCycles / structuralEdges.length);
5559
- const cycleNodeRatio = clamp01(cycleNodeSet.size / sourceFileCount);
5560
- const cycleDensityPenalty = clamp01(
5561
- clamp01(cycleEdgeRatio / 0.2) * 0.75 + clamp01(cycleNodeRatio / 0.35) * 0.25
5712
+ const cycleEdgeRatio = structuralEdges.length === 0 ? 0 : clamp012(edgesInsideCycles / structuralEdges.length);
5713
+ const cycleNodeRatio = clamp012(cycleNodeSet.size / sourceFileCount);
5714
+ const cycleDensityPenalty = clamp012(
5715
+ clamp012(cycleEdgeRatio / 0.2) * 0.75 + clamp012(cycleNodeRatio / 0.35) * 0.25
5562
5716
  );
5563
5717
  const fanInConcentration = concentration(input.structural.files.map((file) => file.fanIn));
5564
5718
  const fanOutConcentration = concentration(input.structural.files.map((file) => file.fanOut));
@@ -5582,7 +5736,7 @@ var computeRepositoryHealthSummary = (input) => {
5582
5736
  [...evolutionSourceFiles].sort((a, b) => b.churnTotal - a.churnTotal || a.filePath.localeCompare(b.filePath)).slice(0, topChangeCount).map((item) => item.filePath)
5583
5737
  );
5584
5738
  const overlapCount = [...topStructural].filter((filePath) => topChange.has(filePath)).length;
5585
- structuralHotspotOverlap = topStructural.size === 0 || topChange.size === 0 ? 0 : clamp01(overlapCount / Math.min(topStructural.size, topChange.size));
5739
+ structuralHotspotOverlap = topStructural.size === 0 || topChange.size === 0 ? 0 : clamp012(overlapCount / Math.min(topStructural.size, topChange.size));
5586
5740
  }
5587
5741
  const modularityFactors = [
5588
5742
  {
@@ -5718,22 +5872,22 @@ var computeRepositoryHealthSummary = (input) => {
5718
5872
  );
5719
5873
  const maxPairs = evolutionFileCount * (evolutionFileCount - 1) / 2;
5720
5874
  const densePairs = sourcePairs.filter((pair) => pair.couplingScore >= 0.55);
5721
- denseCoChangePairRatio = maxPairs <= 0 ? 0 : clamp01(densePairs.length / maxPairs);
5875
+ denseCoChangePairRatio = maxPairs <= 0 ? 0 : clamp012(densePairs.length / maxPairs);
5722
5876
  const couplingScoreConcentration = concentration(sourcePairs.map((pair) => pair.couplingScore));
5723
5877
  churnConcentrationPenalty = dampenForSmallSamples(
5724
- clamp01((top10PercentFilesChurnShare - 0.35) / 0.55),
5878
+ clamp012((top10PercentFilesChurnShare - 0.35) / 0.55),
5725
5879
  evolutionFileCount,
5726
5880
  12,
5727
5881
  0.3
5728
5882
  );
5729
5883
  volatilityConcentrationPenalty = dampenForSmallSamples(
5730
- clamp01((top10PercentFilesVolatilityShare - 0.35) / 0.55),
5884
+ clamp012((top10PercentFilesVolatilityShare - 0.35) / 0.55),
5731
5885
  evolutionFileCount,
5732
5886
  12,
5733
5887
  0.3
5734
5888
  );
5735
5889
  const coChangeRaw = average2([
5736
- clamp01(denseCoChangePairRatio / 0.2),
5890
+ clamp012(denseCoChangePairRatio / 0.2),
5737
5891
  couplingScoreConcentration
5738
5892
  ]);
5739
5893
  coChangeClusterPenalty = dampenForSmallSamples(coChangeRaw, sourcePairs.length, 20, 0.35);
@@ -5839,7 +5993,7 @@ var computeRepositoryHealthSummary = (input) => {
5839
5993
  const testRatio = sourceFiles <= 0 ? 1 : testFiles / sourceFiles;
5840
5994
  const testingDirectoryPresent = hasTestDirectory(paths);
5841
5995
  const testPresencePenalty = sourceFiles <= 0 ? 0 : testFiles === 0 ? 1 : 0;
5842
- const testRatioPenalty = sourceFiles <= 0 ? 0 : 1 - clamp01(testRatio / 0.25);
5996
+ const testRatioPenalty = sourceFiles <= 0 ? 0 : 1 - clamp012(testRatio / 0.25);
5843
5997
  const testingDirectoryPenalty = sourceFiles <= 0 ? 0 : testingDirectoryPresent ? 0 : 0.35;
5844
5998
  const testHealthFactors = [
5845
5999
  {
@@ -5933,7 +6087,7 @@ var computeRepositoryHealthSummary = (input) => {
5933
6087
  continue;
5934
6088
  }
5935
6089
  trackedFiles += 1;
5936
- const dominantShare = clamp01(file.authorDistributionByCommits[0]?.share ?? 0);
6090
+ const dominantShare = clamp012(file.authorDistributionByCommits[0]?.share ?? 0);
5937
6091
  if (file.authorDistributionByCommits.length === 1 || dominantShare >= 0.9) {
5938
6092
  singleContributorFiles += 1;
5939
6093
  }
@@ -5957,8 +6111,8 @@ var computeRepositoryHealthSummary = (input) => {
5957
6111
  }
5958
6112
  const totalAuthorCommits = [...authorTotals.values()].reduce((sum, value) => sum + value, 0);
5959
6113
  const highestAuthorCommits = [...authorTotals.values()].sort((a, b) => b - a)[0] ?? 0;
5960
- const topAuthorCommitShare = totalAuthorCommits <= 0 ? 0 : clamp01(highestAuthorCommits / totalAuthorCommits);
5961
- const filesWithSingleContributorRatio = trackedFiles === 0 ? 0 : clamp01(singleContributorFiles / trackedFiles);
6114
+ const topAuthorCommitShare = totalAuthorCommits <= 0 ? 0 : clamp012(highestAuthorCommits / totalAuthorCommits);
6115
+ const filesWithSingleContributorRatio = trackedFiles === 0 ? 0 : clamp012(singleContributorFiles / trackedFiles);
5962
6116
  const authorEntropy = normalizedEntropy([...authorTotals.values()]);
5963
6117
  let dominatedModules = 0;
5964
6118
  let trackedModules = 0;
@@ -5977,17 +6131,17 @@ var computeRepositoryHealthSummary = (input) => {
5977
6131
  dominatedModules += 1;
5978
6132
  }
5979
6133
  }
5980
- const modulesDominatedBySingleContributorRatio = trackedModules === 0 ? 0 : clamp01(dominatedModules / trackedModules);
6134
+ const modulesDominatedBySingleContributorRatio = trackedModules === 0 ? 0 : clamp012(dominatedModules / trackedModules);
5981
6135
  const ownershipSampleSize = trackedFiles;
5982
6136
  const ownershipCommitVolume = totalAuthorCommits;
5983
6137
  const ownershipReliability = average2([
5984
- clamp01(ownershipSampleSize / 12),
5985
- clamp01(ownershipCommitVolume / 180)
6138
+ clamp012(ownershipSampleSize / 12),
6139
+ clamp012(ownershipCommitVolume / 180)
5986
6140
  ]);
5987
- const topAuthorPenalty = clamp01((topAuthorCommitShare - 0.55) / 0.4);
5988
- const singleContributorPenalty = clamp01((filesWithSingleContributorRatio - 0.35) / 0.6);
5989
- const entropyPenalty = clamp01((0.75 - authorEntropy) / 0.75);
5990
- const moduleDominancePenalty = clamp01((modulesDominatedBySingleContributorRatio - 0.4) / 0.6);
6141
+ const topAuthorPenalty = clamp012((topAuthorCommitShare - 0.55) / 0.4);
6142
+ const singleContributorPenalty = clamp012((filesWithSingleContributorRatio - 0.35) / 0.6);
6143
+ const entropyPenalty = clamp012((0.75 - authorEntropy) / 0.75);
6144
+ const moduleDominancePenalty = clamp012((modulesDominatedBySingleContributorRatio - 0.4) / 0.6);
5991
6145
  const ownershipBasePenalty = weightedPenalty([
5992
6146
  {
5993
6147
  factorId: "health.ownership.top_author_commit_share",
@@ -6045,7 +6199,7 @@ var computeRepositoryHealthSummary = (input) => {
6045
6199
  evidence: [{ kind: "repository_metric", metric: "ownership.moduleDominance" }]
6046
6200
  }
6047
6201
  ]);
6048
- const ownershipDistributionPenalty2 = clamp01(
6202
+ const ownershipDistributionPenalty2 = clamp012(
6049
6203
  ownershipBasePenalty * (0.3 + 0.7 * ownershipReliability) * ownershipPenaltyMultiplier
6050
6204
  );
6051
6205
  const ownershipDistributionFactors2 = [
@@ -6155,11 +6309,11 @@ var computeRepositoryHealthSummary = (input) => {
6155
6309
  impact: round45(ownershipDistributionPenalty2 * 0.25)
6156
6310
  });
6157
6311
  }
6158
- const modularityHealth2 = clamp01(1 - modularityPenalty);
6159
- const changeHygieneHealth2 = clamp01(1 - changeHygienePenalty);
6160
- const testHealthScore2 = clamp01(1 - testHealthPenalty);
6161
- const ownershipDistributionHealth2 = clamp01(1 - ownershipDistributionPenalty2);
6162
- const normalizedScore2 = clamp01(
6312
+ const modularityHealth2 = clamp012(1 - modularityPenalty);
6313
+ const changeHygieneHealth2 = clamp012(1 - changeHygienePenalty);
6314
+ const testHealthScore2 = clamp012(1 - testHealthPenalty);
6315
+ const ownershipDistributionHealth2 = clamp012(1 - ownershipDistributionPenalty2);
6316
+ const normalizedScore2 = clamp012(
6163
6317
  modularityHealth2 * DIMENSION_WEIGHTS.modularity + changeHygieneHealth2 * DIMENSION_WEIGHTS.changeHygiene + testHealthScore2 * DIMENSION_WEIGHTS.testHealth + ownershipDistributionHealth2 * DIMENSION_WEIGHTS.ownershipDistribution
6164
6318
  );
6165
6319
  const topIssues2 = [...issues].sort(
@@ -6190,7 +6344,7 @@ var computeRepositoryHealthSummary = (input) => {
6190
6344
  }
6191
6345
  };
6192
6346
  }
6193
- const ownershipDistributionPenalty = clamp01(0.12 * ownershipPenaltyMultiplier);
6347
+ const ownershipDistributionPenalty = clamp012(0.12 * ownershipPenaltyMultiplier);
6194
6348
  const ownershipDistributionFactors = [
6195
6349
  {
6196
6350
  factorId: "health.ownership.missing_git_history",
@@ -6205,11 +6359,11 @@ var computeRepositoryHealthSummary = (input) => {
6205
6359
  evidence: [{ kind: "repository_metric", metric: "evolution.available" }]
6206
6360
  }
6207
6361
  ];
6208
- const modularityHealth = clamp01(1 - modularityPenalty);
6209
- const changeHygieneHealth = clamp01(1 - changeHygienePenalty);
6210
- const testHealthScore = clamp01(1 - testHealthPenalty);
6211
- const ownershipDistributionHealth = clamp01(1 - ownershipDistributionPenalty);
6212
- const normalizedScore = clamp01(
6362
+ const modularityHealth = clamp012(1 - modularityPenalty);
6363
+ const changeHygieneHealth = clamp012(1 - changeHygienePenalty);
6364
+ const testHealthScore = clamp012(1 - testHealthPenalty);
6365
+ const ownershipDistributionHealth = clamp012(1 - ownershipDistributionPenalty);
6366
+ const normalizedScore = clamp012(
6213
6367
  modularityHealth * DIMENSION_WEIGHTS.modularity + changeHygieneHealth * DIMENSION_WEIGHTS.changeHygiene + testHealthScore * DIMENSION_WEIGHTS.testHealth + ownershipDistributionHealth * DIMENSION_WEIGHTS.ownershipDistribution
6214
6368
  );
6215
6369
  const topIssues = [...issues].sort(