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

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 (70) hide show
  1. package/README.md +4 -0
  2. package/dist/bin/sentinel.js +95 -82
  3. package/dist/chunk-2DUG6GVU.js +19301 -0
  4. package/dist/chunk-F5WISUN3.js +17 -0
  5. package/dist/chunk-F5WISUN3.js.map +1 -0
  6. package/dist/{chunk-P6KTBQ2Q.js → chunk-FZLUCPST.js} +24 -15
  7. package/dist/{chunk-ZNANJEMK.js → chunk-KKHKRY7P.js} +40 -16
  8. package/dist/chunk-KKHKRY7P.js.map +1 -0
  9. package/dist/chunk-NE3IEJBN.js +59 -0
  10. package/dist/chunk-NE3IEJBN.js.map +1 -0
  11. package/dist/chunk-NGLEGAEN.js +190 -0
  12. package/dist/chunk-NGLEGAEN.js.map +1 -0
  13. package/dist/chunk-PXTU5MPW.js +9 -0
  14. package/dist/chunk-PXTU5MPW.js.map +1 -0
  15. package/dist/{chunk-4YQXLPJ5.js → chunk-QMIJ4ZGJ.js} +2 -2
  16. package/dist/chunk-TMVKYXZ3.js +18 -0
  17. package/dist/chunk-TMVKYXZ3.js.map +1 -0
  18. package/dist/chunk-U7G2Y6YC.js +15 -0
  19. package/dist/chunk-U7G2Y6YC.js.map +1 -0
  20. package/dist/chunk-VWASE6NN.js +34 -0
  21. package/dist/chunk-VWASE6NN.js.map +1 -0
  22. package/dist/{chunk-THTXP2QU.js → chunk-XMAXE2Q2.js} +10 -7
  23. package/dist/chunk-XMAXE2Q2.js.map +1 -0
  24. package/dist/chunk-XYOIXC6A.js +126 -0
  25. package/dist/chunk-XYOIXC6A.js.map +1 -0
  26. package/dist/chunk-ZZMYV576.js +297 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +14 -5
  29. package/dist/{migrate-NWQ3LYER.js → migrate-X7PB2X7R.js} +237 -228
  30. package/dist/roles/arch/config.d.ts +25 -0
  31. package/dist/roles/arch/config.js +8 -0
  32. package/dist/roles/arch/config.js.map +1 -0
  33. package/dist/roles/build/nest/toolchain.js +3 -3
  34. package/dist/roles/code-churn/config.d.ts +92 -0
  35. package/dist/roles/code-churn/config.js +10 -0
  36. package/dist/roles/code-churn/config.js.map +1 -0
  37. package/dist/roles/runtime-analysis/config.d.ts +97 -0
  38. package/dist/roles/runtime-analysis/config.js +10 -0
  39. package/dist/roles/runtime-analysis/config.js.map +1 -0
  40. package/dist/roles/runtime-analysis/gateway.d.ts +2 -0
  41. package/dist/roles/runtime-analysis/gateway.js +89 -0
  42. package/dist/roles/runtime-analysis/gateway.js.map +1 -0
  43. package/dist/roles/runtime-analysis/mock-api.d.ts +2 -0
  44. package/dist/roles/runtime-analysis/mock-api.js +43 -0
  45. package/dist/roles/runtime-analysis/mock-api.js.map +1 -0
  46. package/dist/roles/sql/config.d.ts +68 -0
  47. package/dist/roles/sql/config.js +8 -0
  48. package/dist/roles/sql/config.js.map +1 -0
  49. package/dist/roles/static-analysis/config.js +2 -1
  50. package/dist/roles/test/setup/file-boundary.js +3 -3
  51. package/dist/roles/test/setup/jest-parity.js +4 -4
  52. package/dist/roles/test/setup/workspace-entry.js +2 -2
  53. package/dist/{validate-4V3EGTXN.js → validate-GTBRD2M4.js} +2 -2
  54. package/docs/arch-adoption.md +201 -0
  55. package/docs/code-churn-adoption.md +237 -0
  56. package/docs/runtime-analysis-adoption.md +198 -0
  57. package/docs/sql-adoption.md +598 -0
  58. package/docs/static-analysis-adoption.md +1 -1
  59. package/docs/static-analysis-study.md +49 -10
  60. package/docs/typescript-adoption.md +47 -6
  61. package/docs/typescript-traces.md +512 -8
  62. package/docs/using-sentinel.md +4 -2
  63. package/package.json +25 -2
  64. package/runtime-analysis-deps/load.mjs +6 -0
  65. package/runtime-analysis-deps/package-lock.json +1766 -0
  66. package/runtime-analysis-deps/package.json +11 -0
  67. package/dist/chunk-F6ART7RH.js +0 -9555
  68. package/dist/chunk-THTXP2QU.js.map +0 -1
  69. package/dist/chunk-ZNANJEMK.js.map +0 -1
  70. /package/dist/{chunk-4YQXLPJ5.js.map → chunk-QMIJ4ZGJ.js.map} +0 -0
