@hublo/sentinel 1.7.0-alpha.3 → 1.7.0-alpha.30

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.
Files changed (48) hide show
  1. package/README.md +3 -0
  2. package/dist/bin/sentinel.js +88 -81
  3. package/dist/{chunk-P6KTBQ2Q.js → chunk-2PRJJRJI.js} +24 -15
  4. package/dist/{chunk-THTXP2QU.js → chunk-APBEGLRI.js} +6 -6
  5. package/dist/chunk-APBEGLRI.js.map +1 -0
  6. package/dist/{chunk-F6ART7RH.js → chunk-HYXFUUF5.js} +14959 -6817
  7. package/dist/{chunk-4YQXLPJ5.js → chunk-LVY5NPOC.js} +2 -2
  8. package/dist/chunk-PXTU5MPW.js +9 -0
  9. package/dist/chunk-PXTU5MPW.js.map +1 -0
  10. package/dist/chunk-SHF46ALB.js +190 -0
  11. package/dist/chunk-SHF46ALB.js.map +1 -0
  12. package/dist/chunk-TMVKYXZ3.js +18 -0
  13. package/dist/chunk-TMVKYXZ3.js.map +1 -0
  14. package/dist/chunk-XYOIXC6A.js +126 -0
  15. package/dist/chunk-XYOIXC6A.js.map +1 -0
  16. package/dist/{chunk-ZNANJEMK.js → chunk-YUZB4LRJ.js} +35 -16
  17. package/dist/chunk-YUZB4LRJ.js.map +1 -0
  18. package/dist/chunk-ZZMYV576.js +297 -0
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +10 -5
  21. package/dist/{migrate-NWQ3LYER.js → migrate-X7PB2X7R.js} +237 -228
  22. package/dist/roles/arch/config.d.ts +25 -0
  23. package/dist/roles/arch/config.js +8 -0
  24. package/dist/roles/arch/config.js.map +1 -0
  25. package/dist/roles/build/nest/toolchain.js +3 -3
  26. package/dist/roles/code-churn/config.d.ts +92 -0
  27. package/dist/roles/code-churn/config.js +10 -0
  28. package/dist/roles/code-churn/config.js.map +1 -0
  29. package/dist/roles/sql/config.d.ts +68 -0
  30. package/dist/roles/sql/config.js +8 -0
  31. package/dist/roles/sql/config.js.map +1 -0
  32. package/dist/roles/static-analysis/config.js +2 -1
  33. package/dist/roles/test/setup/file-boundary.js +3 -3
  34. package/dist/roles/test/setup/jest-parity.js +4 -4
  35. package/dist/roles/test/setup/workspace-entry.js +2 -2
  36. package/dist/{validate-4V3EGTXN.js → validate-4GMB32V7.js} +2 -2
  37. package/docs/arch-adoption.md +201 -0
  38. package/docs/code-churn-adoption.md +237 -0
  39. package/docs/sql-adoption.md +672 -0
  40. package/docs/static-analysis-adoption.md +1 -1
  41. package/docs/static-analysis-study.md +49 -10
  42. package/docs/typescript-adoption.md +47 -6
  43. package/docs/typescript-traces.md +546 -6
  44. package/docs/using-sentinel.md +4 -2
  45. package/package.json +17 -1
  46. package/dist/chunk-THTXP2QU.js.map +0 -1
  47. package/dist/chunk-ZNANJEMK.js.map +0 -1
  48. /package/dist/{chunk-4YQXLPJ5.js.map → chunk-LVY5NPOC.js.map} +0 -0
@@ -25,7 +25,7 @@ pnpm install
25
25
  added the three `static-analysis` scripts and static-analysis.config.mjs; declare
26
26
  this module's entry points there, everything else comes from the role
27
27
  ignored static-analysis-report/ in the root .gitignore
