@hublo/sentinel 1.7.0-alpha.2 → 1.7.0-alpha.21

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 (57) hide show
  1. package/README.md +1 -0
  2. package/dist/bin/sentinel.js +45 -84
  3. package/dist/{chunk-THTXP2QU.js → chunk-BBNABWZ6.js} +5 -6
  4. package/dist/chunk-BBNABWZ6.js.map +1 -0
  5. package/dist/{chunk-DLGBRLUU.js → chunk-EESVRILJ.js} +3 -16
  6. package/dist/chunk-EESVRILJ.js.map +1 -0
  7. package/dist/{chunk-4YQXLPJ5.js → chunk-J2RMARWP.js} +2 -2
  8. package/dist/chunk-PXTU5MPW.js +9 -0
  9. package/dist/chunk-PXTU5MPW.js.map +1 -0
  10. package/dist/{chunk-EETHWJBF.js → chunk-RI7R3S3T.js} +6835 -5310
  11. package/dist/{chunk-LNFGVGLE.js → chunk-SWWQ7X7B.js} +11 -23
  12. package/dist/{chunk-LNFGVGLE.js.map → chunk-SWWQ7X7B.js.map} +1 -1
  13. package/dist/{chunk-Z3JI7ZWX.js → chunk-UVXXEAHU.js} +231 -196
  14. package/dist/{chunk-ZNANJEMK.js → chunk-XTBHIKFG.js} +30 -16
  15. package/dist/chunk-XTBHIKFG.js.map +1 -0
  16. package/dist/chunk-XYOIXC6A.js +126 -0
  17. package/dist/chunk-XYOIXC6A.js.map +1 -0
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +6 -6
  20. package/dist/roles/build/nest/toolchain.d.ts +1 -1
  21. package/dist/roles/build/nest/toolchain.js +2 -6
  22. package/dist/roles/build/nest/toolchain.js.map +1 -1
  23. package/dist/roles/code-churn/config.d.ts +92 -0
  24. package/dist/roles/code-churn/config.js +10 -0
  25. package/dist/roles/code-churn/config.js.map +1 -0
  26. package/dist/roles/static-analysis/config.js +2 -1
  27. package/dist/roles/test/nest/toolchain.d.ts +1 -1
  28. package/dist/roles/test/nest/toolchain.js +2 -3
  29. package/dist/roles/test/nest/toolchain.js.map +1 -1
  30. package/dist/roles/test/react/toolchain.js +2 -3
  31. package/dist/roles/test/react/toolchain.js.map +1 -1
  32. package/dist/roles/test/setup/jest-parity.js +2 -2
  33. package/dist/roles/test/setup/workspace-entry.js +2 -2
  34. package/dist/roles/test/shared-test-config.d.ts +1 -1
  35. package/dist/roles/test/shared-test-config.js +2 -3
  36. package/dist/tsconfig/nest.json +1 -10
  37. package/dist/tsconfig/node.json +1 -11
  38. package/dist/tsconfig/react.json +0 -3
  39. package/dist/{tsconfig-aliases-C_PxuZni.d.ts → tsconfig-aliases-Ce6axdJ4.d.ts} +2 -17
  40. package/dist/{validate-LRHF63AW.js → validate-YCTNTNFT.js} +2 -4
  41. package/docs/build-adoption.md +0 -7
  42. package/docs/code-churn-adoption.md +237 -0
  43. package/docs/static-analysis-adoption.md +1 -1
  44. package/docs/static-analysis-study.md +49 -10
  45. package/docs/test-adoption.md +1 -8
  46. package/docs/typescript-adoption.md +13 -52
  47. package/docs/typescript-traces.md +215 -3
  48. package/package.json +5 -4
  49. package/dist/chunk-4UUL4SEW.js +0 -50
  50. package/dist/chunk-DLGBRLUU.js.map +0 -1
  51. package/dist/chunk-H4HAFJFZ.js +0 -79
  52. package/dist/chunk-H4HAFJFZ.js.map +0 -1
  53. package/dist/chunk-THTXP2QU.js.map +0 -1
  54. package/dist/chunk-ZNANJEMK.js.map +0 -1
  55. package/dist/migrate-NI33SXZD.js +0 -517
  56. package/dist/tsconfig/legacy.json +0 -21
  57. /package/dist/{chunk-4YQXLPJ5.js.map → chunk-J2RMARWP.js.map} +0 -0
