@getcodesentinel/codesentinel 1.42.0 → 1.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -496,7 +496,7 @@ Reading path: packages/ownership (directory)
496
496
  8 steps (truncated)
497
497
 
498
498
  1. packages/ownership/src/index.ts [entry]
499
- external interface: 4 imports from outside the module
499
+ entry: highest external fan-in (4 imports from outside the module)
500
500
  owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 3 · churn 99 · fan-in 0
501
501
  2. packages/ownership/src/domain/codeowners.ts [core]
502
502
  most changed together with packages/ownership/src/index.ts (3 commits)
@@ -562,7 +562,7 @@ Warnings
562
562
  "order": 1,
563
563
  "filePath": "packages/ownership/src/index.ts",
564
564
  "role": "entry",
565
- "reason": "external interface: 4 imports from outside the module",
565
+ "reason": "entry: highest external fan-in (4 imports from outside the module)",
566
566
  "owner": [
567
567
  {
568
568
  "kind": "user",
@@ -580,7 +580,15 @@ The payload keys are `schemaVersion`, `target`, `targetKind`, `steps`, `people`,
580
580
 
581
581
  ### How the order is chosen
582
582
 
583
- The entry step is the file with the highest fan-in from outside the module. From there a greedy walk scores change coupling at 0.5, internal fan-in at 0.3 and churn at 0.2. When the walk is exhausted it jumps to the highest remaining internal fan-in. Every step carries the signal that selected it, and its role is one of `entry`, `core`, `helper` or `test`.
583
+ The entry step is chosen in five steps:
584
+
585
+ 1. **Seed file.** When the target is a single file, that file is the entry.
586
+ 2. **Single-file module.** When the steppable universe contains a single file, that file is the entry.
587
+ 3. **Package index.** For a directory target, a file directly at the target root is the entry when it is named `index.ts`, `index.tsx`, `main.ts`, `mod.ts` or `public-api.ts` (checked in that order). The file must be part of the steppable universe: a test file excluded by default does not trigger this rule.
588
+ 4. **Highest external fan-in.** Otherwise the file with the most imports from outside the module is the entry. When several files share that maximum, the one with the highest internal fan-out wins: the file that imports the most distinct files inside the module. This tie-break reports `entry: highest internal fan-out (N imports inside the module)`. If the fan-out maximum is zero, or files still tie, the shortest path and then alphabetical order decide, and the reason reports the external-fan-in rule.
589
+ 5. **Highest internal fan-in.** When every file has zero external fan-in, the file with the most importers inside the module is the entry. Ties use the same shortest-then-alphabetical breakers.
590
+
591
+ A single-file target still starts at that file. From there a greedy walk scores change coupling at 0.5, internal fan-in at 0.3 and churn at 0.2. When the walk is exhausted it jumps to the highest remaining internal fan-in. Every step carries the signal that selected it, and its role is one of `entry`, `core`, `helper` or `test`. The git-only fallback (no structural graph) orders by churn and change coupling and does not apply the package-index rule.
584
592
 
585
593
  ### Degraded and edge behaviour
586
594
 
package/dist/index.js CHANGED
@@ -11297,6 +11297,7 @@ var createEmptyGraphIndex = () => {
11297
11297
  return {
11298
11298
  fanInInternal: () => 0,
11299
11299
  fanInExternal: () => 0,
11300
+ fanOutInternal: () => 0,
11300
11301
  neighbours: () => empty,
11301
11302
  importsTo: () => false
11302
11303
  };
@@ -11314,6 +11315,7 @@ var createGraphIndex = (graph, universe) => {
11314
11315
  const universeSet = new Set(universe);
11315
11316
  const internalFanIn = /* @__PURE__ */ new Map();
11316
11317
  const externalFanIn = /* @__PURE__ */ new Map();
11318
+ const internalFanOut = /* @__PURE__ */ new Map();
11317
11319
  const adjacency = /* @__PURE__ */ new Map();
11318
11320
  const edges = /* @__PURE__ */ new Set();
11319
11321
  const addAdjacency = (from, to) => {
@@ -11336,10 +11338,19 @@ var createGraphIndex = (graph, universe) => {
11336
11338
  } else {
11337
11339
  externalFanIn.set(to, (externalFanIn.get(to) ?? 0) + 1);
11338
11340
  }
11341
+ if (universeSet.has(to)) {
11342
+ const targets = internalFanOut.get(from);
11343
+ if (targets === void 0) {
11344
+ internalFanOut.set(from, /* @__PURE__ */ new Set([to]));
11345
+ } else {
11346
+ targets.add(to);
11347
+ }
11348
+ }
11339
11349
  }
11340
11350
  return {
11341
11351
  fanInInternal: (filePath) => internalFanIn.get(filePath) ?? 0,
11342
11352
  fanInExternal: (filePath) => externalFanIn.get(filePath) ?? 0,
11353
+ fanOutInternal: (filePath) => internalFanOut.get(filePath)?.size ?? 0,
11343
11354
  neighbours: (filePath) => {
11344
11355
  const candidates = adjacency.get(filePath);
11345
11356
  if (candidates === void 0) return [];
@@ -11574,17 +11585,106 @@ var roleFor = (order, filePath, includeTests, internalFanIn, medianFanIn) => {
11574
11585
  if (internalFanIn > medianFanIn) return "core";
11575
11586
  return "helper";
11576
11587
  };
11577
- var entryReason = (filePath, steppableCount, graphIndex) => {
11588
+ var INDEX_FILE_NAMES = ["index.ts", "index.tsx", "main.ts", "mod.ts", "public-api.ts"];
11589
+ var chooseEntryByFanIn = (stats, fanIn) => {
11590
+ const firstFile = stats.steppable[0];
11591
+ if (firstFile === void 0) return null;
11592
+ let best = firstFile;
11593
+ let bestFanIn = fanIn(best);
11594
+ for (const filePath of stats.steppable) {
11595
+ const count = fanIn(filePath);
11596
+ if (count > bestFanIn || count === bestFanIn && (filePath.length < best.length || filePath.length === best.length && comparePaths(filePath, best) < 0)) {
11597
+ best = filePath;
11598
+ bestFanIn = count;
11599
+ }
11600
+ }
11601
+ return best;
11602
+ };
11603
+ var chooseShortestPath = (files) => {
11604
+ let best = null;
11605
+ for (const filePath of files) {
11606
+ if (best === null || filePath.length < best.length || filePath.length === best.length && comparePaths(filePath, best) < 0) {
11607
+ best = filePath;
11608
+ }
11609
+ }
11610
+ return best;
11611
+ };
11612
+ var maxOf = (files, value) => {
11613
+ let max = Number.NEGATIVE_INFINITY;
11614
+ for (const filePath of files) {
11615
+ const current = value(filePath);
11616
+ if (current > max) max = current;
11617
+ }
11618
+ return max;
11619
+ };
11620
+ var selectEntry = (stats, graphIndex, targetRoot, seedFile) => {
11621
+ const firstFile = stats.steppable[0];
11622
+ if (firstFile === void 0) return null;
11623
+ if (seedFile !== null && stats.steppableSet.has(seedFile)) {
11624
+ return { filePath: seedFile, rule: "seed" };
11625
+ }
11626
+ if (stats.steppable.length === 1) {
11627
+ return { filePath: firstFile, rule: "single" };
11628
+ }
11629
+ if (targetRoot !== null) {
11630
+ for (const name of INDEX_FILE_NAMES) {
11631
+ const candidate = `${targetRoot}/${name}`;
11632
+ if (stats.steppableSet.has(candidate)) {
11633
+ return { filePath: candidate, rule: "index" };
11634
+ }
11635
+ }
11636
+ }
11637
+ const externalMax = maxOf(stats.steppable, (filePath) => graphIndex.fanInExternal(filePath));
11638
+ if (externalMax > 0) {
11639
+ const externallyTied = stats.steppable.filter(
11640
+ (filePath) => graphIndex.fanInExternal(filePath) === externalMax
11641
+ );
11642
+ if (externallyTied.length > 1) {
11643
+ const fanOutMax = maxOf(externallyTied, (filePath) => graphIndex.fanOutInternal(filePath));
11644
+ if (fanOutMax > 0) {
11645
+ const fanOutTied = externallyTied.filter(
11646
+ (filePath) => graphIndex.fanOutInternal(filePath) === fanOutMax
11647
+ );
11648
+ const fanOutEntry = chooseShortestPath(fanOutTied);
11649
+ if (fanOutEntry !== null) return { filePath: fanOutEntry, rule: "fanout" };
11650
+ }
11651
+ }
11652
+ const externalEntry = chooseShortestPath(externallyTied);
11653
+ if (externalEntry !== null) return { filePath: externalEntry, rule: "external" };
11654
+ }
11655
+ const internalEntry = chooseEntryByFanIn(stats, (filePath) => graphIndex.fanInInternal(filePath));
11656
+ if (internalEntry === null) return null;
11657
+ return { filePath: internalEntry, rule: "internal" };
11658
+ };
11659
+ var entryReason = (selection, steppableCount, graphIndex) => {
11578
11660
  if (steppableCount === 1) return "the module has a single file";
11579
- const external = graphIndex.fanInExternal(filePath);
11580
- if (external > 0) {
11581
- return `external interface: ${importCount(external)} from outside the module`;
11661
+ const { filePath, rule } = selection;
11662
+ if (rule === "seed") {
11663
+ const external = graphIndex.fanInExternal(filePath);
11664
+ if (external > 0) {
11665
+ return `external interface: ${importCount(external)} from outside the module`;
11666
+ }
11667
+ const internal2 = graphIndex.fanInInternal(filePath);
11668
+ if (internal2 === 0) {
11669
+ return "no imports in or out of the module; first by path";
11670
+ }
11671
+ return `no external importers; ${importerCount(internal2)}`;
11672
+ }
11673
+ if (rule === "index") {
11674
+ const external = graphIndex.fanInExternal(filePath);
11675
+ return external > 0 ? `entry: package index (${importCount(external)} from outside the module)` : "entry: package index";
11676
+ }
11677
+ if (rule === "external") {
11678
+ return `entry: highest external fan-in (${importCount(graphIndex.fanInExternal(filePath))} from outside the module)`;
11679
+ }
11680
+ if (rule === "fanout") {
11681
+ return `entry: highest internal fan-out (${importCount(graphIndex.fanOutInternal(filePath))} inside the module)`;
11582
11682
  }
11583
11683
  const internal = graphIndex.fanInInternal(filePath);
11584
11684
  if (internal === 0) {
11585
11685
  return "no imports in or out of the module; first by path";
11586
11686
  }
11587
- return `no external importers; ${importerCount(internal)}`;
11687
+ return `entry: highest internal fan-in (${importerCount(internal)})`;
11588
11688
  };
11589
11689
  var chooseGreedyCandidate = (current, candidates, stats, evolution) => {
11590
11690
  let best = null;
@@ -11647,7 +11747,7 @@ var exhaustedReason = (filePath, stats, evolution) => {
11647
11747
  }
11648
11748
  return `highest churn in the module (${lineCount(evolution.churn(filePath))})`;
11649
11749
  };
11650
- var orderGraphReadingPath = (stats, graphIndex, evolution, includeTests, maxSteps, seedFile) => {
11750
+ var orderGraphReadingPath = (stats, graphIndex, evolution, includeTests, maxSteps, seedFile, targetRoot) => {
11651
11751
  const firstFile = stats.steppable[0];
11652
11752
  if (firstFile === void 0) return [];
11653
11753
  const result = [];
@@ -11666,20 +11766,9 @@ var orderGraphReadingPath = (stats, graphIndex, evolution, includeTests, maxStep
11666
11766
  });
11667
11767
  visited.add(filePath);
11668
11768
  };
11669
- let entry = firstFile;
11670
- if (seedFile !== null && stats.steppableSet.has(seedFile)) {
11671
- entry = seedFile;
11672
- } else {
11673
- let entryExternal = graphIndex.fanInExternal(entry);
11674
- for (const filePath of stats.steppable) {
11675
- const external = graphIndex.fanInExternal(filePath);
11676
- if (external > entryExternal || external === entryExternal && (filePath.length < entry.length || filePath.length === entry.length && comparePaths(filePath, entry) < 0)) {
11677
- entry = filePath;
11678
- entryExternal = external;
11679
- }
11680
- }
11681
- }
11682
- add(entry, entryReason(entry, stats.steppable.length, graphIndex));
11769
+ const selection = selectEntry(stats, graphIndex, targetRoot, seedFile);
11770
+ if (selection === null) return [];
11771
+ add(selection.filePath, entryReason(selection, stats.steppable.length, graphIndex));
11683
11772
  while (result.length < maxSteps) {
11684
11773
  const current = result[result.length - 1]?.filePath;
11685
11774
  if (current === void 0) break;
@@ -11787,7 +11876,8 @@ var orderReadingPath = (params) => {
11787
11876
  params.evolution,
11788
11877
  params.includeTests,
11789
11878
  params.maxSteps,
11790
- seedFile
11879
+ seedFile,
11880
+ params.targetRoot ?? null
11791
11881
  );
11792
11882
  };
11793
11883
  var ownerFor = (filePath, ownership) => {
@@ -11854,7 +11944,8 @@ var buildReadingPath = (input) => {
11854
11944
  hasGraph: graph !== null,
11855
11945
  includeTests,
11856
11946
  maxSteps,
11857
- seedFile: universe.targetKind === "file" ? target : null
11947
+ seedFile: universe.targetKind === "file" ? target : null,
11948
+ targetRoot: universe.targetKind === "directory" ? target : null
11858
11949
  });
11859
11950
  const steps = ordered.map((entry) => ({
11860
11951
  order: 0,