28
- run `pnpm install` to apply the workspace changes
28
+ run `pnpm install` to apply the workspace changes and this module's new dependencies, and commit pnpm-lock.yaml if it changed
29
29
  ```
30
30
 
31
31
  ⚠️ **If your module has a `project.json` and no `package.json`, `--init` creates one.** Measured on
@@ -44,7 +44,9 @@ the same idea sometimes carries two names.
44
44
  ⚠️ Not every symbol above is produced in the first version. `A`, `D`, `H` and `LCOM4` are not:
45
45
  `A` is not graph-derivable (section 8), and `LCOM4` was dropped because the front end is functional,
46
46
  which leaves it a nest-only metric to be re-examined. The Lakos family, visibility, churn and
47
- entropy are the second version. What the first one produces is listed in section 7.
47
+ entropy were planned as the second version; measured, they became something else, and section 11
48
+ says what and why: churn is a role of its own (`code-churn`), coupling and visibility were already
49
+ here, Lakos and entropy were not added. What the first version produces is listed in section 7.
48
50
 
49
51
  Two conventions worth stating because they bite. A **percentile** is written `p95` and means the
50
52
  value below which 95% of the measured population sits. A **rank correlation** is Spearman's: 1
@@ -253,15 +255,15 @@ that validates the categories now. Two of its cells are already filled, and both
253
255
  **A category is sound when its metrics lead to the same action.** Otherwise it is a filing
254
256
  cabinet, not a tool.
255
257
 
256
- | category | the question | contains | the action |
257
- | ---------------- | ------------------------------- | -------------------------------------------- | ------------------- |
258
- | **Impact** | what does it break | Ca, Ce, DC, I, later A and D | none. It **orders** |
259
- | **Activity** | how much does it move | churn, entropy, authors, co-change | none. It **orders** |
260
- | **Cycles** | what bites its own tail | SCCs, System Cyclicality | move one import |
261
- | **Modularity** | is the split right | Q, density per module | re-cut, move a file |
262
- | **Complexity** | is it readable | CX per file and per folder, Halstead, MI | read it, then split |
263
- | **Duplication** | does it already exist elsewhere | clones, duplicated lines, share per language | extract, or accept |
264
- | **Reachability** | is any of it still run | dead code, with a confidence per finding | delete, or declare |
258
+ | category | the question | contains | the action |
259
+ | ---------------- | ------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------- |
260
+ | **Impact** | what does it break | Ca, Ce, DC, I, later A and D | none. It **orders** |
261
+ | **Activity** | how much does it move | churn, entropy, authors, co-change (section 11: churn is the `code-churn` role, entropy dropped) | none. It **orders** |
262
+ | **Cycles** | what bites its own tail | SCCs, System Cyclicality | move one import |
263
+ | **Modularity** | is the split right | Q, density per module | re-cut, move a file |
264
+ | **Complexity** | is it readable | CX per file and per folder, Halstead, MI | read it, then split |
265
+ | **Duplication** | does it already exist elsewhere | clones, duplicated lines, share per language | extract, or accept |
266
+ | **Reachability** | is any of it still run | dead code, with a confidence per finding | delete, or declare |
265
267
 
266
268
  Cycles is separate from Impact although both come from the graph, because the action differs: a
267
269
  cycle is fixed, a high centrality is not. **Impact × Activity** are the two terms of risk and
@@ -1622,3 +1624,40 @@ All three are now tests.
1622
1624
  - CodeScene, code health and hotspots: <https://codescene.io/docs/guides/technical/code-health.html>
1623
1625
  - Sonar, Clean as You Code: <https://www.sonarsource.com/blog/clean-as-you-code/>
1624
1626
  - Martin's package metrics: <https://en.wikipedia.org/wiki/Software_package_metrics>
1627
+
1628
+ ---
1629
+
1630
+ ## 11. What the second version became (HUB-46818, #98)
1631
+
1632
+ The second version listed in section 0 was the Lakos family, visibility, churn and entropy. Before
1633
+ writing any of it, each was measured on hublo/monorepo: its formula against what this role
1634
+ already computes, its redundancy with the figures already printed, and whether it ranks the files
1635
+ that were fixed afterwards. Metrics taken at 2c90e36a70d (2026-05-15), fixes counted from then to
1636
+ `main`, 20 742 files, Spearman correlations, the partial one controlling for file size.
1637
+
1638
+ | Planned | Decision | Why, measured |
1639
+ | ------------------------------------------------------------ | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1640
+ | Coupling: degree centrality, `Ca`, `Ce`, `I` | **Already here** | `graph/scan.ts` computes density, Louvain modularity `Q`, degree centrality and `Ca`/`Ce`/`I` per file. Nothing to add |
1641
+ | Visibility (MacCormack fan-in and fan-out, propagation cost) | **Not added** | Propagation cost is exactly `RACD` (identical figures). Per file, the outgoing closure ranks like `Ce` (ρ .919) and the incoming one like `Ca` (ρ .781): the closures add little to a ranking the report already prints |
1642
+ | Lakos `CCD`, `ACD`, `RACD`, `NCCD` | **Not added** | `RACD` falls with module size (ρ −.725 with N) and `NCCD` follows edges per file (ρ .853); `NCCD` is above 1 on 56 of the 110 modules of 20 files or more. Against fixes per KLOC, on 51 modules, no signal. Per file, beyond size, partial ρ .04 to .09 |
1643
+ | Churn | **Shipped, as the `code-churn` role** | It reads the history, not the tree, so it is a role of its own with its own adoption ([`code-churn-adoption.md`](code-churn-adoption.md)). Beyond size it is the strongest of the candidates (partial ρ about .13 to .18 against later fixes), and it is nearly independent of the import graph (ρ .09 with the incoming closure), so it says something the graph does not |
1644
+ | Change entropy (Hassan) | **Dropped** | Its file model ranks files like the commit count it is built from, and its decayed variant adds nothing: what it says, churn says |
1645
+
1646
+ The definition shipped is the rework one (Sourcegraph, DevStats): of the lines added in a period,
1647
+ the share rewritten or deleted within 21 days. The commit count used in the measurements above is
1648
+ a related but different churn (Nagappan and Ball's family); it decided that history was worth
1649
+ reading, and the rework definition decided what the figure says to a reader.
1650
+
1651
+ Four traps the measurements found, each handled by the role and written in its cheat sheet:
1652
+
1653
+ | Trap | Measured | What the role does |
1654
+ | --------------------------- | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
1655
+ | Merge commits counted twice | without `--first-parent`, +74% commits on recruitment, +137% on host-admin | main's first-parent history only, a merge read as everything it brought |
1656
+ | Sweeps | 3.5% of changesets touch more than 100 files and carry 33% of the file changes | a commit over 100 files OF THE MODULE is not counted (0.5 point on host-admin) |
1657
+ | Renames across modules | 1 487 in 12 months | the history is read per module: a line moved in reads as new, said in the caveat |
1658
+ | A pace that changed | about 250 changesets a month, then over 1 000 from 2026-06 | a fixed period of lines (90 days), each followed for the same 21 days, rather than a count of commits |
1659
+
1660
+ Measured and kept for later, not shipped: co-change between files (61% of the strong pairs have
1661
+ no import link at all, a candidate signal of hidden coupling) and test priority (central files
1662
+ without a test of their own). The second needs real coverage: the proxy "a test imports the file"
1663
+ ranked like line coverage on one module (ρ .888) and not on host-admin (ρ .091).
@@ -72,21 +72,53 @@ and the `paths` entries tsc reports having MATCHED (`--traceResolution`), the se
72
72
  files no tsconfig compiles included. Measured on 113 modules (sentinel#147), that is all that is
73
73
  left once the presets carry the base's standards.
74
74
 
75
- It keeps nothing unless tsc agrees, and restores the file otherwise:
75
+ It is all or nothing. Every tsconfig of the module that extends the base is proved first, each
76
+ rewritten and put back in turn, and the module's files are written only when tsc agrees on every
77
+ one of them, on both:
76
78
 
77
79
  - `--showConfig` of every tsconfig of the folder applies the same options, `paths` aside. Applied,
78
80
  not printed: the base printed `alwaysStrict`, `allowJs: false` and `isolatedModules`, and the
79
81
  presets leave them to `strict`, the default and `verbatimModuleSyntax`. Same compilation,
80
82
  different output, so the comparison derives those options the way tsc does
81
- (`src/roles/typescript/migrate/compare.ts`);
83
+ (`src/roles/typescript/compare.ts`);
82
84
  - every module and type reference tsc resolves, file by file, lands on the same file.
83
85
 
84
86
  A kept tsconfig is then formatted with the style the module states (its `.oxfmtrc.json`, else
85
87
  the workspace's Prettier), the same rule `--init --test` follows: whitespace only, after tsc agreed.
86
88
 
87
- It refuses, and writes nothing, for a module not adopted yet (run `--init --typescript` first), a
88
- tsconfig with comments, and a module whose installed sentinel has no `legacy`. A nested folder
89
- that is a module of its own is named and left to its own run.
89
+ It refuses, and writes nothing, for:
90
+
91
+ - a module not adopted yet (run `--init --typescript` first);
92
+ - a module with one tsconfig that extends the base without a sentinel preset, even when the others
93
+ are proved (`partly-adopted`). On the monorepo that is `tsconfig.acceptance.json` in `contract`
94
+ and `network`. Detaching the rest would leave the module compiling two ways, still on the base.
95
+ `--init` adopts the main tsconfig only, so the fix is to add the stack preset to that file's
96
+ `extends`, or to make it extend the adopted tsconfig;
97
+ - a tsconfig with comments;
98
+ - a module whose installed sentinel has no `legacy`, or resolves it from another install than its
99
+ stack preset;
100
+ - a tsconfig tsc cannot read (`error`, naming what tsc said), or a program that compiles files and
101
+ whose trace yields no resolution at all (`no-trace`): every program resolves at least its type
102
+ references, the smallest of the monorepo's 111 traces 447, so none means the trace was not read.
103
+ A solution file (`files: []`, `include` absent or `[]`) compiles nothing and is not traced: its
104
+ programs are, through the tsconfigs that extend it. A program tsc lists no file for (a spec
105
+ tsconfig in a library with no tests) is not a `no-trace` either: its trace must stay empty
106
+ after the rewrite.
107
+
108
+ A nested folder that is a module of its own is named and left to its own run. Each refusal carries a
109
+ `refusal` code in `--json` (`not-adopted`, `partly-adopted`, `comments`, `no-legacy`,
110
+ `several-installs`, `no-trace`, `disagrees`, `error`).
111
+
112
+ `--dry-run` writes nothing either, but each tsconfig is rewritten on disk for the time of its proof.
113
+ A watcher (the Nx daemon, tsserver, a dev server) can see it come and go.
114
+
115
+ Once migrated, `--inspect` lists the compromises the module takes from `legacy` under
116
+ `inherited compromises (debt to remove)`: the options the stack preset does not set and the module
117
+ does not set itself, the ones that apply, each against the value the standard would apply
118
+ (`noImplicitAny — false, where the standard says true, inherited from …/legacy`). `--json` carries
119
+ the same lists as data: `standardOverrides` and `legacyCompromises`, each item with `rule`,
120
+ `value` and `standard`. The debt left the base, and stays
121
+ visible module by module until the module removes the `legacy` line.
90
122
 
91
123
  What it does not prove is tsc's view only: the Nx project graph still reads the root base's
92
124
  `paths`, and esbuild and Vite resolve each file through its nearest tsconfig. The base stays
@@ -117,7 +149,7 @@ sentinel --inspect --typescript # adoption + conformity coverage
117
149
  | `--ci` | from the root, only affected modules; non-zero exit on failure |
118
150
  | `--json` | machine-readable envelope on stdout, for every verb; progress goes to stderr |
119
151
  | `--max-diagnostics <n>` | cap the diagnostics embedded per module in `--run --json` (`0` = no cap) |
120
- | `--dry-run` | preview what `--init` would write, or prove `--migrate` and restore, changing nothing |
152
+ | `--dry-run` | preview what `--init` would write, or prove `--migrate` and write nothing (see above) |
121
153
  | `--rehearse` | with `--dry-run`: run the autofix passes in a copy and name the source they rewrite |
122
154
  | `--runner <tool>` | override the default runner |
123
155
  | `-- <tool options>` | `--run` only, one type named: everything after `--` goes to tsc itself (see below) |
@@ -225,3 +257,12 @@ it would hand it to the workspace tsconfig this module extends
225
257
  ```
226
258
 
227
259
  It is not reported as drift by `--inspect` either, so a module that legitimately overrides the base does not read as non-conformant forever.
260
+
261
+ Not drift, but not hidden either: `--inspect` lists it under `differs from the repo standard`,
262
+ with both values. An option a preset took over from the base (`fromBase`) and that the module
263
+ sets to another value is this module departing from the standard, and that is worth seeing:
264
+
265
+ ```
266
+ differs from the repo standard (kept by --init, not drift):
267
+ • verbatimModuleSyntax — false, where the nest preset says true
268
+ ```