@@ -0,0 +1,201 @@
1
+ # Architecture check adoption cheat sheet
2
+
3
+ `sentinel --arch` checks a module against an architecture decision of its repository: which
4
+ folder may import which, which names a view may not import, which calls a view may not make. Only
5
+ a violation a branch ADDS to a rule at `error` fails the run: what the module had where the branch
6
+ left main never does, and nothing is recorded to get there.
7
+
8
+ ## Adopt a module in two steps
9
+
10
+ ```bash
11
+ # 1. write the module's config, its scripts and the pinned devDependency
12
+ cd apps/front/host-admin
13
+ npx --yes @hublo/sentinel@<version> --init --arch
14
+
15
+ # 2. fetch what step 1 declared, and commit pnpm-lock.yaml with the rest
16
+ pnpm install
17
+ ```
18
+
19
+ Nothing to choose. The repository's `sentinel.arch.json` says which decision governs this module,
20
+ and `--init` writes:
21
+
22
+ | File | What it holds |
23
+ | ----------------- | ---------------------------------------------------------------------------------------- |
24
+ | `arch.config.mjs` | `defineArch`, and in comments each rule of the decision with its level in this module |
25
+ | `package.json` | the `arch`, `arch:json` and `arch:html` scripts, the nx target, `@hublo/sentinel` pinned |
26
+
27
+ The shape of `static-analysis.config.mjs` and `sql.config.mjs`. An existing `arch.config.mjs` is
28
+ the team's and a re-init never rewrites it. If the map applies no decision to the module, `--init`
29
+ says so and writes nothing. An `arch.config.json` or `arch.baseline.json` left by an earlier beta
30
+ is removed: nothing reads them any more.
31
+
32
+ ## Everyday use
33
+
34
+ ```bash
35
+ pnpm run arch # fails on a violation this branch adds at error
36
+ pnpm run arch:json # arch-report/arch.json, for a machine
37
+ pnpm run arch:html # arch-report/arch.html: each rule, its decision, its status, what to do
38
+ sentinel --run --arch --output markdown # arch-report/arch.md, the pull-request section
39
+ sentinel --inspect --arch # the rule set, and each rule's level here
40
+ ```
41
+
42
+ A run prints the files per role (a role with no file usually means a path with a typo in the
43
+ rule set), what it compared with, then one line per rule, then each NEW violation with its file,
44
+ what it reaches and the section of the decision that forbids it:
45
+
46
+ ```
47
+ architecture ADR 0050: the vertical feature slice is the unit of frontend architecture 5543 files
48
+ compared with origin/main at 310bfc2: only what this branch adds can fail
49
+ ✗ G1 A view or route never calls a query client: fetching goes through a hook. 1 new, 4 known
50
+ src/modules/contracts/components/ArchProbeG1.tsx → @tanstack/react-query#useQuery
51
+ why: RFC #19934, Governance readiness, G1
52
+ ✓ G2a The api layer never imports a view, not even a type. 0 new, 3 known
53
+ ```
54
+
55
+ ## Compared with where the branch left main
56
+
57
+ The module is analysed twice: on the branch (the working tree, uncommitted files included) and at
58
+ the merge base, read from git without touching the checkout. The base is `NX_BASE` in CI and
59
+ `origin/main` elsewhere, as for the sql role. When git cannot say what the base is (no
60
+ `origin/main`, a shallow clone), the run fails and says which command fixes it: comparing with
61
+ nothing would report every violation the module has as new.
62
+
63
+ - A violation is compared by what it is: the rule, the file that breaks it, what it reaches. Not
64
+ by a count, so fixing one and adding another in the same change still fails.
65
+ - A file the branch only moves keeps its violations known, through git's rename detection: a pull
66
+ request reorganising files into feature slices does what the decision asks. Locally, git sees the
67
+ move only once it is staged: move with `git mv`, or `git add` both paths, or the moved file's
68
+ violations read as new until then. CI always sees the commit.
69
+ - A violation the branch removes is gone from the next run, and the report says how many were.
70
+ There is nothing to commit for it.
71
+ - A rule the decision adds is measured on both sides, so the module's existing violations of it
72
+ are known on the day it lands.
73
+ - A file the branch makes unparsable fails the run; one main could not parse either is said, and
74
+ does not fail the branch.
75
+
76
+ ## A rule's level in one module
77
+
78
+ ```js
79
+ // arch.config.mjs
80
+ import { defineArch } from '@hublo/sentinel/arch'
81
+
82
+ export default defineArch({
83
+ root: import.meta.dirname,
84
+ overrides: { severity: { G3: 'warn' } },
85
+ })
86
+ ```
87
+
88
+ `warn` reports without failing, `off` skips the rule. A name that is not a rule of the set is
89
+ refused, so a typo cannot leave a rule at `error` while you believe it is a warning. The level
90
+ comes from the module's config, then the map, then the rule set.
91
+
92
+ ## For the repository: the rules and the map
93
+
94
+ The rules belong to the repository that took the decision, next to its ADR, so a decision and
95
+ its check change in the same pull request and this package needs no release.
96
+
97
+ A rule set (`docs/adr/0050-....rules.json`), in dependency-cruiser's vocabulary plus `roles`:
98
+
99
+ ```json
100
+ {
101
+ "name": "ADR 0050: ...",
102
+ "exclude": ["^(?!src/)", "\\.(test|spec|stories)\\.[cm]?[jt]sx?$"],
103
+ "roles": [
104
+ { "name": "route", "path": "^src/routes/" },
105
+ { "name": "api", "path": ["(^|/)(services|queries|mutations)/"] },
106
+ { "name": "view", "path": "\\.(tsx|svelte)$", "exports": "component" }
107
+ ],
108
+ "forbidden": [
109
+ {
110
+ "name": "G2a",
111
+ "severity": "error",
112
+ "comment": "The api layer never imports a view.",
113
+ "from": { "role": "api" },
114
+ "to": { "role": "view" }
115
+ }
116
+ ]
117
+ }
118
+ ```
119
+
120
+ Roles are decided first match wins, by path (regular expressions relative to the module) and,
121
+ for `exports: "component"`, by the file's default or same-named export. A file no role matches is
122
+ `unclassified`: counted, never flagged. A role must have a `path` or `exports`.
123
+
124
+ An import is followed to the file that DEFINES each imported name, through barrels
125
+ (`export { x } from`, `export * from`), and that file's role is what a rule reads. Aliases come from
126
+ the workspace's `tsconfig.base.json`, the module's own `tsconfig.json`, and SvelteKit's `$lib` and
127
+ `kit.alias`. An alias that resolves to nothing is reported, not taken for a package.
128
+
129
+ Which kind of rule a `to` makes:
130
+
131
+ | `to` | Forbids |
132
+ | ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
133
+ | `role` / `path` (`pathNot`, `dependencyTypesNot: ["type-only"]`) | importing a file of that side, inside the module or in a shared library |
134
+ | `module` + `names` | importing those names from that package, as a value |
135
+ | `calls` (+ `module`, a regular expression) | calling those globals, or importing a matching client as a value; `typeImports: true` counts an `import type` of it too |
136
+ | `role` / `path` + `slice: "other"` | the same import, only when it lands in another slice of the module |
137
+ | `classNames` (a regular expression) | a class string written in a `className` or `class` attribute |
138
+
139
+ A rule that states what a file, a class or a directory must BE uses one of these keys instead of
140
+ `to`, one per rule:
141
+
142
+ | Key | Requires | Example |
143
+ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
144
+ | `file` | `name` (a regex on its base name), `exportsItsName`, `exportStar: false`, `interfaceAndSymbol: true`, or `allowed: false` (it does not belong there) | `{ "exportsItsName": { "strip": "\\.controller\\.ts$", "case": "pascal", "append": "Controller" } }` |
145
+ | `bindings` | `binds: "nothing"` (no `{ provide, useClass }`), or `"own-slice"` (only tokens of its own slice) | the application module binds no port |
146
+ | `class` | `implements` / `injects` counted (`to`, `min`, `max`), or exactly these `publicMethods`; `name`, a regex, keeps only the exported classes it names | `{ "name": "UseCase$", "publicMethods": ["execute"] }` |
147
+ | `imports` | `count` of distinct files of `to` (`min`, `max`), or `all`: it imports each kind at once | a route imports exactly one entry view |
148
+ | `inbound` | `slices.min`: at least that many other slices import it | a file in `shared` used by two slices |
149
+ | `directory` | `names` forbidden, `under: "slice"` (directly under a slice root), `withSibling` | no `domain/` beside an `infrastructure/` |
150
+
151
+ A slice is what the rule set's `slices` says: regular expressions with one capture group, the slice
152
+ root, first match wins. Only a file of the same module has a slice; a shared library has none, so it
153
+ is never "another slice". A rule that reads slices in a set that declares none is refused.
154
+
155
+ A violation of these rules names what is wrong in words that stay the same while the violation
156
+ does (`class FooAdapter`, `directory domain`), so a moved count is not a new violation; the count
157
+ is shown beside it.
158
+
159
+ The map (`sentinel.arch.json`, at the workspace root), first match wins:
160
+
161
+ ```json
162
+ {
163
+ "decisions": [
164
+ {
165
+ "modules": ["apps/front/hr-management"],
166
+ "rules": "docs/adr/0050-....rules.json",
167
+ "severity": { "G3": "warn" }
168
+ },
169
+ {
170
+ "modules": ["apps/front/*", "libs/front/*"],
171
+ "rules": "docs/adr/0050-....rules.json"
172
+ }
173
+ ],
174
+ "notices": [{ "modules": ["apps/nest/backends-for-frontends/planning"], "text": "..." }]
175
+ }
176
+ ```
177
+
178
+ A decision's `severity` is read on every run and never copied into a module, so moving it for a
179
+ family of modules is one reviewed change of the map; a module's own `arch.config.mjs` overrides
180
+ it. Notices are said at adoption and change nothing.
181
+
182
+ A rule set, a map or a module config with a defect is refused before anything runs.
183
+
184
+ `calls` names GLOBALS (`fetch`), never a method: `this.db.$transaction()` is not a call of
185
+ `$transaction`, and a rule listing it is said to have found it only as a method.
186
+
187
+ A module the map gives no decision (neither a front nor a BFF, say) is not checked, and `--init`
188
+ says so. To check it, write its rule set (next to the document that decides its architecture) and
189
+ give it a decision in the map: `{ "modules": ["apps/nest/microservices/network"], "rules":
190
+ "apps/nest/microservices/network/agents/implementation/architecture.rules.json" }`. Paths in a
191
+ violation are the module's for the importing file and the workspace's for its target, since a
192
+ target can be in a shared library.
193
+
194
+ ## What the role will not do
195
+
196
+ - Analyse a module whose files did not change: in CI, the modules analysed are those whose own
197
+ files a pull request touches. A shared library that changes can create a violation in a module
198
+ downstream that is not analysed then.
199
+ - Read markup: a `.svelte` file is checked through its `<script>` blocks.
200
+ - Decide a design question no file and import can answer (is this the right boundary for a
201
+ feature). Those stay with the reviewers, as the decisions themselves say.
@@ -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.