@getcodesentinel/codesentinel 1.32.0 → 1.33.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 CHANGED
@@ -13,6 +13,8 @@ import { join as join2 } from "path";
13
13
  import { createHash } from "crypto";
14
14
  import { mkdir, readdir, readFile, rename, stat, unlink, writeFile } from "fs/promises";
15
15
  import { join as join3 } from "path";
16
+ import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync2, statSync } from "fs";
17
+ import { basename, join as join5, relative, resolve } from "path";
16
18
  var round4 = (value) => Number(value.toFixed(4));
17
19
  var normalizeNodes = (nodes) => {
18
20
  const byName = /* @__PURE__ */ new Map();
@@ -115,7 +117,81 @@ var collectTransitiveDependencies = (rootName, nodeByName) => {
115
117
  }
116
118
  return [...seen].sort((a, b) => a.localeCompare(b));
117
119
  };
118
- var buildExternalAnalysisSummary = (targetPath, extraction, metadataByKey, config) => {
120
+ var hasHighRiskSignals = (dependency, config) => dependency.ownRiskSignals.includes("abandoned") || dependency.ownRiskSignals.filter(
121
+ (signal) => signal === "high_centrality" || signal === "deep_chain" || signal === "high_fanout"
122
+ ).length >= 2 || dependency.ownRiskSignals.includes("single_maintainer") && ((dependency.daysSinceLastRelease ?? 0) >= config.abandonedDaysThreshold / 2 || (dependency.repositoryActivity30d ?? 1) <= 0);
123
+ var buildWorkspaceExposureSummaries = (workspaceManifests, allByName, nodeByName, config) => {
124
+ if (workspaceManifests.length === 0) {
125
+ return [];
126
+ }
127
+ const workspaceNames = new Set(workspaceManifests.map((workspace) => workspace.name));
128
+ const externalDependencyNamesByWorkspace = /* @__PURE__ */ new Map();
129
+ const workspaceCountByDependency = /* @__PURE__ */ new Map();
130
+ for (const workspace of workspaceManifests) {
131
+ const dependencyNames = [
132
+ ...new Set(
133
+ workspace.directDependencies.map((dependency) => dependency.name).filter((dependencyName) => !workspaceNames.has(dependencyName))
134
+ )
135
+ ].sort((a, b) => a.localeCompare(b));
136
+ externalDependencyNamesByWorkspace.set(workspace.path, dependencyNames);
137
+ for (const dependencyName of dependencyNames) {
138
+ workspaceCountByDependency.set(
139
+ dependencyName,
140
+ (workspaceCountByDependency.get(dependencyName) ?? 0) + 1
141
+ );
142
+ }
143
+ }
144
+ return [...workspaceManifests].map((workspace) => {
145
+ const dependencyNames = externalDependencyNamesByWorkspace.get(workspace.path) ?? [];
146
+ const directSpecByName = new Map(
147
+ workspace.directDependencies.map((dependency) => [dependency.name, dependency])
148
+ );
149
+ const resolvedDependencies = dependencyNames.map((dependencyName) => allByName.get(dependencyName)).filter((dependency) => dependency !== void 0);
150
+ const unresolvedDependencies = dependencyNames.filter(
151
+ (dependencyName) => !allByName.has(dependencyName)
152
+ );
153
+ const highRiskDependencies = resolvedDependencies.filter(
154
+ (dependency) => (directSpecByName.get(dependency.name)?.scope ?? dependency.dependencyScope) === "prod" && hasHighRiskSignals(dependency, config)
155
+ ).map((dependency) => dependency.name).sort((a, b) => a.localeCompare(b));
156
+ const highRiskDevelopmentDependencies = resolvedDependencies.filter(
157
+ (dependency) => (directSpecByName.get(dependency.name)?.scope ?? dependency.dependencyScope) === "dev" && hasHighRiskSignals(dependency, config)
158
+ ).map((dependency) => dependency.name).sort((a, b) => a.localeCompare(b));
159
+ const transitiveExposureDependencies = resolvedDependencies.filter((dependency) => {
160
+ const transitiveDependencies = collectTransitiveDependencies(dependency.name, nodeByName);
161
+ return transitiveDependencies.some((transitiveName) => {
162
+ const transitive = allByName.get(transitiveName);
163
+ return transitive?.riskSignals.some(canPropagateSignal) ?? false;
164
+ });
165
+ }).map((dependency) => dependency.name).sort((a, b) => a.localeCompare(b));
166
+ const singleMaintainerDependencies = resolvedDependencies.filter((dependency) => dependency.ownRiskSignals.includes("single_maintainer")).map((dependency) => dependency.name).sort((a, b) => a.localeCompare(b));
167
+ const abandonedDependencies = resolvedDependencies.filter((dependency) => dependency.ownRiskSignals.includes("abandoned")).map((dependency) => dependency.name).sort((a, b) => a.localeCompare(b));
168
+ return {
169
+ name: workspace.name,
170
+ path: workspace.path,
171
+ kind: workspace.kind,
172
+ directDependencies: dependencyNames.length,
173
+ directProductionDependencies: dependencyNames.filter(
174
+ (dependencyName) => directSpecByName.get(dependencyName)?.scope === "prod"
175
+ ).length,
176
+ directDevelopmentDependencies: dependencyNames.filter(
177
+ (dependencyName) => directSpecByName.get(dependencyName)?.scope === "dev"
178
+ ).length,
179
+ unresolvedDependencies,
180
+ dependencyNames,
181
+ sharedDependencies: dependencyNames.filter(
182
+ (dependencyName) => (workspaceCountByDependency.get(dependencyName) ?? 0) > 1
183
+ ),
184
+ highRiskDependencies,
185
+ highRiskDevelopmentDependencies,
186
+ transitiveExposureDependencies,
187
+ singleMaintainerDependencies,
188
+ abandonedDependencies
189
+ };
190
+ }).sort(
191
+ (a, b) => b.highRiskDependencies.length - a.highRiskDependencies.length || b.transitiveExposureDependencies.length - a.transitiveExposureDependencies.length || b.directDependencies - a.directDependencies || a.path.localeCompare(b.path)
192
+ );
193
+ };
194
+ var buildExternalAnalysisSummary = (targetPath, extraction, metadataByKey, config, workspaceManifests = []) => {
119
195
  const nodes = normalizeNodes(extraction.nodes);
120
196
  const directNames = new Set(extraction.directDependencies.map((dep) => dep.name));
121
197
  const directSpecByName = new Map(extraction.directDependencies.map((dep) => [dep.name, dep]));
@@ -235,6 +311,13 @@ var buildExternalAnalysisSummary = (targetPath, extraction, metadataByKey, confi
235
311
  ).map((dep) => dep.name);
236
312
  const singleMaintainerDependencies = dependencies.filter((dep) => dep.ownRiskSignals.includes("single_maintainer")).map((dep) => dep.name).sort((a, b) => a.localeCompare(b));
237
313
  const abandonedDependencies = dependencies.filter((dep) => dep.ownRiskSignals.includes("abandoned")).map((dep) => dep.name).sort((a, b) => a.localeCompare(b));
314
+ const workspaces = buildWorkspaceExposureSummaries(
315
+ workspaceManifests,
316
+ allByName,
317
+ nodeByName,
318
+ config
319
+ );
320
+ const workspaceSummary2 = workspaces.length > 0 ? { workspaces } : {};
238
321
  return {
239
322
  targetPath,
240
323
  available: true,
@@ -253,6 +336,7 @@ var buildExternalAnalysisSummary = (targetPath, extraction, metadataByKey, confi
253
336
  metadataCoverage: allDependencies.length === 0 ? 0 : round4(metadataAvailableCount / allDependencies.length)
254
337
  },
255
338
  dependencies,
339
+ ...workspaceSummary2,
256
340
  highRiskDependencies,
257
341
  highRiskDevelopmentDependencies,
258
342
  transitiveExposureDependencies,
@@ -1423,6 +1507,136 @@ var prepareDependencyExtraction = async (repositoryPath) => {
1423
1507
  extraction: parseLockfileExtraction(lockfile.kind, lockfile.raw, directSpecs)
1424
1508
  };
1425
1509
  };
1510
+ var normalizePath = (pathValue) => pathValue.replaceAll("\\", "/");
1511
+ var stripQuotes2 = (value) => value.replace(/^['"]|['"]$/g, "");
1512
+ var readPackageJson = (path) => {
1513
+ try {
1514
+ return JSON.parse(readFileSync2(path, "utf8"));
1515
+ } catch {
1516
+ return null;
1517
+ }
1518
+ };
1519
+ var inferWorkspaceKind = (workspacePath) => {
1520
+ const segments = workspacePath.split("/");
1521
+ const first = segments[0] ?? "";
1522
+ if (first === "apps" || first === "app") {
1523
+ return "app";
1524
+ }
1525
+ if (first === "packages" || first === "package") {
1526
+ return "package";
1527
+ }
1528
+ if (first === "docs" || first === "documentation") {
1529
+ return "docs";
1530
+ }
1531
+ if (first === "examples" || first === "example-apps" || first === "playground") {
1532
+ return "example";
1533
+ }
1534
+ if (first === "tooling" || first === "tools") {
1535
+ return "tooling";
1536
+ }
1537
+ return "unknown";
1538
+ };
1539
+ var readWorkspacePatternsFromPackageJson = (projectRoot) => {
1540
+ const packageJson = readPackageJson(join5(projectRoot, "package.json"));
1541
+ if (packageJson?.workspaces === void 0) {
1542
+ return [];
1543
+ }
1544
+ const workspaces = packageJson.workspaces;
1545
+ if (Array.isArray(workspaces)) {
1546
+ const workspaceArray = workspaces;
1547
+ return workspaceArray.filter((workspace) => typeof workspace === "string");
1548
+ }
1549
+ const workspaceObject = workspaces;
1550
+ return workspaceObject.packages ?? [];
1551
+ };
1552
+ var readWorkspacePatternsFromPnpmWorkspace = (projectRoot) => {
1553
+ const workspacePath = join5(projectRoot, "pnpm-workspace.yaml");
1554
+ if (!existsSync2(workspacePath)) {
1555
+ return [];
1556
+ }
1557
+ const patterns = [];
1558
+ const lines = readFileSync2(workspacePath, "utf8").split("\n");
1559
+ let readingPackages = false;
1560
+ for (const line of lines) {
1561
+ const trimmed = line.trim();
1562
+ if (trimmed.length === 0 || trimmed.startsWith("#")) {
1563
+ continue;
1564
+ }
1565
+ if (!line.startsWith(" ") && !line.startsWith("-")) {
1566
+ readingPackages = trimmed === "packages:";
1567
+ continue;
1568
+ }
1569
+ if (!readingPackages) {
1570
+ continue;
1571
+ }
1572
+ const match = trimmed.match(/^-\s+(.+)$/);
1573
+ if (match?.[1] !== void 0) {
1574
+ patterns.push(stripQuotes2(match[1].trim()));
1575
+ }
1576
+ }
1577
+ return patterns;
1578
+ };
1579
+ var expandPattern = (projectRoot, pattern) => {
1580
+ const segments = normalizePath(pattern).split("/").filter((segment) => segment.length > 0);
1581
+ let current = [projectRoot];
1582
+ for (const segment of segments) {
1583
+ const next = [];
1584
+ if (segment === "*") {
1585
+ for (const directory of current) {
1586
+ if (!existsSync2(directory)) {
1587
+ continue;
1588
+ }
1589
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
1590
+ if (entry.isDirectory()) {
1591
+ next.push(join5(directory, entry.name));
1592
+ }
1593
+ }
1594
+ }
1595
+ } else {
1596
+ for (const directory of current) {
1597
+ const candidate = join5(directory, segment);
1598
+ if (existsSync2(candidate) && statSync(candidate).isDirectory()) {
1599
+ next.push(candidate);
1600
+ }
1601
+ }
1602
+ }
1603
+ current = next;
1604
+ }
1605
+ return current;
1606
+ };
1607
+ var loadWorkspaceDependencyManifests = (projectRoot) => {
1608
+ const absoluteRoot = resolve(projectRoot);
1609
+ const packageJsonPatterns = readWorkspacePatternsFromPackageJson(absoluteRoot);
1610
+ const pnpmPatterns = readWorkspacePatternsFromPnpmWorkspace(absoluteRoot);
1611
+ const patterns = packageJsonPatterns.length > 0 ? packageJsonPatterns : pnpmPatterns;
1612
+ const includePatterns = patterns.filter((pattern) => !pattern.startsWith("!"));
1613
+ const excludePatterns = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1));
1614
+ const excludedPaths = new Set(
1615
+ excludePatterns.flatMap((pattern) => expandPattern(absoluteRoot, pattern)).map((path) => normalizePath(relative(absoluteRoot, path)))
1616
+ );
1617
+ const manifestsByPath = /* @__PURE__ */ new Map();
1618
+ for (const pattern of includePatterns) {
1619
+ for (const absoluteWorkspacePath of expandPattern(absoluteRoot, pattern)) {
1620
+ const relativePath = normalizePath(relative(absoluteRoot, absoluteWorkspacePath));
1621
+ if (relativePath.length === 0 || relativePath.startsWith("..") || excludedPaths.has(relativePath)) {
1622
+ continue;
1623
+ }
1624
+ const packageJsonPath2 = join5(absoluteWorkspacePath, "package.json");
1625
+ if (!existsSync2(packageJsonPath2)) {
1626
+ continue;
1627
+ }
1628
+ const rawPackageJson = readFileSync2(packageJsonPath2, "utf8");
1629
+ const packageJson = readPackageJson(packageJsonPath2);
1630
+ manifestsByPath.set(relativePath, {
1631
+ name: packageJson?.name ?? basename(absoluteWorkspacePath),
1632
+ path: relativePath,
1633
+ kind: inferWorkspaceKind(relativePath),
1634
+ directDependencies: parsePackageJson(rawPackageJson)
1635
+ });
1636
+ }
1637
+ }
1638
+ return [...manifestsByPath.values()].sort((a, b) => a.path.localeCompare(b.path));
1639
+ };
1426
1640
  var withDefaults = (overrides) => ({
1427
1641
  ...DEFAULT_EXTERNAL_ANALYSIS_CONFIG,
1428
1642
  ...overrides
@@ -1467,7 +1681,8 @@ var analyzeDependencyExposure = async (input, metadataProvider, onProgress) => {
1467
1681
  input.repositoryPath,
1468
1682
  extraction,
1469
1683
  metadataByKey,
1470
- config
1684
+ config,
1685
+ loadWorkspaceDependencyManifests(input.repositoryPath)
1471
1686
  );
1472
1687
  if (summary.available) {
1473
1688
  onProgress?.({
@@ -1753,7 +1968,7 @@ var analyzeDependencyCandidateFromRegistry = async (input) => {
1753
1968
  };
1754
1969
 
1755
1970
  // ../reporter/dist/index.js
1756
- import { basename, posix } from "path";
1971
+ import { basename as basename2, posix } from "path";
1757
1972
  var SNAPSHOT_SCHEMA_VERSION = "codesentinel.snapshot.v1";
1758
1973
  var REPORT_SCHEMA_VERSION = "codesentinel.report.v1";
1759
1974
  var RISK_MODEL_VERSION = "deterministic-v1";
@@ -2391,13 +2606,97 @@ var repositoryDimensionScores = (snapshot) => {
2391
2606
  interactions: interactionScore
2392
2607
  };
2393
2608
  };
2609
+ var workspaceSummary = (snapshot) => ({
2610
+ structural: [...snapshot.analysis.structural.workspaces ?? []].sort(
2611
+ (a, b) => b.incomingEdgeCount + b.outgoingEdgeCount + b.internalEdgeCount - (a.incomingEdgeCount + a.outgoingEdgeCount + a.internalEdgeCount) || b.fileCount - a.fileCount || a.path.localeCompare(b.path)
2612
+ ).map((workspace) => ({
2613
+ name: workspace.name,
2614
+ path: workspace.path,
2615
+ kind: workspace.kind,
2616
+ fileCount: workspace.fileCount,
2617
+ internalEdgeCount: workspace.internalEdgeCount,
2618
+ incomingEdgeCount: workspace.incomingEdgeCount,
2619
+ outgoingEdgeCount: workspace.outgoingEdgeCount
2620
+ })),
2621
+ risk: [...snapshot.analysis.risk.workspaceScores].sort((a, b) => b.score - a.score || a.path.localeCompare(b.path)).map((workspace) => ({
2622
+ name: workspace.name,
2623
+ path: workspace.path,
2624
+ kind: workspace.kind,
2625
+ score: workspace.score,
2626
+ normalizedScore: workspace.normalizedScore,
2627
+ fileCount: workspace.fileCount,
2628
+ averageFileRisk: workspace.averageFileRisk,
2629
+ peakFileRisk: workspace.peakFileRisk,
2630
+ internalEdgeCount: workspace.internalEdgeCount,
2631
+ incomingEdgeCount: workspace.incomingEdgeCount,
2632
+ outgoingEdgeCount: workspace.outgoingEdgeCount,
2633
+ topFiles: workspace.topFiles.slice(0, 5).map((file) => ({
2634
+ file: file.file,
2635
+ score: file.score
2636
+ }))
2637
+ })),
2638
+ evolution: snapshot.analysis.evolution.available ? [...snapshot.analysis.evolution.workspaces ?? []].sort(
2639
+ (a, b) => b.recentVolatility - a.recentVolatility || b.churnTotal - a.churnTotal || b.commitCount - a.commitCount || a.path.localeCompare(b.path)
2640
+ ).map((workspace) => ({
2641
+ name: workspace.name,
2642
+ path: workspace.path,
2643
+ kind: workspace.kind,
2644
+ fileCount: workspace.fileCount,
2645
+ commitCount: workspace.commitCount,
2646
+ churnTotal: workspace.churnTotal,
2647
+ recentCommitCount: workspace.recentCommitCount,
2648
+ recentVolatility: workspace.recentVolatility,
2649
+ topAuthorShareByCommits: workspace.topAuthorShareByCommits,
2650
+ busFactorByCommits: workspace.busFactorByCommits,
2651
+ hotspotCount: workspace.hotspotCount,
2652
+ topHotspots: workspace.topHotspots.slice(0, 5).map((hotspot) => ({
2653
+ filePath: hotspot.filePath,
2654
+ rank: hotspot.rank,
2655
+ commitCount: hotspot.commitCount,
2656
+ churnTotal: hotspot.churnTotal
2657
+ })),
2658
+ internalCouplingPairCount: workspace.internalCouplingPairCount,
2659
+ incomingCouplingPairCount: workspace.incomingCouplingPairCount,
2660
+ outgoingCouplingPairCount: workspace.outgoingCouplingPairCount
2661
+ })) : [],
2662
+ external: snapshot.analysis.external.available ? [...snapshot.analysis.external.workspaces ?? []].sort(
2663
+ (a, b) => b.highRiskDependencies.length - a.highRiskDependencies.length || b.transitiveExposureDependencies.length - a.transitiveExposureDependencies.length || b.directDependencies - a.directDependencies || a.path.localeCompare(b.path)
2664
+ ).map((workspace) => ({
2665
+ name: workspace.name,
2666
+ path: workspace.path,
2667
+ kind: workspace.kind,
2668
+ directDependencies: workspace.directDependencies,
2669
+ directProductionDependencies: workspace.directProductionDependencies,
2670
+ directDevelopmentDependencies: workspace.directDevelopmentDependencies,
2671
+ unresolvedDependencies: [...workspace.unresolvedDependencies].sort(
2672
+ (a, b) => a.localeCompare(b)
2673
+ ),
2674
+ dependencyNames: [...workspace.dependencyNames].sort((a, b) => a.localeCompare(b)),
2675
+ sharedDependencies: [...workspace.sharedDependencies].sort((a, b) => a.localeCompare(b)),
2676
+ highRiskDependencies: [...workspace.highRiskDependencies].sort(
2677
+ (a, b) => a.localeCompare(b)
2678
+ ),
2679
+ highRiskDevelopmentDependencies: [...workspace.highRiskDevelopmentDependencies].sort(
2680
+ (a, b) => a.localeCompare(b)
2681
+ ),
2682
+ transitiveExposureDependencies: [...workspace.transitiveExposureDependencies].sort(
2683
+ (a, b) => a.localeCompare(b)
2684
+ ),
2685
+ singleMaintainerDependencies: [...workspace.singleMaintainerDependencies].sort(
2686
+ (a, b) => a.localeCompare(b)
2687
+ ),
2688
+ abandonedDependencies: [...workspace.abandonedDependencies].sort(
2689
+ (a, b) => a.localeCompare(b)
2690
+ )
2691
+ })) : []
2692
+ });
2394
2693
  var createReport = (snapshot, diff) => {
2395
2694
  const external = snapshot.analysis.external;
2396
2695
  return {
2397
2696
  schemaVersion: REPORT_SCHEMA_VERSION,
2398
2697
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
2399
2698
  repository: {
2400
- name: basename(snapshot.analysis.structural.targetPath) || snapshot.analysis.structural.targetPath,
2699
+ name: basename2(snapshot.analysis.structural.targetPath) || snapshot.analysis.structural.targetPath,
2401
2700
  targetPath: snapshot.analysis.structural.targetPath,
2402
2701
  riskScore: snapshot.analysis.risk.riskScore,
2403
2702
  normalizedScore: snapshot.analysis.risk.normalizedScore,
@@ -2407,6 +2706,7 @@ var createReport = (snapshot, diff) => {
2407
2706
  dimensionScores: repositoryDimensionScores(snapshot)
2408
2707
  },
2409
2708
  health: snapshot.analysis.health,
2709
+ workspaces: workspaceSummary(snapshot),
2410
2710
  hotspots: hotspotItems(snapshot),
2411
2711
  structural: {
2412
2712
  cycleCount: snapshot.analysis.structural.metrics.cycleCount,
@@ -2480,6 +2780,55 @@ var renderTextDiff = (report) => {
2480
2780
  ` resolvedCycles: ${report.diff.resolvedCycles.join(", ") || "none"}`
2481
2781
  ];
2482
2782
  };
2783
+ var renderTextWorkspaceSummary = (report) => {
2784
+ const workspaceCount = Math.max(
2785
+ report.workspaces.structural.length,
2786
+ report.workspaces.risk.length,
2787
+ report.workspaces.evolution.length,
2788
+ report.workspaces.external.length
2789
+ );
2790
+ if (workspaceCount === 0) {
2791
+ return [];
2792
+ }
2793
+ const lines = ["", "Workspace Summary"];
2794
+ lines.push(" topRisk:");
2795
+ for (const workspace of report.workspaces.risk.slice(0, 5)) {
2796
+ lines.push(
2797
+ ` - ${workspace.path} | score=${workspace.score} files=${workspace.fileCount} peakFileRisk=${workspace.peakFileRisk}`
2798
+ );
2799
+ }
2800
+ if (report.workspaces.risk.length === 0) {
2801
+ lines.push(" - none");
2802
+ }
2803
+ lines.push(" structuralCoupling:");
2804
+ for (const workspace of report.workspaces.structural.slice(0, 5)) {
2805
+ lines.push(
2806
+ ` - ${workspace.path} | internal=${workspace.internalEdgeCount} incoming=${workspace.incomingEdgeCount} outgoing=${workspace.outgoingEdgeCount}`
2807
+ );
2808
+ }
2809
+ if (report.workspaces.structural.length === 0) {
2810
+ lines.push(" - none");
2811
+ }
2812
+ lines.push(" evolutionHotspots:");
2813
+ for (const workspace of report.workspaces.evolution.slice(0, 5)) {
2814
+ lines.push(
2815
+ ` - ${workspace.path} | commits=${workspace.commitCount} churn=${workspace.churnTotal} recentVolatility=${workspace.recentVolatility}`
2816
+ );
2817
+ }
2818
+ if (report.workspaces.evolution.length === 0) {
2819
+ lines.push(" - none");
2820
+ }
2821
+ lines.push(" dependencyExposure:");
2822
+ for (const workspace of report.workspaces.external.slice(0, 5)) {
2823
+ lines.push(
2824
+ ` - ${workspace.path} | direct=${workspace.directDependencies} shared=${workspace.sharedDependencies.length} highRisk=${workspace.highRiskDependencies.length} transitiveExposure=${workspace.transitiveExposureDependencies.length}`
2825
+ );
2826
+ }
2827
+ if (report.workspaces.external.length === 0) {
2828
+ lines.push(" - none");
2829
+ }
2830
+ return lines;
2831
+ };
2483
2832
  var renderTextReport = (report) => {
2484
2833
  const lines = [];
2485
2834
  lines.push("Repository Summary");
@@ -2545,6 +2894,7 @@ var renderTextReport = (report) => {
2545
2894
  lines.push(` cycleCount: ${report.structural.cycleCount}`);
2546
2895
  lines.push(` cycles: ${report.structural.cycles.join(" ; ") || "none"}`);
2547
2896
  lines.push(` fragileClusters: ${report.structural.fragileClusters.length}`);
2897
+ lines.push(...renderTextWorkspaceSummary(report));
2548
2898
  lines.push("");
2549
2899
  lines.push("External Exposure");
2550
2900
  if (!report.external.available) {
@@ -2587,6 +2937,59 @@ var renderMarkdownDiff = (report) => {
2587
2937
  `- resolvedCycles: ${report.diff.resolvedCycles.map((item) => `\`${item}\``).join(", ") || "none"}`
2588
2938
  ];
2589
2939
  };
2940
+ var renderMarkdownWorkspaceSummary = (report) => {
2941
+ const workspaceCount = Math.max(
2942
+ report.workspaces.structural.length,
2943
+ report.workspaces.risk.length,
2944
+ report.workspaces.evolution.length,
2945
+ report.workspaces.external.length
2946
+ );
2947
+ if (workspaceCount === 0) {
2948
+ return [];
2949
+ }
2950
+ const lines = ["", "## Workspace Summary"];
2951
+ lines.push("- top risk:");
2952
+ if (report.workspaces.risk.length === 0) {
2953
+ lines.push(" - none");
2954
+ } else {
2955
+ for (const workspace of report.workspaces.risk.slice(0, 5)) {
2956
+ lines.push(
2957
+ ` - \`${workspace.path}\`: score=\`${workspace.score}\`, files=\`${workspace.fileCount}\`, peak file risk=\`${workspace.peakFileRisk}\``
2958
+ );
2959
+ }
2960
+ }
2961
+ lines.push("- structural coupling:");
2962
+ if (report.workspaces.structural.length === 0) {
2963
+ lines.push(" - none");
2964
+ } else {
2965
+ for (const workspace of report.workspaces.structural.slice(0, 5)) {
2966
+ lines.push(
2967
+ ` - \`${workspace.path}\`: internal=\`${workspace.internalEdgeCount}\`, incoming=\`${workspace.incomingEdgeCount}\`, outgoing=\`${workspace.outgoingEdgeCount}\``
2968
+ );
2969
+ }
2970
+ }
2971
+ lines.push("- evolution hotspots:");
2972
+ if (report.workspaces.evolution.length === 0) {
2973
+ lines.push(" - none");
2974
+ } else {
2975
+ for (const workspace of report.workspaces.evolution.slice(0, 5)) {
2976
+ lines.push(
2977
+ ` - \`${workspace.path}\`: commits=\`${workspace.commitCount}\`, churn=\`${workspace.churnTotal}\`, recent volatility=\`${workspace.recentVolatility}\``
2978
+ );
2979
+ }
2980
+ }
2981
+ lines.push("- dependency exposure:");
2982
+ if (report.workspaces.external.length === 0) {
2983
+ lines.push(" - none");
2984
+ } else {
2985
+ for (const workspace of report.workspaces.external.slice(0, 5)) {
2986
+ lines.push(
2987
+ ` - \`${workspace.path}\`: direct=\`${workspace.directDependencies}\`, shared=\`${workspace.sharedDependencies.length}\`, high risk=\`${workspace.highRiskDependencies.length}\`, transitive exposure=\`${workspace.transitiveExposureDependencies.length}\``
2988
+ );
2989
+ }
2990
+ }
2991
+ return lines;
2992
+ };
2590
2993
  var renderMarkdownReport = (report) => {
2591
2994
  const lines = [];
2592
2995
  lines.push("# CodeSentinel Report");
@@ -2658,6 +3061,7 @@ var renderMarkdownReport = (report) => {
2658
3061
  `- cycles: ${report.structural.cycles.map((cycle) => `\`${cycle}\``).join(", ") || "none"}`
2659
3062
  );
2660
3063
  lines.push(`- fragile clusters: \`${report.structural.fragileClusters.length}\``);
3064
+ lines.push(...renderMarkdownWorkspaceSummary(report));
2661
3065
  lines.push("");
2662
3066
  lines.push("## External Exposure Summary");
2663
3067
  if (!report.external.available) {
@@ -2724,7 +3128,7 @@ var formatReport = (report, format) => {
2724
3128
 
2725
3129
  // ../governance/dist/index.js
2726
3130
  import { mkdirSync, rmSync } from "fs";
2727
- import { basename as basename2, join as join5, resolve } from "path";
3131
+ import { basename as basename3, join as join6, resolve as resolve2 } from "path";
2728
3132
  import { execFile } from "child_process";
2729
3133
  import { promisify } from "util";
2730
3134
  var EXIT_CODES = {
@@ -3245,10 +3649,10 @@ var tryRunGit = async (repositoryPath, args) => {
3245
3649
  }
3246
3650
  };
3247
3651
  var buildWorktreePath = (repoRoot, sha) => {
3248
- const tmpRoot = join5(repoRoot, SENTINEL_TMP_DIR, WORKTREE_DIR);
3652
+ const tmpRoot = join6(repoRoot, SENTINEL_TMP_DIR, WORKTREE_DIR);
3249
3653
  mkdirSync(tmpRoot, { recursive: true });
3250
3654
  const baseName = `baseline-${sha.slice(0, 12)}-${process.pid}`;
3251
- const candidate = resolve(tmpRoot, baseName);
3655
+ const candidate = resolve2(tmpRoot, baseName);
3252
3656
  return candidate;
3253
3657
  };
3254
3658
  var sanitizeSnapshotForWorktree = (snapshot, worktreePath, canonicalPath) => {
@@ -3281,7 +3685,7 @@ var sanitizeSnapshotForWorktree = (snapshot, worktreePath, canonicalPath) => {
3281
3685
  };
3282
3686
  };
3283
3687
  var resolveBaselineSnapshotFromRef = async (input) => {
3284
- const repositoryPath = resolve(input.repositoryPath);
3688
+ const repositoryPath = resolve2(input.repositoryPath);
3285
3689
  const ref = input.baselineRef.trim();
3286
3690
  if (ref.length === 0) {
3287
3691
  throw new BaselineRefResolutionError("baseline-ref cannot be empty");
@@ -3313,7 +3717,7 @@ var resolveBaselineSnapshotFromRef = async (input) => {
3313
3717
  }
3314
3718
  };
3315
3719
  var resolveAutoBaselineRef = async (input) => {
3316
- const repositoryPath = resolve(input.repositoryPath);
3720
+ const repositoryPath = resolve2(input.repositoryPath);
3317
3721
  const repoRoot = await runGit(repositoryPath, ["rev-parse", "--show-toplevel"]);
3318
3722
  try {
3319
3723
  return await resolveAutoBaseline({
@@ -3336,9 +3740,9 @@ var resolveAutoBaselineRef = async (input) => {
3336
3740
  };
3337
3741
 
3338
3742
  // src/index.ts
3339
- import { readFileSync as readFileSync3 } from "fs";
3743
+ import { readFileSync as readFileSync4 } from "fs";
3340
3744
  import { readFile as readFile7, writeFile as writeFile7 } from "fs/promises";
3341
- import { dirname as dirname3, resolve as resolve6 } from "path";
3745
+ import { dirname as dirname3, resolve as resolve7 } from "path";
3342
3746
  import { fileURLToPath as fileURLToPath2 } from "url";
3343
3747
 
3344
3748
  // src/application/format-analyze-output.ts
@@ -3357,6 +3761,40 @@ var toHealthTier2 = (score) => {
3357
3761
  }
3358
3762
  return "excellent";
3359
3763
  };
3764
+ var createWorkspaceSummaryShape = (summary) => ({
3765
+ structuralTop: [...summary.structural.workspaces ?? []].sort(
3766
+ (a, b) => b.incomingEdgeCount + b.outgoingEdgeCount + b.internalEdgeCount - (a.incomingEdgeCount + a.outgoingEdgeCount + a.internalEdgeCount) || b.fileCount - a.fileCount || a.path.localeCompare(b.path)
3767
+ ).slice(0, 5).map((workspace) => ({
3768
+ path: workspace.path,
3769
+ fileCount: workspace.fileCount,
3770
+ internalEdgeCount: workspace.internalEdgeCount,
3771
+ incomingEdgeCount: workspace.incomingEdgeCount,
3772
+ outgoingEdgeCount: workspace.outgoingEdgeCount
3773
+ })),
3774
+ riskTop: [...summary.risk.workspaceScores].sort((a, b) => b.score - a.score || a.path.localeCompare(b.path)).slice(0, 5).map((workspace) => ({
3775
+ path: workspace.path,
3776
+ score: workspace.score,
3777
+ fileCount: workspace.fileCount,
3778
+ peakFileRisk: workspace.peakFileRisk
3779
+ })),
3780
+ evolutionTop: summary.evolution.available ? [...summary.evolution.workspaces ?? []].sort(
3781
+ (a, b) => b.recentVolatility - a.recentVolatility || b.churnTotal - a.churnTotal || b.commitCount - a.commitCount || a.path.localeCompare(b.path)
3782
+ ).slice(0, 5).map((workspace) => ({
3783
+ path: workspace.path,
3784
+ commitCount: workspace.commitCount,
3785
+ churnTotal: workspace.churnTotal,
3786
+ recentVolatility: workspace.recentVolatility
3787
+ })) : [],
3788
+ dependencyExposureTop: summary.external.available ? [...summary.external.workspaces ?? []].sort(
3789
+ (a, b) => b.highRiskDependencies.length - a.highRiskDependencies.length || b.transitiveExposureDependencies.length - a.transitiveExposureDependencies.length || b.directDependencies - a.directDependencies || a.path.localeCompare(b.path)
3790
+ ).slice(0, 5).map((workspace) => ({
3791
+ path: workspace.path,
3792
+ directDependencies: workspace.directDependencies,
3793
+ sharedDependencies: workspace.sharedDependencies.length,
3794
+ highRiskDependencies: workspace.highRiskDependencies.length,
3795
+ transitiveExposureDependencies: workspace.transitiveExposureDependencies.length
3796
+ })) : []
3797
+ });
3360
3798
  var createSummaryShape = (summary) => ({
3361
3799
  targetPath: summary.structural.targetPath,
3362
3800
  structural: summary.structural.metrics,
@@ -3394,6 +3832,7 @@ var createSummaryShape = (summary) => ({
3394
3832
  fragileClusterCount: summary.risk.fragileClusters.length,
3395
3833
  dependencyAmplificationZoneCount: summary.risk.dependencyAmplificationZones.length
3396
3834
  },
3835
+ workspaces: createWorkspaceSummaryShape(summary),
3397
3836
  health: {
3398
3837
  healthScore: summary.health.healthScore,
3399
3838
  healthTier: toHealthTier2(summary.health.healthScore),
@@ -3748,11 +4187,11 @@ var parseLogLevel = (value) => {
3748
4187
  import { spawn } from "child_process";
3749
4188
  import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
3750
4189
  import { homedir as homedir2 } from "os";
3751
- import { dirname, join as join6 } from "path";
4190
+ import { dirname, join as join7 } from "path";
3752
4191
  import { stderr, stdin } from "process";
3753
4192
  import { clearScreenDown, cursorTo, emitKeypressEvents } from "readline";
3754
4193
  var UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
3755
- var UPDATE_CACHE_PATH = join6(homedir2(), ".cache", "codesentinel", "update-check.json");
4194
+ var UPDATE_CACHE_PATH = join7(homedir2(), ".cache", "codesentinel", "update-check.json");
3756
4195
  var SEMVER_PATTERN = /^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<prerelease>[0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
3757
4196
  var ANSI = {
3758
4197
  reset: "\x1B[0m",
@@ -3984,7 +4423,7 @@ var promptInstall = async (packageName, latestVersion, currentVersion) => {
3984
4423
  );
3985
4424
  return "skip";
3986
4425
  }
3987
- return await new Promise((resolve7) => {
4426
+ return await new Promise((resolve8) => {
3988
4427
  emitKeypressEvents(stdin);
3989
4428
  let selectedIndex = 0;
3990
4429
  const previousRawMode = stdin.isRaw;
@@ -4009,7 +4448,7 @@ var promptInstall = async (packageName, latestVersion, currentVersion) => {
4009
4448
  } else {
4010
4449
  stderr.write("\n");
4011
4450
  }
4012
- resolve7(choice);
4451
+ resolve8(choice);
4013
4452
  };
4014
4453
  const onKeypress = (_str, key) => {
4015
4454
  if (key.ctrl === true && key.name === "c") {
@@ -4203,7 +4642,7 @@ var promptSelection = async (currentVersion, actions) => {
4203
4642
  if (!stdin2.isTTY || !stderr2.isTTY || typeof stdin2.setRawMode !== "function") {
4204
4643
  return "exit";
4205
4644
  }
4206
- return await new Promise((resolve7) => {
4645
+ return await new Promise((resolve8) => {
4207
4646
  emitKeypressEvents2(stdin2);
4208
4647
  let selectedIndex = 0;
4209
4648
  const previousRawMode = stdin2.isRaw;
@@ -4218,7 +4657,7 @@ var promptSelection = async (currentVersion, actions) => {
4218
4657
  stdin2.setRawMode(previousRawMode);
4219
4658
  clearTerminal();
4220
4659
  showCursor2();
4221
- resolve7(selection);
4660
+ resolve8(selection);
4222
4661
  };
4223
4662
  const onKeypress = (_str, key) => {
4224
4663
  if (key.ctrl === true && key.name === "c") {
@@ -4311,7 +4750,7 @@ var waitForReturnToMenu = async () => {
4311
4750
  }
4312
4751
  stderr2.write(`
4313
4752
  ${PROMPT_PADDING}Press enter to return to the menu...`);
4314
- await new Promise((resolve7) => {
4753
+ await new Promise((resolve8) => {
4315
4754
  emitKeypressEvents2(stdin2);
4316
4755
  const previousRawMode = stdin2.isRaw;
4317
4756
  const cleanup = () => {
@@ -4320,7 +4759,7 @@ ${PROMPT_PADDING}Press enter to return to the menu...`);
4320
4759
  stdin2.setRawMode(previousRawMode);
4321
4760
  showCursor2();
4322
4761
  stderr2.write("\n");
4323
- resolve7();
4762
+ resolve8();
4324
4763
  };
4325
4764
  const onKeypress = (_str, key) => {
4326
4765
  if (key.ctrl === true && key.name === "c") {
@@ -4338,7 +4777,7 @@ ${PROMPT_PADDING}Press enter to return to the menu...`);
4338
4777
  });
4339
4778
  };
4340
4779
  var runCliCommand = async (scriptPath2, args) => {
4341
- return await new Promise((resolve7, reject) => {
4780
+ return await new Promise((resolve8, reject) => {
4342
4781
  const child = spawn2(process.execPath, [...process.execArgv, scriptPath2, ...args], {
4343
4782
  stdio: ["inherit", "pipe", "pipe"],
4344
4783
  env: {
@@ -4352,7 +4791,7 @@ var runCliCommand = async (scriptPath2, args) => {
4352
4791
  reject(error);
4353
4792
  });
4354
4793
  child.on("close", (code) => {
4355
- resolve7(code ?? 1);
4794
+ resolve8(code ?? 1);
4356
4795
  });
4357
4796
  });
4358
4797
  };
@@ -4423,14 +4862,14 @@ ${PROMPT_PADDING}Command exited with code ${exitCode}.
4423
4862
  };
4424
4863
 
4425
4864
  // src/application/run-analyze-command.ts
4426
- import { resolve as resolve3 } from "path";
4865
+ import { resolve as resolve4 } from "path";
4427
4866
 
4428
4867
  // ../code-graph/dist/index.js
4429
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
4430
- import { extname, isAbsolute, join as join7, relative, resolve as resolve2 } from "path";
4868
+ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
4869
+ import { extname, isAbsolute, join as join8, relative as relative2, resolve as resolve3 } from "path";
4431
4870
  import * as ts from "typescript";
4432
- import { existsSync as existsSync22, readdirSync, readFileSync as readFileSync22, statSync } from "fs";
4433
- import { basename as basename3, join as join22, relative as relative2, resolve as resolve22 } from "path";
4871
+ import { existsSync as existsSync22, readdirSync as readdirSync2, readFileSync as readFileSync22, statSync as statSync2 } from "fs";
4872
+ import { basename as basename4, join as join22, relative as relative22, resolve as resolve22 } from "path";
4434
4873
  var edgeKey = (from, to) => `${from}\0${to}`;
4435
4874
  var createGraphData = (nodes, rawEdges) => {
4436
4875
  const sortedNodes = [...nodes].sort((a, b) => a.id.localeCompare(b.id));
@@ -4798,10 +5237,10 @@ var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([
4798
5237
  ".cache",
4799
5238
  "out"
4800
5239
  ]);
4801
- var normalizePath = (pathValue) => pathValue.replaceAll("\\", "/");
4802
- var readPackageJson = (packageJsonPath2) => {
5240
+ var normalizePath2 = (pathValue) => pathValue.replaceAll("\\", "/");
5241
+ var readPackageJson2 = (packageJsonPath2) => {
4803
5242
  try {
4804
- return JSON.parse(readFileSync2(packageJsonPath2, "utf8"));
5243
+ return JSON.parse(readFileSync3(packageJsonPath2, "utf8"));
4805
5244
  } catch {
4806
5245
  return null;
4807
5246
  }
@@ -4811,11 +5250,11 @@ var isProjectSourceFile = (filePath, projectRoot) => {
4811
5250
  if (!SOURCE_EXTENSIONS.has(extension)) {
4812
5251
  return false;
4813
5252
  }
4814
- const relativePath = relative(projectRoot, filePath);
5253
+ const relativePath = relative2(projectRoot, filePath);
4815
5254
  if (relativePath.startsWith("..")) {
4816
5255
  return false;
4817
5256
  }
4818
- const normalizedRelativePath = normalizePath(relativePath);
5257
+ const normalizedRelativePath = normalizePath2(relativePath);
4819
5258
  const segments = normalizedRelativePath.split("/");
4820
5259
  return !segments.some((segment) => IGNORED_SEGMENTS.has(segment));
4821
5260
  };
@@ -4826,7 +5265,7 @@ var discoverSourceFilesByScan = (projectRoot) => {
4826
5265
  SCAN_EXCLUDES,
4827
5266
  SCAN_INCLUDES
4828
5267
  );
4829
- return files.map((filePath) => resolve2(filePath));
5268
+ return files.map((filePath) => resolve3(filePath));
4830
5269
  };
4831
5270
  var parseTsConfigFile = (configPath) => {
4832
5271
  const parsedCommandLine = ts.getParsedCommandLineOfConfigFile(
@@ -4857,7 +5296,7 @@ var collectFilesFromTsConfigGraph = (projectRoot) => {
4857
5296
  const collectedFiles = /* @__PURE__ */ new Set();
4858
5297
  let rootOptions = null;
4859
5298
  const visitConfig = (configPath) => {
4860
- const absoluteConfigPath = resolve2(configPath);
5299
+ const absoluteConfigPath = resolve3(configPath);
4861
5300
  if (visitedConfigPaths.has(absoluteConfigPath)) {
4862
5301
  return;
4863
5302
  }
@@ -4867,10 +5306,10 @@ var collectFilesFromTsConfigGraph = (projectRoot) => {
4867
5306
  rootOptions = parsed.options;
4868
5307
  }
4869
5308
  for (const filePath of parsed.fileNames) {
4870
- collectedFiles.add(resolve2(filePath));
5309
+ collectedFiles.add(resolve3(filePath));
4871
5310
  }
4872
5311
  for (const reference of parsed.projectReferences ?? []) {
4873
- const referencePath = resolve2(reference.path);
5312
+ const referencePath = resolve3(reference.path);
4874
5313
  const referenceConfigPath = ts.sys.directoryExists(referencePath) ? ts.findConfigFile(
4875
5314
  referencePath,
4876
5315
  (filePath) => ts.sys.fileExists(filePath),
@@ -5013,7 +5452,7 @@ var parseWorkspaceSpecifier = (specifier, workspaceNames) => {
5013
5452
  var expandFileCandidates = (pathWithoutExtension) => [
5014
5453
  pathWithoutExtension,
5015
5454
  ...[...SOURCE_EXTENSIONS].map((extension) => `${pathWithoutExtension}${extension}`),
5016
- ...[...SOURCE_EXTENSIONS].map((extension) => join7(pathWithoutExtension, `index${extension}`))
5455
+ ...[...SOURCE_EXTENSIONS].map((extension) => join8(pathWithoutExtension, `index${extension}`))
5017
5456
  ];
5018
5457
  var isExportArray = (value) => Array.isArray(value);
5019
5458
  var isExportMap = (value) => typeof value !== "string" && !isExportArray(value);
@@ -5074,8 +5513,8 @@ var collectPackageExportCandidates = (packageJson, subpath) => {
5074
5513
  var resolveFirstAnalyzedCandidate = (candidates, sourceFilePathSet) => {
5075
5514
  for (const candidate of candidates) {
5076
5515
  for (const expanded of expandFileCandidates(candidate)) {
5077
- const normalized = normalizePath(expanded);
5078
- if (sourceFilePathSet.has(normalized) && existsSync2(normalized)) {
5516
+ const normalized = normalizePath2(expanded);
5517
+ if (sourceFilePathSet.has(normalized) && existsSync3(normalized)) {
5079
5518
  return normalized;
5080
5519
  }
5081
5520
  }
@@ -5094,8 +5533,8 @@ var createWorkspaceResolver = (projectRoot, workspaces, sourceFilePathSet) => {
5094
5533
  if (workspace === void 0) {
5095
5534
  return void 0;
5096
5535
  }
5097
- const workspaceRoot = resolve2(projectRoot, workspace.path);
5098
- const packageJson = readPackageJson(join7(workspaceRoot, "package.json"));
5536
+ const workspaceRoot = resolve3(projectRoot, workspace.path);
5537
+ const packageJson = readPackageJson2(join8(workspaceRoot, "package.json"));
5099
5538
  const candidates = parsed.subpath === null ? [
5100
5539
  ...collectPackageExportCandidates(packageJson, null),
5101
5540
  packageJson?.source,
@@ -5108,10 +5547,10 @@ var createWorkspaceResolver = (projectRoot, workspaces, sourceFilePathSet) => {
5108
5547
  ].filter((candidate) => candidate !== void 0) : [
5109
5548
  ...collectPackageExportCandidates(packageJson, parsed.subpath),
5110
5549
  parsed.subpath,
5111
- join7("src", parsed.subpath)
5550
+ join8("src", parsed.subpath)
5112
5551
  ];
5113
5552
  return resolveFirstAnalyzedCandidate(
5114
- candidates.map((candidate) => resolve2(workspaceRoot, candidate)),
5553
+ candidates.map((candidate) => resolve3(workspaceRoot, candidate)),
5115
5554
  sourceFilePathSet
5116
5555
  );
5117
5556
  };
@@ -5140,7 +5579,7 @@ var createTsPathAliasResolver = (projectRoot, options, sourceFilePathSet) => {
5140
5579
  }
5141
5580
  const replacement = hasWildcard ? specifier.slice(prefix.length, specifier.length - suffix.length) : "";
5142
5581
  const candidates = substitutions.map(
5143
- (substitution) => resolve2(baseUrl, hasWildcard ? substitution.replaceAll("*", replacement) : substitution)
5582
+ (substitution) => resolve3(baseUrl, hasWildcard ? substitution.replaceAll("*", replacement) : substitution)
5144
5583
  );
5145
5584
  const resolved = resolveFirstAnalyzedCandidate(candidates, sourceFilePathSet);
5146
5585
  if (resolved !== void 0) {
@@ -5151,10 +5590,10 @@ var createTsPathAliasResolver = (projectRoot, options, sourceFilePathSet) => {
5151
5590
  };
5152
5591
  };
5153
5592
  var parseTypescriptProject = (projectPath, onProgress, workspaces = []) => {
5154
- const projectRoot = isAbsolute(projectPath) ? projectPath : resolve2(projectPath);
5593
+ const projectRoot = isAbsolute(projectPath) ? projectPath : resolve3(projectPath);
5155
5594
  const { fileNames, options, tsconfigCount, usedFallbackScan } = parseTsConfig(projectRoot);
5156
5595
  onProgress?.({ stage: "config_resolved", tsconfigCount, usedFallbackScan });
5157
- const sourceFilePaths = fileNames.filter((filePath) => isProjectSourceFile(filePath, projectRoot)).map((filePath) => normalizePath(resolve2(filePath)));
5596
+ const sourceFilePaths = fileNames.filter((filePath) => isProjectSourceFile(filePath, projectRoot)).map((filePath) => normalizePath2(resolve3(filePath)));
5158
5597
  const uniqueSourceFilePaths = [...new Set(sourceFilePaths)].sort((a, b) => a.localeCompare(b));
5159
5598
  const sourceFilePathSet = new Set(uniqueSourceFilePaths);
5160
5599
  onProgress?.({ stage: "files_discovered", totalSourceFiles: uniqueSourceFilePaths.length });
@@ -5165,7 +5604,7 @@ var parseTypescriptProject = (projectPath, onProgress, workspaces = []) => {
5165
5604
  onProgress?.({ stage: "program_created", totalSourceFiles: uniqueSourceFilePaths.length });
5166
5605
  const nodeByAbsolutePath = /* @__PURE__ */ new Map();
5167
5606
  for (const sourcePath of uniqueSourceFilePaths) {
5168
- const relativePath = normalizePath(relative(projectRoot, sourcePath));
5607
+ const relativePath = normalizePath2(relative2(projectRoot, sourcePath));
5169
5608
  const nodeId = relativePath;
5170
5609
  nodeByAbsolutePath.set(sourcePath, {
5171
5610
  id: nodeId,
@@ -5202,7 +5641,7 @@ var parseTypescriptProject = (projectPath, onProgress, workspaces = []) => {
5202
5641
  ts.sys
5203
5642
  ).resolvedModule;
5204
5643
  if (resolved !== void 0) {
5205
- resolvedPath = normalizePath(resolve2(resolved.resolvedFileName));
5644
+ resolvedPath = normalizePath2(resolve3(resolved.resolvedFileName));
5206
5645
  }
5207
5646
  if (resolvedPath === void 0 || !sourceFilePathSet.has(resolvedPath)) {
5208
5647
  resolvedPath = resolveTsPathAlias(specifier);
@@ -5237,16 +5676,16 @@ var parseTypescriptProject = (projectPath, onProgress, workspaces = []) => {
5237
5676
  edges
5238
5677
  };
5239
5678
  };
5240
- var normalizePath2 = (pathValue) => pathValue.replaceAll("\\", "/");
5241
- var stripQuotes2 = (value) => value.replace(/^['"]|['"]$/g, "");
5242
- var readPackageJson2 = (path) => {
5679
+ var normalizePath22 = (pathValue) => pathValue.replaceAll("\\", "/");
5680
+ var stripQuotes3 = (value) => value.replace(/^['"]|['"]$/g, "");
5681
+ var readPackageJson22 = (path) => {
5243
5682
  try {
5244
5683
  return JSON.parse(readFileSync22(path, "utf8"));
5245
5684
  } catch {
5246
5685
  return null;
5247
5686
  }
5248
5687
  };
5249
- var inferWorkspaceKind = (workspacePath) => {
5688
+ var inferWorkspaceKind2 = (workspacePath) => {
5250
5689
  const segments = workspacePath.split("/");
5251
5690
  const first = segments[0] ?? "";
5252
5691
  if (first === "apps" || first === "app") {
@@ -5266,8 +5705,8 @@ var inferWorkspaceKind = (workspacePath) => {
5266
5705
  }
5267
5706
  return "unknown";
5268
5707
  };
5269
- var readWorkspacePatternsFromPackageJson = (projectRoot) => {
5270
- const packageJson = readPackageJson2(join22(projectRoot, "package.json"));
5708
+ var readWorkspacePatternsFromPackageJson2 = (projectRoot) => {
5709
+ const packageJson = readPackageJson22(join22(projectRoot, "package.json"));
5271
5710
  if (packageJson?.workspaces === void 0) {
5272
5711
  return [];
5273
5712
  }
@@ -5279,7 +5718,7 @@ var readWorkspacePatternsFromPackageJson = (projectRoot) => {
5279
5718
  const workspaceObject = workspaces;
5280
5719
  return workspaceObject.packages ?? [];
5281
5720
  };
5282
- var readWorkspacePatternsFromPnpmWorkspace = (projectRoot) => {
5721
+ var readWorkspacePatternsFromPnpmWorkspace2 = (projectRoot) => {
5283
5722
  const workspacePath = join22(projectRoot, "pnpm-workspace.yaml");
5284
5723
  if (!existsSync22(workspacePath)) {
5285
5724
  return [];
@@ -5301,13 +5740,13 @@ var readWorkspacePatternsFromPnpmWorkspace = (projectRoot) => {
5301
5740
  }
5302
5741
  const match = trimmed.match(/^-\s+(.+)$/);
5303
5742
  if (match?.[1] !== void 0) {
5304
- patterns.push(stripQuotes2(match[1].trim()));
5743
+ patterns.push(stripQuotes3(match[1].trim()));
5305
5744
  }
5306
5745
  }
5307
5746
  return patterns;
5308
5747
  };
5309
- var expandPattern = (projectRoot, pattern) => {
5310
- const segments = normalizePath2(pattern).split("/").filter((segment) => segment.length > 0);
5748
+ var expandPattern2 = (projectRoot, pattern) => {
5749
+ const segments = normalizePath22(pattern).split("/").filter((segment) => segment.length > 0);
5311
5750
  let current = [projectRoot];
5312
5751
  for (const segment of segments) {
5313
5752
  const next = [];
@@ -5316,7 +5755,7 @@ var expandPattern = (projectRoot, pattern) => {
5316
5755
  if (!existsSync22(directory)) {
5317
5756
  continue;
5318
5757
  }
5319
- for (const entry of readdirSync(directory, { withFileTypes: true })) {
5758
+ for (const entry of readdirSync2(directory, { withFileTypes: true })) {
5320
5759
  if (entry.isDirectory()) {
5321
5760
  next.push(join22(directory, entry.name));
5322
5761
  }
@@ -5325,7 +5764,7 @@ var expandPattern = (projectRoot, pattern) => {
5325
5764
  } else {
5326
5765
  for (const directory of current) {
5327
5766
  const candidate = join22(directory, segment);
5328
- if (existsSync22(candidate) && statSync(candidate).isDirectory()) {
5767
+ if (existsSync22(candidate) && statSync2(candidate).isDirectory()) {
5329
5768
  next.push(candidate);
5330
5769
  }
5331
5770
  }
@@ -5336,18 +5775,18 @@ var expandPattern = (projectRoot, pattern) => {
5336
5775
  };
5337
5776
  var discoverWorkspacePackages = (projectRoot) => {
5338
5777
  const absoluteRoot = resolve22(projectRoot);
5339
- const packageJsonPatterns = readWorkspacePatternsFromPackageJson(absoluteRoot);
5340
- const pnpmPatterns = readWorkspacePatternsFromPnpmWorkspace(absoluteRoot);
5778
+ const packageJsonPatterns = readWorkspacePatternsFromPackageJson2(absoluteRoot);
5779
+ const pnpmPatterns = readWorkspacePatternsFromPnpmWorkspace2(absoluteRoot);
5341
5780
  const patterns = packageJsonPatterns.length > 0 ? packageJsonPatterns : pnpmPatterns;
5342
5781
  const includePatterns = patterns.filter((pattern) => !pattern.startsWith("!"));
5343
5782
  const excludePatterns = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1));
5344
5783
  const excludedPaths = new Set(
5345
- excludePatterns.flatMap((pattern) => expandPattern(absoluteRoot, pattern)).map((path) => normalizePath2(relative2(absoluteRoot, path)))
5784
+ excludePatterns.flatMap((pattern) => expandPattern2(absoluteRoot, pattern)).map((path) => normalizePath22(relative22(absoluteRoot, path)))
5346
5785
  );
5347
5786
  const packagesByPath = /* @__PURE__ */ new Map();
5348
5787
  for (const pattern of includePatterns) {
5349
- for (const absoluteWorkspacePath of expandPattern(absoluteRoot, pattern)) {
5350
- const relativePath = normalizePath2(relative2(absoluteRoot, absoluteWorkspacePath));
5788
+ for (const absoluteWorkspacePath of expandPattern2(absoluteRoot, pattern)) {
5789
+ const relativePath = normalizePath22(relative22(absoluteRoot, absoluteWorkspacePath));
5351
5790
  if (relativePath.length === 0 || relativePath.startsWith("..") || excludedPaths.has(relativePath)) {
5352
5791
  continue;
5353
5792
  }
@@ -5355,11 +5794,11 @@ var discoverWorkspacePackages = (projectRoot) => {
5355
5794
  if (!existsSync22(packageJsonPath2)) {
5356
5795
  continue;
5357
5796
  }
5358
- const packageJson = readPackageJson2(packageJsonPath2);
5797
+ const packageJson = readPackageJson22(packageJsonPath2);
5359
5798
  packagesByPath.set(relativePath, {
5360
- name: packageJson?.name ?? basename3(absoluteWorkspacePath),
5799
+ name: packageJson?.name ?? basename4(absoluteWorkspacePath),
5361
5800
  path: relativePath,
5362
- kind: inferWorkspaceKind(relativePath)
5801
+ kind: inferWorkspaceKind2(relativePath)
5363
5802
  });
5364
5803
  }
5365
5804
  }
@@ -8177,7 +8616,7 @@ var evaluateRepositoryRisk = (input, options = {}) => {
8177
8616
  };
8178
8617
 
8179
8618
  // src/application/run-analyze-command.ts
8180
- var resolveTargetPath = (inputPath, cwd) => resolve3(cwd, inputPath ?? ".");
8619
+ var resolveTargetPath = (inputPath, cwd) => resolve4(cwd, inputPath ?? ".");
8181
8620
  var scoringProfileConfig = {
8182
8621
  default: void 0,
8183
8622
  personal: {
@@ -8520,7 +8959,7 @@ var runCheckCommand = async (inputPath, authorIdentityMode, options, logger = cr
8520
8959
 
8521
8960
  // src/application/run-ci-command.ts
8522
8961
  import { readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
8523
- import { relative as relative3, resolve as resolve4 } from "path";
8962
+ import { relative as relative3, resolve as resolve5 } from "path";
8524
8963
  var isPathOutsideBase = (value) => {
8525
8964
  return value === ".." || value.startsWith("../") || value.startsWith("..\\");
8526
8965
  };
@@ -8533,7 +8972,7 @@ var runCiCommand = async (inputPath, authorIdentityMode, options, logger = creat
8533
8972
  if (options.baselineSha !== void 0 && options.baselineRef !== "auto") {
8534
8973
  throw new GovernanceConfigurationError("baseline-sha requires --baseline-ref auto");
8535
8974
  }
8536
- const resolvedTargetPath = resolve4(inputPath ?? process.cwd());
8975
+ const resolvedTargetPath = resolve5(inputPath ?? process.cwd());
8537
8976
  logger.info("building current snapshot");
8538
8977
  const current = await buildAnalysisSnapshot(
8539
8978
  inputPath,
@@ -8593,7 +9032,7 @@ var runCiCommand = async (inputPath, authorIdentityMode, options, logger = creat
8593
9032
  `target path is outside git repository root: ${resolvedTargetPath}`
8594
9033
  );
8595
9034
  }
8596
- const baselineTargetPath = relativeTargetPath.length === 0 || relativeTargetPath === "." ? worktreePath : resolve4(worktreePath, relativeTargetPath);
9035
+ const baselineTargetPath = relativeTargetPath.length === 0 || relativeTargetPath === "." ? worktreePath : resolve5(worktreePath, relativeTargetPath);
8597
9036
  return buildAnalysisSnapshot(
8598
9037
  baselineTargetPath,
8599
9038
  authorIdentityMode,
@@ -8667,15 +9106,15 @@ ${ciMarkdown}`;
8667
9106
  };
8668
9107
 
8669
9108
  // src/application/run-report-command.ts
8670
- import { join as join9 } from "path";
9109
+ import { join as join10 } from "path";
8671
9110
  import { readFile as readFile6, writeFile as writeFile6 } from "fs/promises";
8672
9111
 
8673
9112
  // src/application/html-report.ts
8674
9113
  import { mkdir as mkdir3, readFile as readFile5, rm, stat as stat2, writeFile as writeFile5 } from "fs/promises";
8675
- import { dirname as dirname2, join as join8, resolve as resolve5 } from "path";
9114
+ import { dirname as dirname2, join as join9, resolve as resolve6 } from "path";
8676
9115
  import { fileURLToPath } from "url";
8677
9116
  var HTML_REPORT_DIR = ".codesentinel/report";
8678
- var getBundledHtmlAppPath = () => resolve5(dirname2(fileURLToPath(import.meta.url)), "html-report-app");
9117
+ var getBundledHtmlAppPath = () => resolve6(dirname2(fileURLToPath(import.meta.url)), "html-report-app");
8679
9118
  var serializeReportBootstrap = (report) => `window.__CODESENTINEL_REPORT__ = ${JSON.stringify(report).replaceAll("</", "<\\/")};
8680
9119
  `;
8681
9120
  var escapeInlineScript = (script) => script.replaceAll("</script", "<\\/script").replaceAll("<script", "\\x3Cscript").replaceAll("<!--", "\\x3C!--").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
@@ -8689,18 +9128,18 @@ var readReferencedAssets = async (appPath, indexHtml) => {
8689
9128
  (value) => value !== void 0 && !/^https?:\/\//.test(value) && !value.startsWith("//")
8690
9129
  );
8691
9130
  const styles = await Promise.all(
8692
- stylesheetPaths.map(async (href) => readFile5(resolve5(appPath, href), "utf8"))
9131
+ stylesheetPaths.map(async (href) => readFile5(resolve6(appPath, href), "utf8"))
8693
9132
  );
8694
9133
  const scriptPaths = [...indexHtml.matchAll(/<script[^>]+src=["']([^"']+)["'][^>]*><\/script>/g)].map((match) => match[1]).filter(
8695
9134
  (value) => value !== void 0 && !/^https?:\/\//.test(value) && !value.startsWith("//")
8696
9135
  );
8697
9136
  const scripts = await Promise.all(
8698
- scriptPaths.map(async (src) => readFile5(resolve5(appPath, src), "utf8"))
9137
+ scriptPaths.map(async (src) => readFile5(resolve6(appPath, src), "utf8"))
8699
9138
  );
8700
9139
  return { styles, scripts };
8701
9140
  };
8702
9141
  var inlineBuiltHtml = async (appPath, report) => {
8703
- const indexHtml = await readFile5(resolve5(appPath, "index.html"), "utf8");
9142
+ const indexHtml = await readFile5(resolve6(appPath, "index.html"), "utf8");
8704
9143
  const { styles, scripts } = await readReferencedAssets(appPath, indexHtml);
8705
9144
  const htmlWithoutExternalAssets = indexHtml.replace(
8706
9145
  /\s*<link[^>]+rel=["']stylesheet["'][^>]*>\s*/g,
@@ -8735,7 +9174,7 @@ var assertHtmlAppAssets = async (assetPath) => {
8735
9174
  };
8736
9175
  var resolveHtmlReportOutputPath = (repositoryPath, outputPath) => {
8737
9176
  const invocationCwd = process.env["INIT_CWD"] ?? process.cwd();
8738
- return resolve5(invocationCwd, outputPath ?? join8(repositoryPath, HTML_REPORT_DIR));
9177
+ return resolve6(invocationCwd, outputPath ?? join9(repositoryPath, HTML_REPORT_DIR));
8739
9178
  };
8740
9179
  var writeHtmlReportBundle = async (report, options) => {
8741
9180
  const bundledAppPath = options.bundledAppPath ?? getBundledHtmlAppPath();
@@ -8744,7 +9183,7 @@ var writeHtmlReportBundle = async (report, options) => {
8744
9183
  await rm(outputPath, { recursive: true, force: true });
8745
9184
  await ensureDirectory(outputPath);
8746
9185
  await writeFile5(
8747
- resolve5(outputPath, "index.html"),
9186
+ resolve6(outputPath, "index.html"),
8748
9187
  await inlineBuiltHtml(bundledAppPath, report),
8749
9188
  "utf8"
8750
9189
  );
@@ -8771,15 +9210,15 @@ var openPath = async (targetPath) => {
8771
9210
  if (command === void 0) {
8772
9211
  return false;
8773
9212
  }
8774
- return new Promise((resolve7) => {
9213
+ return new Promise((resolve8) => {
8775
9214
  const child = spawn3(command.command, command.args, {
8776
9215
  detached: true,
8777
9216
  stdio: "ignore"
8778
9217
  });
8779
- child.once("error", () => resolve7(false));
9218
+ child.once("error", () => resolve8(false));
8780
9219
  child.once("spawn", () => {
8781
9220
  child.unref();
8782
- resolve7(true);
9221
+ resolve8(true);
8783
9222
  });
8784
9223
  });
8785
9224
  };
@@ -8817,7 +9256,7 @@ var runReportCommand = async (inputPath, authorIdentityMode, options, logger = c
8817
9256
  ...options.outputPath === void 0 ? {} : { outputPath: options.outputPath }
8818
9257
  });
8819
9258
  if (options.open === true) {
8820
- const opened = await openPath(join9(bundlePath, "index.html"));
9259
+ const opened = await openPath(join10(bundlePath, "index.html"));
8821
9260
  if (!opened) {
8822
9261
  logger.warn("unable to open html report automatically on this platform");
8823
9262
  }
@@ -8908,8 +9347,8 @@ var runExplainCommand = async (inputPath, authorIdentityMode, options, logger =
8908
9347
 
8909
9348
  // src/index.ts
8910
9349
  var program = new Command();
8911
- var packageJsonPath = resolve6(dirname3(fileURLToPath2(import.meta.url)), "../package.json");
8912
- var { version } = JSON.parse(readFileSync3(packageJsonPath, "utf8"));
9350
+ var packageJsonPath = resolve7(dirname3(fileURLToPath2(import.meta.url)), "../package.json");
9351
+ var { version } = JSON.parse(readFileSync4(packageJsonPath, "utf8"));
8913
9352
  var parseRecentWindowDays = (value) => {
8914
9353
  const parsed = Number.parseInt(value, 10);
8915
9354
  if (!Number.isInteger(parsed) || parsed <= 0) {