@@ -0,0 +1,237 @@
1
+ # Code churn adoption cheat sheet
2
+
3
+ A quick reference for adopting the sentinel `code-churn` role on a module, for reading its figure,
4
+ and for moving a setting in `code-churn.config.mjs` (HUB-46818, issue #98).
5
+
6
+ **What it measures.** Of the lines a module **added** in a period, the share **rewritten or
7
+ deleted within 21 days** of being written: code churn as
8
+ [Sourcegraph](https://sourcegraph.com/blog/code-churn) and
9
+ [DevStats](https://www.devstats.com/glossary/code-churn) define it. A line rewritten days after it
10
+ landed is work done twice.
11
+
12
+ ```
13
+ code churn % = lines added in the period and removed within 21 days / lines added in the period
14
+ ```
15
+
16
+ **It reads the git history and nothing else**: no build, no test run, no network. The static
17
+ analysis role answers what the code is today; this one answers how it got there.
18
+
19
+ **It reports and never fails a run.** No threshold, no gate: a churn figure is a trend.
20
+
21
+ ## Adopt a module in two steps
22
+
23
+ Run from the **module's own directory**. You do not need to install sentinel first.
24
+
25
+ ```bash
26
+ # 1. write the module's config + the pinned devDependency
27
+ cd apps/.../<module>
28
+ npx --yes @hublo/sentinel@<version> --init --code-churn
29
+
30
+ # 2. fetch what step 1 declared
31
+ pnpm install
32
+ ```
33
+
34
+ `--init` writes `code-churn.config.mjs`, adds the three scripts below and the `code-churn` nx
35
+ target to the module's `package.json`, and pins `@hublo/sentinel` into its `devDependencies`. A
36
+ module with no file the role measures is skipped by name. An existing `code-churn.config.mjs` is
37
+ the team's and is never rewritten by a re-init.
38
+
39
+ **Adopt first, then the history is read.** On a module that has not adopted, `--run` counts the
40
+ files it would measure and says how to adopt, without reading the history. A bare `sentinel --run`
41
+ sweeps every role over every module, 441 on the monorepo: a `git log` for each of them, nobody
42
+ having asked, is what this avoids.
43
+
44
+ ## Everyday use
45
+
46
+ ```bash
47
+ pnpm run code-churn # the figure and the five most rewritten files, in your terminal
48
+ pnpm run code-churn:json # code-churn-report/code-churn.json, for a machine
49
+ pnpm run code-churn:html # code-churn-report/code-churn.html, every file, for a reader
50
+ ```
51
+
52
+ Or without the scripts:
53
+
54
+ ```bash
55
+ sentinel --run --code-churn # same as the first script
56
+ sentinel --run --code-churn --output markdown # code-churn-report/code-churn.md, the pull-request recap
57
+ sentinel --inspect --code-churn --json # every setting, without reading the history
58
+ ```
59
+
60
+ The console, on `apps/nest/microservices/planning-parameter` (hublo/monorepo `main` f12da701121):
61
+
62
+ ```
63
+ code churn 4.2%: 405 of the 9750 line(s) added from 2026-07-28 to 2026-10-26 were rewritten or deleted within 21 days (123 commit(s) of origin/main up to f12da701121, 1 of them skipped as touching more than 100 files of the module).
64
+ 100% 78/78 src/team-sequence-parameter/business-logic/use-cases/cut-slots-at-half-day-hour.ts (deleted)
65
+ 16.9% 48/284 src/team-sequence-assignment/business-logic/use-cases/update-team-sequence-assignment-period.use-case.ts
66
+ ```
67
+
68
+ ## What it reads
69
+
70
+ | Point | How |
71
+ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
72
+ | Which history | **main's**, `--first-parent`, up to the merge base of `HEAD` and `NX_BASE` (CI) or `origin/main` (elsewhere). The same commit locally and in CI, so a figure seen in CI is the one you get on your machine. Your branch's own commits are not main's yet and are not read |
73
+ | A merge | read as everything it brought (`--diff-merges=first-parent`). What a pull request rewrote before merging is not seen: what is measured is what main received |
74
+ | Which period | the lines written in the 90 days that end 21 days before the newest commit read, so every counted line has had its full window |
75
+ | Which files | `src` when the module has one, the module otherwise (the static analysis perimeter), then the role's `include`; tests, declarations and generated files left out |
76
+ | A rename | the file's lines are carried to its new name (`-M`) |
77
+ | A sweep | a commit touching more than 100 files **of the module** is not counted: neither its lines as added, nor what it removes as rework |
78
+
79
+ When git cannot answer, the run **fails and says why**, never an empty figure: a shallow clone
80
+ (`fetch-depth: 0` in CI, `git fetch --unshallow` locally), no `origin/main` (`git fetch origin
81
+ main`), a module outside git.
82
+
83
+ ## How to read the figure
84
+
85
+ Every report places the figure in a **band**, calibrated on the monorepo's own modules, and says
86
+ what the band means. A band places the figure; it never says whether the code is good. A module
87
+ compares best with itself over time, measured with the same settings.
88
+
89
+ | When | Band | What the reports say |
90
+ | ----------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
91
+ | under 500 lines added in the period | little activity | the counts, no percentage: a figure over a few lines is noise. The files table still shows what changed, how often and why |
92
+ | under 3% | low | among the lowest quarter of the modules the levels were calibrated on |
93
+ | 3 to 11% | usual | within the usual range |
94
+ | over 11% | above | above three quarters of the modules; the files that carry it lead the table |
95
+ | over 16% | worth a look | above 90% of the modules; read the kinds of change: mostly `feat`, the specification moves; mostly `fix`, the code is corrected after it landed |
96
+
97
+ The levels are the 25th, 75th and 90th percentiles (3.1, 11.4 and 15.9%, rounded down) of the 36
98
+ sentinel modules of `main` f12da701121 that added at least 500 lines from 2026-07-28 to
99
+ 2026-10-26; 77 of the 113 added fewer. Vendor figures (LinearB under 3% "elite" and over 8% "needs
100
+ focus", EM Tools 15 to 25% "healthy", GitClear) count other things under the same name: LinearB
101
+ counts CHANGED lines whose previous version is under 21 days old, over all branches. Applied as
102
+ they are, LinearB's bands would put 18 of those 36 modules in alert, so none is applied.
103
+
104
+ Measured on hublo/monorepo `main` f12da701121, period 2026-07-28 to 2026-10-26:
105
+
106
+ | Module | Churn | Added | Rewritten | Commits read | Skipped as sweeps |
107
+ | -------------------------------------------- | ----: | ------: | --------: | -----------: | ----------------: |
108
+ | `apps/nest/microservices/planning-parameter` | 4.2% | 9 750 | 405 | 123 | 1 |
109
+ | `apps/nest/microservices/recruitment` | 7.7% | 44 798 | 3 429 | 344 | 3 |
110
+ | `apps/front/host-admin` | 12.1% | 185 650 | 22 546 | 1 262 | 14 |
111
+
112
+ The host-admin row leaves out `src/routeTree.gen.ts`, TanStack Router's generated route tree,
113
+ which the `*.gen.*` ignore added on 2026-11-17 (187 639 and 22 615 before it).
114
+
115
+ ## What the reports show
116
+
117
+ `code-churn.html` stays on one subject: how the module's code CHANGES. Code churn is a symptom of
118
+ design and of instability, and the page reads it from the history; what the code IS today
119
+ (complexity, duplication, dead code, import coupling) is static analysis's page.
120
+
121
+ It opens on one plain sentence and three cards: the figure and its band; the pull requests of the
122
+ period by kind of change (`feat`, `fix`, `refactor`, other, read from each title); and which kind
123
+ rewrote the lines. Then two tabs, and a **Help** button in the banner.
124
+
125
+ **Code churn.** Every file the period changed, sortable, searchable, filterable by tag and
126
+ paginated by 50, every column with a "?":
127
+
128
+ | Column | What it says |
129
+ | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
130
+ | Code churn, rewritten / added | how much of the code the file gained was taken back within 21 days |
131
+ | Changes, feat / fix / refactor / other | how many merged pull requests changed it, and of what kind: many `fix`, corrected after it lands; many `feat`, its requirement keeps moving |
132
+ | Hotspot | how often it changes and how complex it is, together, 0 to 1, relative to this module; tagged "hotspot" only with a complexity over 10 too |
133
+ | Changes with | the file it changes with most often in the same pull requests ("13 of 18"), the next nine under "+ N more": the dependency git sees and the import graph does not (Gall et al., 1998; D'Ambros, Lanza and Robbes, 2009) |
134
+
135
+ On `apps/nest/microservices/regulation-storage` (25.8%, worth a look), the 960 rewritten lines
136
+ split into 612 by one `fix` four days after the module was ported, 322 by `feat`: its rework is a
137
+ correction right after delivery, not a moving specification.
138
+
139
+ **Settings.** The settings the run used and the bands.
140
+
141
+ **Help.** What code churn is and why it matters, the band, the kinds of change, each column, how
142
+ to put the page beside static analysis (`pnpm exec sentinel --run --static-analysis --output
143
+ html`), what the figures do not say and the sources. Every part comes with an example taken from
144
+ the module itself.
145
+
146
+ The hotspot score needs a complexity, measured by the run with static analysis's own pass, for
147
+ every file. Nothing runs the module's tests: test coverage was tried and removed, since it needs
148
+ the tests to run (minutes on a large module, a database for nest's integration suites). Import
149
+ coupling, centrality and fix density were tried too, and left to the json: two reviewers read the
150
+ extra tab as "nothing new", and a second subject on the page lost the first.
151
+
152
+ ## How others read code churn
153
+
154
+ No large company publishes code churn as a productivity measure. Research supports it as a
155
+ **risk signal on a file or a module**, read over time and beside other figures. So this role
156
+ reports it per module, never per person, and never as a target.
157
+
158
+ | Who | Their reading | What this role takes from it |
159
+ | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
160
+ | Nagappan and Ball, Microsoft Research, ICSE 2005 ([paper](https://www.st.cs.uni-saarland.de/edu/recommendation-systems/papers/ICSE05Churn.pdf)) | On Windows Server 2003, RELATIVE churn (normalised by size and time) predicts defect density; absolute churn does not | A ratio per module, not a count of lines |
161
+ | Shin, Meneely, Williams, Osborne, IEEE TSE 2011 ([paper](https://ieeexplore.ieee.org/document/5560680)) | Complexity, churn and developer activity together find over 80% of the vulnerable files of Firefox and the RHEL kernel | Churn is strongest crossed with another figure, such as static analysis's complexity |
162
+ | Google, _Software Engineering at Google_, ch. 7 ([chapter](https://abseil.io/resources/swe-book/html/ch07.html)) | Lines of code are not a productivity measure; goals first, then signals, then metrics | Never presented as productivity |
163
+ | SPACE, Forsgren, Storey et al., 2021 ([ACM Queue](https://queue.acm.org/detail.cfm?id=3454124)) | An activity metric is never used alone, nor to reward or penalise a developer | Per module and over time, never per person |
164
+ | DORA, 2024 ([history](https://dora.dev/guides/dora-metrics/history/)) | "Deployment rework rate" counts unplanned DEPLOYMENTS after incidents | A different figure under a similar name: this role does not measure it |
165
+ | Meta, Diff Authoring Time, 2025 ([paper](https://arxiv.org/html/2503.10977v2)) | Measures the time spent authoring a change, because simple line metrics are gamed | The figure describes code, not people |
166
+ | GitClear, vendor ([report](https://www.gitclear.com/coding_on_copilot_data_shows_ais_downward_pressure_on_code_quality)) | The same definition over two weeks, rising with AI coding assistants (153 M lines, 2020 to 2023; their 2024 figure is a projection) | A reason to watch the trend now; a vendor's figure, cited as one |
167
+ | CodeScene, Tornhill, vendor ([hotspots](https://docs.enterprise.codescene.io/versions/4.1.4/guides/technical/hotspots.html)) | A hotspot is change frequency multiplied by complexity | The natural next step: churn beside static analysis's complexity |
168
+ | Vendor benchmarks (EM Tools, LinearB) | EM Tools: 15 to 25% "healthy", no source. LinearB 2026: under 3% "elite", over 8% "needs focus", for changed lines whose previous version is under 21 days old, all branches | Other definitions: never applied. Our bands are our own modules' percentiles |
169
+
170
+ ## Every hypothesis and compromise, in one place
171
+
172
+ Each choice the figure depends on, why it was made, what it costs, and how a module moves it.
173
+ Measured on hublo/monorepo `main` f12da701121 unless said otherwise.
174
+
175
+ | # | Hypothesis or compromise | Why | What it costs, measured | Moved by |
176
+ | --- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------- |
177
+ | 1 | Churn is Sourcegraph's rework: a line removed within 21 days of being written | A published definition a reader can check, rather than one of ours | The window is a convention: DevStats gives 14 to 21 days | `window.reworkDays` |
178
+ | 2 | The measured lines are those written in the 90 days that end 21 days before the newest commit read | Every counted line has had its full window; a line written yesterday cannot have been rewritten yet | The figure describes work that is three weeks old at least | `window.periodDays` |
179
+ | 3 | Only main's history is read, first-parent, a merge as everything it brought | What a module received is what it carries; the same answer for everyone | Rework inside a branch before it merges is not seen (validation case V4) | not movable |
180
+ | 4 | The read ends at the merge base of `HEAD` and `NX_BASE` / `origin/main` | The same figure in CI and on a developer's machine | A branch's own commits are not in its figure until they merge | not movable |
181
+ | 5 | The history is read only for a module that adopted the role | A bare sweep covers every module; reading history for each one nobody asked about costs a `git log` per module, and a shallow clone would fail them all | A module must adopt before it sees a figure | adopt |
182
+ | 6 | The perimeter is the static analysis one: `src` when it exists, then `include`; tests, declarations and generated files left out | Both roles answer "is my config, are my tests measured" the same way | Code outside `src` in a module that has one is not measured | `include`, `includeTests`, `tests`, `ignore` |
183
+ | 7 | A commit touching more than 100 files OF THE MODULE is a sweep: its lines are replayed, never counted | A formatter run or a mass rename is not work done twice | No count separates a sweep from a large feature. On host-admin the cap skips 14 commits, real features among them: 12.1% with the cap against 12.5% without on `main` f12da701121 (14 of 1 262 commits), 12.1% against 12.6% at 7112443cc41 (14 of 1 271, validation case V5). Across planning-parameter, recruitment and host-admin, the cap moves the figure by at most 0.6 point. Counted in the repository instead, it skipped 40 of 123 commits on planning-parameter (2.5% for 4.2%), which is why it is not | `maxFilesPerCommit` |
184
+ | 8 | The history is read for this module only (`--relative -- .`) | One module's history, not the repository's, at a cost of seconds | A line moved in from another module reads as written at the move | not movable |
185
+ | 9 | A rename is followed when git detects it, at 50% similarity, inside the module | git's own detection, the one every git tool uses | A file renamed AND mostly rewritten in one commit reads as one file deleted and one added: its young lines count as rework | not movable |
186
+ | 10 | Diffs are read with no context (`--unified=0`), with git's default `myers` algorithm, indent heuristic and rename limit pinned on the command line | Every removed and written line is in a hunk header; nothing else is read; a developer's own `diff.algorithm` cannot move the figure | Two blank lines can align differently from a diff with three lines of context: 1 file of 1 492 differs by two lines on each side against PyDriller. `git blame` also reads with no context | not movable |
187
+ | 11 | A line is dated by its commit's committer date, which on main is when it landed | The date main received the line | A commit rebased later carries the date it was rebased | not movable |
188
+ | 12 | A whitespace-only change is a change | It is what git records, and a reformat of the whole module is caught by the sweep cap | Reindenting young lines in a small commit counts as rework | not movable |
189
+ | 13 | Binary files are skipped | They have no lines | none on the modules measured | not movable |
190
+ | 14 | No gate; a band places the figure among the modules the levels were calibrated on | No published level transfers to another definition or codebase; ours are the monorepo's own percentiles | A band reads as a grade if the sentence is skipped; it says where, never how good. Recalibrated by a sweep at each stable release | `levels` |
191
+ | 15 | A shallow clone, no `origin/main`, a module outside git: the run fails | A cut history makes every line look new; an empty figure would be read as no churn | CI needs `fetch-depth: 0`, which the recap workflow sets | not movable |
192
+ | 16 | The nx target is not cached | The figure depends on the history, which nx does not hash | Each run reads the history again: 0.5 s on planning-parameter, 6 s on host-admin | not movable |
193
+ | 17 | The kind of a change is read from the commit subject: a Conventional Commit title, or the branch of a merge commit | Deterministic and readable; commitlint enforces it; 96% of main's 3 175 commits of the period carry one | It is what the author declared, not a proof: a `fix` may correct a behaviour the product asked to change | not movable |
194
+ | 18 | Change coupling counts commits of main, each a merged pull request | A pull request is the unit a team reviews and ships | A large pull request couples everything it touches once; read the count beside the partner. Sweeps are left out | `maxFilesPerCommit` |
195
+ | 19 | Complexity is the McCabe number of a file's most complex function, measured by static analysis's own pass | The measure static analysis and the linters use, now for every file | A file of many simple functions reads as simple | not movable |
196
+ | 20 | Under 500 added lines, no percentage | 77 of the 113 modules are under it, 26 lines in the median, where one rewrite moves the figure by points | A quiet module never shows a band; its files and kinds still show | `levels.minimumAdded` |
197
+
198
+ ## The config file, `code-churn.config.mjs`
199
+
200
+ The shape of `static-analysis.config.mjs`. A setting the module leaves out keeps the role's value;
201
+ a setting it writes **replaces** it, including inside a list, and the reports mark it as
202
+ overridden by this module.
203
+
204
+ | Setting | Default | What it moves |
205
+ | ------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
206
+ | `window.reworkDays` | `21` | how long after a line is written a change to it counts as rework |
207
+ | `window.periodDays` | `90` | how far back the measured lines were written |
208
+ | `maxFilesPerCommit` | `100` | over this many files of the module, a commit is a sweep |
209
+ | `levels` | `{ minimumAdded: 500, low: 3, above: 11, watch: 16 }` | the module's band, and below how many added lines it has none |
210
+ | `include` | `["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,svelte,vue}"]` | the files measured, inside `src` |
211
+ | `includeTests` | `false` | measure the tests too |
212
+ | `tests` | the sql role's list, extended to JavaScript | what counts as a test |
213
+ | `ignore` | `node_modules`, `dist`, `build`, `coverage`, declarations, generated (`*.generated.*`, `*.gen.*`, `generated/`) | never measured |
214
+ | `listed` | `10` | how many files the json row lists |
215
+
216
+ ## How it was validated
217
+
218
+ The figure was recomputed **independently with `git blame`**: for each commit C of the period, the
219
+ code 21 days after C, and how many of C's lines `git blame --first-parent` still finds there. On
220
+ hublo/monorepo `main` f12da701121, commit by commit:
221
+
222
+ | Module | Commits compared | Added | Rewritten | Difference |
223
+ | -------------------------------------------- | ---------------: | ------: | --------: | ---------: |
224
+ | `apps/nest/microservices/planning-parameter` | 66 | 9 547 | 469 | 0 |
225
+ | `apps/nest/microservices/recruitment` | 205 | 44 477 | 3 429 | 0 |
226
+ | `apps/front/host-admin` | 934 | 222 068 | 27 801 | 0 |
227
+
228
+ Set aside on both sides: the (commit, file) pairs where `git blame` follows a newly added file to
229
+ another file deleted in the same commit, since its rename pairing is per path and `git log`'s is
230
+ global (6 pairs and 201 lines on planning-parameter, 1 and 330 on recruitment, 3 and 62 on
231
+ host-admin). The figures above are without the sweep cap, so every commit is compared.
232
+
233
+ The added and removed lines read from the patch were also compared with
234
+ [PyDriller](https://github.com/ishepard/pydriller) 2.6, file by file on the 92 non-merge commits of
235
+ planning-parameter: 1 491 of 1 492 identical. The one left differs by two lines on each side, a
236
+ diff with no context aligning two blank lines differently from one with three; both are valid, and
237
+ `git blame` reads with no context, as this role does.
@@ -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).
@@ -138,17 +138,10 @@ The wall is decorator metadata: Nest resolves a constructor's parameters from
138
138
  ```ts
139
139
  plugins: [decoratorMetadata({ root: here })],
140
140
  resolve: { alias: [{ find: /^jest-mock-extended$/, replacement: 'vitest-mock-extended' },
141
- ...tsconfigAliases(workspaceRoot, { moduleRoot: here })] },
141
+ ...tsconfigAliases(workspaceRoot)] },
142
142
  test: { globals: true, environment: 'node', isolate: true },
143
143
  ```
144
144
 
145
- **The aliases are the module's, read the way tsc reads them.** `tsconfigAliases` follows the
146
- module's own tsconfig chain (`tsconfig.spec.json`, then `tsconfig.app.json`, then `tsconfig.json`), so a module that declares
147
- its own `paths` is tested with the aliases it type-checks with. When the chain declares no `paths`,
148
- it falls back to `tsconfig.base.json`, which is what it always read: a module that still extends
149
- the base sees no change. That fallback is a transition. Once no module extends the base, a module
150
- without `paths` has no aliases, as in tsc. The rules are in `src/shared/tsconfig-paths.ts`. One difference with tsc 7 is deliberate: a `baseUrl` in the chain is honoured, as ts-jest, Vite and TypeScript 5 and 6 read it, so a chain whose `baseUrl` is not the directory of the file declaring `paths` resolves differently at runtime than in the typecheck. None exists in the monorepo today.
151
-
152
145
  **`isolate` stays `true`**, whatever the performance note in Vitest's docs suggests. Jest gives each
153
146
  test file a fresh module registry and `isolate: true` reproduces that. Nest registers metadata as an
154
147
  import SIDE EFFECT, a decorator writing into a catalog when its module loads, so a shared registry
@@ -33,7 +33,7 @@ pnpm install
33
33
  | `--run` | dev, everyday | **yes** (tsc) | executes the check, pass/fail. This is your `typecheck` script. |
34
34
  | `--inspect` | dev, everyday | no (reads config) | the resolved config: preset, target, and which rules are deferred |
35
35
  | `--init` | dev, once to adopt | writes files | the tsconfig stub, the `typecheck` script, the pinned dep, + workspace prep |
36
- | `--migrate` | dev, once per role | writes files | changes an adopted module's setup: `--typescript` detaches it from the base |
36
+ | `--migrate` | planned | not available yet | reserved for changing an already-initialized setup (later ticket) |
37
37
  | `--report` | **deprecated** | — | use `--run --json`: same work, same envelope |
38
38
  | `--status` | **deprecated** | — | use `--inspect`, which absorbed it |
39
39
 
@@ -43,52 +43,13 @@ pnpm install
43
43
  > the two above, because they answered the same two questions in a different shape. Both still
44
44
  > run and print a notice telling you what to use instead.
45
45
 
46
- **Location** (any verb): from a module dir → that module; from the root → `--module <name>`, `--ci` (affected), or all modules. `--init` and `--migrate` write, so they target one module only.
46
+ **Location** (any verb): from a module dir → that module; from the root → `--module <name>`, `--ci` (affected), or all modules. `--init` writes, so it targets one module only.
47
47
 
48
48
  **Your tsconfig extends exactly one preset.** The options every stack shares are flattened into
49
49
  each published preset at build time, so `@hublo/sentinel/tsconfig/react` is self-contained and
50
50
  there is nothing to stack under it. The shared layer lives in the repo as
51
51
  `src/roles/typescript/presets/shared.json`; it is ours and is never published on its own.
52
52
 
53
- The one addition is `@hublo/sentinel/typescript/legacy`, and it is not a preset: it is the debt
54
- a module carried through `tsconfig.base.json` (the six strict opt-outs, `ignoreDeprecations`,
55
- and for react the decorator flags, `declaration: false` and `types`). Only `--migrate
56
- --typescript` adds it, LEFT of the stack preset where the base was, so the stack preset keeps
57
- winning; `--init` never does, so a new module is born with the full strict set.
58
-
59
- ## Detach a module from `tsconfig.base.json`
60
-
61
- Run from an **adopted** module's directory (its tsconfig extends a sentinel preset), once its
62
- `@hublo/sentinel` is the version that ships `legacy`:
63
-
64
- ```bash
65
- sentinel --migrate --typescript --dry-run # prove it and write nothing
66
- sentinel --migrate --typescript # prove it and keep the result
67
- ```
68
-
69
- It replaces the base in `extends` with `legacy` (when the module has those compromises), keeps
70
- the stack preset, and writes only what depends on the module: `outDir`, `rootDir`, `exclude`,
71
- and the `paths` entries tsc reports having MATCHED (`--traceResolution`), the setup and config
72
- files no tsconfig compiles included. Measured on 113 modules (sentinel#147), that is all that is
73
- left once the presets carry the base's standards.
74
-
75
- It keeps nothing unless tsc agrees, and restores the file otherwise:
76
-
77
- - `--showConfig` of every tsconfig of the folder applies the same options, `paths` aside. Applied,
78
- not printed: the base printed `alwaysStrict`, `allowJs: false` and `isolatedModules`, and the
79
- presets leave them to `strict`, the default and `verbatimModuleSyntax`. Same compilation,
80
- different output, so the comparison derives those options the way tsc does
81
- (`src/roles/typescript/migrate/compare.ts`);
82
- - every module and type reference tsc resolves, file by file, lands on the same file.
83
-
84
- It refuses, and writes nothing, for a module not adopted yet (run `--init --typescript` first), a
85
- tsconfig with comments, and a module whose installed sentinel has no `legacy`. A nested folder
86
- that is a module of its own is named and left to its own run.
87
-
88
- What it does not prove is tsc's view only: the Nx project graph still reads the root base's
89
- `paths`, and esbuild and Vite resolve each file through its nearest tsconfig. The base stays
90
- until every module is detached, and the module's own build, test and lint are its proof.
91
-
92
53
  ## Everyday use (developers)
93
54
 
94
55
  ```bash
@@ -107,17 +68,17 @@ sentinel --inspect --typescript # adoption + conformity coverage
107
68
 
108
69
  ## Options
109
70
 
110
- | Option | What it does |
111
- | ----------------------- | ------------------------------------------------------------------------------------- |
112
- | `--preset <name>` | override detection (`react` / `nest` / `svelte` / `node`); recommended for `--init` |
113
- | `--module <name>` | from the root, scope to one module |
114
- | `--ci` | from the root, only affected modules; non-zero exit on failure |
115
- | `--json` | machine-readable envelope on stdout, for every verb; progress goes to stderr |
116
- | `--max-diagnostics <n>` | cap the diagnostics embedded per module in `--run --json` (`0` = no cap) |
117
- | `--dry-run` | preview what `--init` would write, or prove `--migrate` and restore, changing nothing |
118
- | `--rehearse` | with `--dry-run`: run the autofix passes in a copy and name the source they rewrite |
119
- | `--runner <tool>` | override the default runner |
120
- | `-- <tool options>` | `--run` only, one type named: everything after `--` goes to tsc itself (see below) |
71
+ | Option | What it does |
72
+ | ----------------------- | ----------------------------------------------------------------------------------- |
73
+ | `--preset <name>` | override detection (`react` / `nest` / `svelte` / `node`); recommended for `--init` |
74
+ | `--module <name>` | from the root, scope to one module |
75
+ | `--ci` | from the root, only affected modules; non-zero exit on failure |
76
+ | `--json` | machine-readable envelope on stdout, for every verb; progress goes to stderr |
77
+ | `--max-diagnostics <n>` | cap the diagnostics embedded per module in `--run --json` (`0` = no cap) |
78
+ | `--dry-run` | preview what `--init` would write, changing nothing |
79
+ | `--rehearse` | with `--dry-run`: run the autofix passes in a copy and name the source they rewrite |
80
+ | `--runner <tool>` | override the default runner |
81
+ | `-- <tool options>` | `--run` only, one type named: everything after `--` goes to tsc itself (see below) |
121
82
 
122
83
  ## Measuring a deferred rule
123
84