@hublo/sentinel 1.7.0-alpha.14 → 1.7.0-alpha.16

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.
@@ -12,7 +12,7 @@ import {
12
12
  presetNotInstalledYet,
13
13
  registerAdapters,
14
14
  resolve
15
- } from "../chunk-TA4OTQMH.js";
15
+ } from "../chunk-IXMVCXKM.js";
16
16
  import {
17
17
  resolveContext,
18
18
  separateToolArgs
@@ -35,7 +35,7 @@ import {
35
35
  TARGETS,
36
36
  VERBS
37
37
  } from "../chunk-BBNABWZ6.js";
38
- import "../chunk-5NBNAIFJ.js";
38
+ import "../chunk-BOGG3VZW.js";
39
39
  import "../chunk-PXTU5MPW.js";
40
40
  import "../chunk-4EIY7TTR.js";
41
41
  import "../chunk-O7REVMOC.js";
@@ -61,6 +61,36 @@ function defineCodeChurn(input = {}) {
61
61
  moved: leafPaths(input.overrides).sort()
62
62
  };
63
63
  }
64
+ function invalidSettings(config) {
65
+ const problems = [];
66
+ const positive = (path, value) => {
67
+ if (!Number.isInteger(value) || value < 1) {
68
+ problems.push(`${path} must be a whole number of 1 or more, got ${JSON.stringify(value)}`);
69
+ }
70
+ };
71
+ const strings = (path, value, allowEmpty) => {
72
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
73
+ problems.push(`${path} must be a list of globs, got ${JSON.stringify(value)}`);
74
+ } else if (!allowEmpty && value.length === 0) {
75
+ problems.push(`${path} must name at least one glob, or nothing is measured`);
76
+ }
77
+ };
78
+ positive("window.reworkDays", config.window?.reworkDays);
79
+ positive("window.periodDays", config.window?.periodDays);
80
+ positive("maxFilesPerCommit", config.maxFilesPerCommit);
81
+ if (!Number.isInteger(config.listed) || config.listed < 0) {
82
+ problems.push(
83
+ `listed must be a whole number of 0 or more, got ${JSON.stringify(config.listed)}`
84
+ );
85
+ }
86
+ if (typeof config.includeTests !== "boolean") {
87
+ problems.push(`includeTests must be true or false, got ${JSON.stringify(config.includeTests)}`);
88
+ }
89
+ strings("include", config.include, false);
90
+ strings("tests", config.tests, true);
91
+ strings("ignore", config.ignore, true);
92
+ return problems;
93
+ }
64
94
 
65
95
  export {
66
96
  TARGET,
@@ -68,6 +98,7 @@ export {
68
98
  REPORT_DIR,
69
99
  SCRIPTS,
70
100
  defaults,
71
- defineCodeChurn
101
+ defineCodeChurn,
102
+ invalidSettings
72
103
  };
73
- //# sourceMappingURL=chunk-5NBNAIFJ.js.map
104
+ //# sourceMappingURL=chunk-BOGG3VZW.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/roles/code-churn/presets/shared.json","../src/roles/code-churn/preset-data.ts","../src/roles/code-churn/configs/define.ts"],"sourcesContent":["{\n \"window\": {\n \"reworkDays\": 21,\n \"periodDays\": 90\n },\n \"maxFilesPerCommit\": 100,\n \"include\": [\"**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,svelte,vue}\"],\n \"includeTests\": false,\n \"tests\": [\n \"**/{test,tests,__tests__,e2e,fixtures,mocks,__mocks__,test-utils}/**\",\n \"**/*.{spec,test,integration-spec,e2e-spec,steps,test-util,mock}.{ts,tsx,mts,cts,js,jsx}\"\n ],\n \"ignore\": [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n \"**/coverage/**\",\n \"**/*.d.{ts,mts,cts}\",\n \"**/*.generated.*\",\n \"**/generated/**\"\n ],\n \"listed\": 10\n}\n","/**\n * The code churn role's values: what it reads, where it writes, and what a module may move.\n *\n * ## What this role measures\n *\n * Code churn in the sense Sourcegraph and DevStats give it: of the lines a module ADDED in a period,\n * the share that was rewritten or deleted within a few weeks of being written. A line rewritten\n * days after it landed is work done twice, which is what the figure is about, and a module whose\n * share is high is one where the code is written before what it must do is settled.\n *\n * It reads the git history and nothing else: no build, no test run, no network. The static\n * analysis role answers what the code IS today; this one answers how it got there. The two are\n * separate roles because one reads the tree and the other reads the history, and a module adopts\n * either without the other (HUB-46818, hublo/sentinel#98).\n *\n * ## Which modules: the ones that hold code\n *\n * Every preset, like the static analysis role: rework is the same question whatever the stack. A\n * module with no file the role reads is skipped by `--init`, and said so.\n */\nimport sharedData from './presets/shared.json'\n\n/** The target this role serves, and the flag that runs it: `sentinel --run --code-churn`. */\nexport const TARGET = 'code-churn'\n\n/** The file a module writes at its root to move a setting. Optional at every moment. */\nexport const CODE_CHURN_CONFIG_FILE = 'code-churn.config.mjs'\n\n/**\n * Where the files of `--output json|html|markdown` land, inside the module.\n *\n * Its own directory rather than `static-analysis-report/`: two roles writing into one folder would\n * each clear the other's stale files.\n */\nexport const REPORT_DIR = 'code-churn-report'\n\n/**\n * One script per shape a DEVELOPER runs. `markdown` gets none: it is the pull request comment a CI\n * workflow produces, the decision static analysis took for the same reason.\n */\nexport const SCRIPTS = {\n console: 'code-churn',\n json: 'code-churn:json',\n html: 'code-churn:html',\n} as const\n\nexport interface CodeChurnDefaults {\n /** The two durations the figure is made of, in days. */\n window: {\n /**\n * How long after a line is written a change to it counts as rework. 21 days, the window\n * Sourcegraph uses (\"code rewritten or deleted within three weeks of being written\"); DevStats\n * gives 14 to 21. A change after it is maintenance, not rework, and is not counted.\n */\n reworkDays: number\n /**\n * How far back the lines that are measured were written, in days, ending `reworkDays` before\n * the newest commit read. The period stops there so every line it holds has had its full\n * window: a line written yesterday cannot have been rewritten yet, and counting it would lower\n * the figure for a reason that has nothing to do with the code.\n */\n periodDays: number\n }\n /**\n * A commit that touches more files than this IN THE MODULE is a sweep, a formatter run or a\n * rename sweep, and its lines are not counted. Counted in the module and not in the repository,\n * which was measured: see `churn.ts`, \"What is not counted\".\n */\n maxFilesPerCommit: number\n /** The files whose lines are measured, as globs relative to the module. */\n include: string[]\n /**\n * Measure the tests too. OFF by default: the figure is about the product code, and a test\n * rewritten with the code it checks is the expected case, not rework. A module that decides\n * otherwise sets it to true, and the report says so.\n */\n includeTests: boolean\n /** What counts as a test, by path. The list the sql role measured, extended to JavaScript. */\n tests: string[]\n /** Files never measured, whatever `include` says: generated and built output. */\n ignore: string[]\n /** How many files the report lists, highest churn first. */\n listed: number\n}\n\n/**\n * The role's values, read from `presets/shared.json`: preset data is JSON, never TypeScript, in every\n * role (AGENTS.md, and `tests/role-layout.test.ts` holds it). The reasons for each value are the\n * comments on `CodeChurnDefaults` above, since JSON carries none.\n */\nexport const defaults: CodeChurnDefaults = sharedData as CodeChurnDefaults\n","/**\n * `defineCodeChurn`: what a module imports to declare its own code churn settings.\n *\n * ```js\n * // code-churn.config.mjs\n * import { defineCodeChurn } from '@hublo/sentinel/code-churn'\n *\n * export default defineCodeChurn({\n * root: import.meta.dirname,\n * overrides: { window: { periodDays: 180 } },\n * })\n * ```\n *\n * The shape of `defineStaticAnalysis` and `defineSql`, for the two reasons stated there. A function\n * receives the module's INTENT, the keys it actually passed, and merges them here, so setting one\n * key never drops its siblings: a spread in the module's file would replace the whole `window` block\n * to set `periodDays`, and lose `reworkDays` with nobody seeing it. And the defaults are never\n * copied into a module, so a changed default reaches every module at the next release instead of\n * leaving stale copies behind.\n *\n * `overrides` REPLACES what it names, lists included, and every path it sets lands in `moved`, so\n * the report prints `(module)` beside it: two modules measured with different windows no longer\n * compare, and the reader has to be told.\n */\nimport { isPlainObject } from '../../../shared/deep-merge.js'\nimport { defaults, type CodeChurnDefaults } from '../preset-data.js'\n\ntype DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] }\n\n/** What a module's config file passes. Everything is optional, including the file itself. */\nexport interface CodeChurnInput {\n /** The module's own directory, normally `import.meta.dirname`. */\n root?: string\n /** The seam. Replaces whatever it names, and every path it sets lands in `moved`. */\n overrides?: DeepPartial<CodeChurnDefaults>\n}\n\nexport interface ResolvedCodeChurnConfig extends CodeChurnDefaults {\n /** The module's directory, or null when its config file did not say. */\n root: string | null\n /** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */\n moved: string[]\n}\n\n/**\n * Merge `patch` into `base`, recursively, patch winning.\n *\n * Arrays are REPLACED, never concatenated: a merge that concatenates cannot express \"replace this\n * list\", which is exactly what a team reaching for `overrides` asks for.\n */\nfunction mergeInto<T>(base: T, patch: unknown): T {\n if (!isPlainObject(patch)) return base\n if (!isPlainObject(base)) return patch as T\n const out: Record<string, unknown> = { ...base }\n for (const [key, value] of Object.entries(patch)) {\n out[key] = isPlainObject(value) ? mergeInto(out[key], value) : value\n }\n return out as T\n}\n\n/** Every leaf path in `patch`, dotted, so a reader can be told what the module decided. */\nfunction leafPaths(patch: unknown, prefix = ''): string[] {\n if (!isPlainObject(patch)) return prefix ? [prefix] : []\n return Object.entries(patch).flatMap(([key, value]) =>\n leafPaths(value, prefix ? `${prefix}.${key}` : key),\n )\n}\n\n/** Resolve a module's declaration against this role's defaults. */\nexport function defineCodeChurn(input: CodeChurnInput = {}): ResolvedCodeChurnConfig {\n return {\n ...mergeInto(defaults, input.overrides),\n root: input.root ?? null,\n moved: leafPaths(input.overrides).sort(),\n }\n}\n"],"mappings":";;;;;AAAA;AAAA,EACE,QAAU;AAAA,IACR,YAAc;AAAA,IACd,YAAc;AAAA,EAChB;AAAA,EACA,mBAAqB;AAAA,EACrB,SAAW,CAAC,iDAAiD;AAAA,EAC7D,cAAgB;AAAA,EAChB,OAAS;AAAA,IACP;AAAA,IACA;AAAA,EACF;AAAA,EACA,QAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,QAAU;AACZ;;;ACCO,IAAM,SAAS;AAGf,IAAM,yBAAyB;AAQ/B,IAAM,aAAa;AAMnB,IAAM,UAAU;AAAA,EACrB,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AACR;AA8CO,IAAM,WAA8B;;;ACxC3C,SAAS,UAAa,MAAS,OAAmB;AAChD,MAAI,CAAC,cAAc,KAAK,EAAG,QAAO;AAClC,MAAI,CAAC,cAAc,IAAI,EAAG,QAAO;AACjC,QAAM,MAA+B,EAAE,GAAG,KAAK;AAC/C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,QAAI,GAAG,IAAI,cAAc,KAAK,IAAI,UAAU,IAAI,GAAG,GAAG,KAAK,IAAI;AAAA,EACjE;AACA,SAAO;AACT;AAGA,SAAS,UAAU,OAAgB,SAAS,IAAc;AACxD,MAAI,CAAC,cAAc,KAAK,EAAG,QAAO,SAAS,CAAC,MAAM,IAAI,CAAC;AACvD,SAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,IAAQ,CAAC,CAAC,KAAK,KAAK,MAC/C,UAAU,OAAO,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK,GAAG;AAAA,EACpD;AACF;AAGO,SAAS,gBAAgB,QAAwB,CAAC,GAA4B;AACnF,SAAO;AAAA,IACL,GAAG,UAAU,UAAU,MAAM,SAAS;AAAA,IACtC,MAAM,MAAM,QAAQ;AAAA,IACpB,OAAO,UAAU,MAAM,SAAS,EAAE,KAAK;AAAA,EACzC;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/roles/code-churn/presets/shared.json","../src/roles/code-churn/preset-data.ts","../src/roles/code-churn/configs/define.ts"],"sourcesContent":["{\n \"window\": {\n \"reworkDays\": 21,\n \"periodDays\": 90\n },\n \"maxFilesPerCommit\": 100,\n \"include\": [\"**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,svelte,vue}\"],\n \"includeTests\": false,\n \"tests\": [\n \"**/{test,tests,__tests__,e2e,fixtures,mocks,__mocks__,test-utils}/**\",\n \"**/*.{spec,test,integration-spec,e2e-spec,steps,test-util,mock}.{ts,tsx,mts,cts,js,jsx}\"\n ],\n \"ignore\": [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n \"**/coverage/**\",\n \"**/*.d.{ts,mts,cts}\",\n \"**/*.generated.*\",\n \"**/generated/**\"\n ],\n \"listed\": 10\n}\n","/**\n * The code churn role's values: what it reads, where it writes, and what a module may move.\n *\n * ## What this role measures\n *\n * Code churn in the sense Sourcegraph and DevStats give it: of the lines a module ADDED in a period,\n * the share that was rewritten or deleted within a few weeks of being written. A line rewritten\n * days after it landed is work done twice, which is what the figure is about, and a module whose\n * share is high is one where the code is written before what it must do is settled.\n *\n * It reads the git history and nothing else: no build, no test run, no network. The static\n * analysis role answers what the code IS today; this one answers how it got there. The two are\n * separate roles because one reads the tree and the other reads the history, and a module adopts\n * either without the other (HUB-46818, hublo/sentinel#98).\n *\n * ## Which modules: the ones that hold code\n *\n * Every preset, like the static analysis role: rework is the same question whatever the stack. A\n * module with no file the role reads is skipped by `--init`, and said so.\n */\nimport sharedData from './presets/shared.json'\n\n/** The target this role serves, and the flag that runs it: `sentinel --run --code-churn`. */\nexport const TARGET = 'code-churn'\n\n/** The file a module writes at its root to move a setting. Optional at every moment. */\nexport const CODE_CHURN_CONFIG_FILE = 'code-churn.config.mjs'\n\n/**\n * Where the files of `--output json|html|markdown` land, inside the module.\n *\n * Its own directory rather than `static-analysis-report/`: two roles writing into one folder would\n * each clear the other's stale files.\n */\nexport const REPORT_DIR = 'code-churn-report'\n\n/**\n * One script per shape a DEVELOPER runs. `markdown` gets none: it is the pull request comment a CI\n * workflow produces, the decision static analysis took for the same reason.\n */\nexport const SCRIPTS = {\n console: 'code-churn',\n json: 'code-churn:json',\n html: 'code-churn:html',\n} as const\n\nexport interface CodeChurnDefaults {\n /** The two durations the figure is made of, in days. */\n window: {\n /**\n * How long after a line is written a change to it counts as rework. 21 days, the window\n * Sourcegraph uses (\"code rewritten or deleted within three weeks of being written\"); DevStats\n * gives 14 to 21. A change after it is maintenance, not rework, and is not counted.\n */\n reworkDays: number\n /**\n * How far back the lines that are measured were written, in days, ending `reworkDays` before\n * the newest commit read. The period stops there so every line it holds has had its full\n * window: a line written yesterday cannot have been rewritten yet, and counting it would lower\n * the figure for a reason that has nothing to do with the code.\n */\n periodDays: number\n }\n /**\n * A commit that touches more files than this IN THE MODULE is a sweep, a formatter run or a\n * rename sweep, and its lines are not counted. Counted in the module and not in the repository,\n * which was measured: see `churn.ts`, \"What is not counted\".\n */\n maxFilesPerCommit: number\n /** The files whose lines are measured, as globs relative to the module. */\n include: string[]\n /**\n * Measure the tests too. OFF by default: the figure is about the product code, and a test\n * rewritten with the code it checks is the expected case, not rework. A module that decides\n * otherwise sets it to true, and the report says so.\n */\n includeTests: boolean\n /** What counts as a test, by path. The list the sql role measured, extended to JavaScript. */\n tests: string[]\n /** Files never measured, whatever `include` says: generated and built output. */\n ignore: string[]\n /** How many files the report lists, highest churn first. */\n listed: number\n}\n\n/**\n * The role's values, read from `presets/shared.json`: preset data is JSON, never TypeScript, in every\n * role (AGENTS.md, and `tests/role-layout.test.ts` holds it). The reasons for each value are the\n * comments on `CodeChurnDefaults` above, since JSON carries none.\n */\nexport const defaults: CodeChurnDefaults = sharedData as CodeChurnDefaults\n","/**\n * `defineCodeChurn`: what a module imports to declare its own code churn settings.\n *\n * ```js\n * // code-churn.config.mjs\n * import { defineCodeChurn } from '@hublo/sentinel/code-churn'\n *\n * export default defineCodeChurn({\n * root: import.meta.dirname,\n * overrides: { window: { periodDays: 180 } },\n * })\n * ```\n *\n * The shape of `defineStaticAnalysis` and `defineSql`, for the two reasons stated there. A function\n * receives the module's INTENT, the keys it actually passed, and merges them here, so setting one\n * key never drops its siblings: a spread in the module's file would replace the whole `window` block\n * to set `periodDays`, and lose `reworkDays` with nobody seeing it. And the defaults are never\n * copied into a module, so a changed default reaches every module at the next release instead of\n * leaving stale copies behind.\n *\n * `overrides` REPLACES what it names, lists included, and every path it sets lands in `moved`, so\n * the report prints `(module)` beside it: two modules measured with different windows no longer\n * compare, and the reader has to be told.\n */\nimport { isPlainObject } from '../../../shared/deep-merge.js'\nimport { defaults, type CodeChurnDefaults } from '../preset-data.js'\n\ntype DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] }\n\n/** What a module's config file passes. Everything is optional, including the file itself. */\nexport interface CodeChurnInput {\n /** The module's own directory, normally `import.meta.dirname`. */\n root?: string\n /** The seam. Replaces whatever it names, and every path it sets lands in `moved`. */\n overrides?: DeepPartial<CodeChurnDefaults>\n}\n\nexport interface ResolvedCodeChurnConfig extends CodeChurnDefaults {\n /** The module's directory, or null when its config file did not say. */\n root: string | null\n /** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */\n moved: string[]\n}\n\n/**\n * Merge `patch` into `base`, recursively, patch winning.\n *\n * Arrays are REPLACED, never concatenated: a merge that concatenates cannot express \"replace this\n * list\", which is exactly what a team reaching for `overrides` asks for.\n */\nfunction mergeInto<T>(base: T, patch: unknown): T {\n if (!isPlainObject(patch)) return base\n if (!isPlainObject(base)) return patch as T\n const out: Record<string, unknown> = { ...base }\n for (const [key, value] of Object.entries(patch)) {\n out[key] = isPlainObject(value) ? mergeInto(out[key], value) : value\n }\n return out as T\n}\n\n/** Every leaf path in `patch`, dotted, so a reader can be told what the module decided. */\nfunction leafPaths(patch: unknown, prefix = ''): string[] {\n if (!isPlainObject(patch)) return prefix ? [prefix] : []\n return Object.entries(patch).flatMap(([key, value]) =>\n leafPaths(value, prefix ? `${prefix}.${key}` : key),\n )\n}\n\n/** Resolve a module's declaration against this role's defaults. */\nexport function defineCodeChurn(input: CodeChurnInput = {}): ResolvedCodeChurnConfig {\n return {\n ...mergeInto(defaults, input.overrides),\n root: input.root ?? null,\n moved: leafPaths(input.overrides).sort(),\n }\n}\n\n/**\n * The settings of a resolved config that cannot be measured with, one sentence each naming the\n * setting and the value. Empty when the config is usable.\n *\n * ⛔ Checked rather than trusted: a negative window runs the period into the future, a `listed` of\n * -1 drops the last file through `slice(0, -1)`, a cap of 0 makes every commit a sweep, an empty\n * `include` measures nothing, and none of them says so. Each one is a figure that looks right.\n */\nexport function invalidSettings(config: CodeChurnDefaults): string[] {\n const problems: string[] = []\n const positive = (path: string, value: unknown): void => {\n if (!Number.isInteger(value) || (value as number) < 1) {\n problems.push(`${path} must be a whole number of 1 or more, got ${JSON.stringify(value)}`)\n }\n }\n const strings = (path: string, value: unknown, allowEmpty: boolean): void => {\n if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {\n problems.push(`${path} must be a list of globs, got ${JSON.stringify(value)}`)\n } else if (!allowEmpty && value.length === 0) {\n problems.push(`${path} must name at least one glob, or nothing is measured`)\n }\n }\n positive('window.reworkDays', config.window?.reworkDays)\n positive('window.periodDays', config.window?.periodDays)\n positive('maxFilesPerCommit', config.maxFilesPerCommit)\n if (!Number.isInteger(config.listed) || config.listed < 0) {\n problems.push(\n `listed must be a whole number of 0 or more, got ${JSON.stringify(config.listed)}`,\n )\n }\n if (typeof config.includeTests !== 'boolean') {\n problems.push(`includeTests must be true or false, got ${JSON.stringify(config.includeTests)}`)\n }\n strings('include', config.include, false)\n strings('tests', config.tests, true)\n strings('ignore', config.ignore, true)\n return problems\n}\n"],"mappings":";;;;;AAAA;AAAA,EACE,QAAU;AAAA,IACR,YAAc;AAAA,IACd,YAAc;AAAA,EAChB;AAAA,EACA,mBAAqB;AAAA,EACrB,SAAW,CAAC,iDAAiD;AAAA,EAC7D,cAAgB;AAAA,EAChB,OAAS;AAAA,IACP;AAAA,IACA;AAAA,EACF;AAAA,EACA,QAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,QAAU;AACZ;;;ACCO,IAAM,SAAS;AAGf,IAAM,yBAAyB;AAQ/B,IAAM,aAAa;AAMnB,IAAM,UAAU;AAAA,EACrB,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AACR;AA8CO,IAAM,WAA8B;;;ACxC3C,SAAS,UAAa,MAAS,OAAmB;AAChD,MAAI,CAAC,cAAc,KAAK,EAAG,QAAO;AAClC,MAAI,CAAC,cAAc,IAAI,EAAG,QAAO;AACjC,QAAM,MAA+B,EAAE,GAAG,KAAK;AAC/C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,QAAI,GAAG,IAAI,cAAc,KAAK,IAAI,UAAU,IAAI,GAAG,GAAG,KAAK,IAAI;AAAA,EACjE;AACA,SAAO;AACT;AAGA,SAAS,UAAU,OAAgB,SAAS,IAAc;AACxD,MAAI,CAAC,cAAc,KAAK,EAAG,QAAO,SAAS,CAAC,MAAM,IAAI,CAAC;AACvD,SAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,IAAQ,CAAC,CAAC,KAAK,KAAK,MAC/C,UAAU,OAAO,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK,GAAG;AAAA,EACpD;AACF;AAGO,SAAS,gBAAgB,QAAwB,CAAC,GAA4B;AACnF,SAAO;AAAA,IACL,GAAG,UAAU,UAAU,MAAM,SAAS;AAAA,IACtC,MAAM,MAAM,QAAQ;AAAA,IACpB,OAAO,UAAU,MAAM,SAAS,EAAE,KAAK;AAAA,EACzC;AACF;AAUO,SAAS,gBAAgB,QAAqC;AACnE,QAAM,WAAqB,CAAC;AAC5B,QAAM,WAAW,CAAC,MAAc,UAAyB;AACvD,QAAI,CAAC,OAAO,UAAU,KAAK,KAAM,QAAmB,GAAG;AACrD,eAAS,KAAK,GAAG,IAAI,6CAA6C,KAAK,UAAU,KAAK,CAAC,EAAE;AAAA,IAC3F;AAAA,EACF;AACA,QAAM,UAAU,CAAC,MAAc,OAAgB,eAA8B;AAC3E,QAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,KAAK,CAAC,SAAS,OAAO,SAAS,QAAQ,GAAG;AAC3E,eAAS,KAAK,GAAG,IAAI,iCAAiC,KAAK,UAAU,KAAK,CAAC,EAAE;AAAA,IAC/E,WAAW,CAAC,cAAc,MAAM,WAAW,GAAG;AAC5C,eAAS,KAAK,GAAG,IAAI,sDAAsD;AAAA,IAC7E;AAAA,EACF;AACA,WAAS,qBAAqB,OAAO,QAAQ,UAAU;AACvD,WAAS,qBAAqB,OAAO,QAAQ,UAAU;AACvD,WAAS,qBAAqB,OAAO,iBAAiB;AACtD,MAAI,CAAC,OAAO,UAAU,OAAO,MAAM,KAAK,OAAO,SAAS,GAAG;AACzD,aAAS;AAAA,MACP,mDAAmD,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IAClF;AAAA,EACF;AACA,MAAI,OAAO,OAAO,iBAAiB,WAAW;AAC5C,aAAS,KAAK,2CAA2C,KAAK,UAAU,OAAO,YAAY,CAAC,EAAE;AAAA,EAChG;AACA,UAAQ,WAAW,OAAO,SAAS,KAAK;AACxC,UAAQ,SAAS,OAAO,OAAO,IAAI;AACnC,UAAQ,UAAU,OAAO,QAAQ,IAAI;AACrC,SAAO;AACT;","names":[]}
@@ -98,8 +98,9 @@ import {
98
98
  SCRIPTS,
99
99
  TARGET,
100
100
  defaults,
101
- defineCodeChurn
102
- } from "./chunk-5NBNAIFJ.js";
101
+ defineCodeChurn,
102
+ invalidSettings
103
+ } from "./chunk-BOGG3VZW.js";
103
104
  import {
104
105
  isPlainObject
105
106
  } from "./chunk-PXTU5MPW.js";
@@ -1389,9 +1390,13 @@ import { existsSync as existsSync10 } from "node:fs";
1389
1390
  import { join as join12 } from "node:path";
1390
1391
 
1391
1392
  // src/roles/code-churn/churn.ts
1392
- function splice(lines, index, count, inserted) {
1393
+ function replaced(lines, index, count, written, birth) {
1393
1394
  while (lines.length < index + count) lines.push(null);
1394
- return lines.splice(index, count, ...inserted);
1395
+ const removed = lines.slice(index, index + count);
1396
+ const next = lines.slice(0, index);
1397
+ for (let line = 0; line < written; line++) next.push(birth);
1398
+ for (let line = index + count; line < lines.length; line++) next.push(lines[line] ?? null);
1399
+ return { lines: next, removed };
1395
1400
  }
1396
1401
  function startOf(hunk) {
1397
1402
  return hunk.oldCount === 0 ? hunk.oldStart : hunk.oldStart - 1;
@@ -1408,7 +1413,6 @@ function computeChurn(commits, options) {
1408
1413
  if (sweep) sweeps += 1;
1409
1414
  const countsAdded = !sweep && commit.time >= options.periodStart && commit.time < options.periodEnd;
1410
1415
  for (const change of commit.files) {
1411
- if (change.binary) continue;
1412
1416
  const known = change.from === null ? void 0 : open.get(change.from);
1413
1417
  if (change.from !== null) open.delete(change.from);
1414
1418
  const path2 = change.to ?? change.from ?? "";
@@ -1418,24 +1422,36 @@ function computeChurn(commits, options) {
1418
1422
  };
1419
1423
  replay.figures.path = path2;
1420
1424
  const birth = countsAdded && change.to !== null && options.isMeasured(change.to) ? commit.time : null;
1421
- const hunks = [...change.hunks].sort((a, b) => b.oldStart - a.oldStart);
1422
- for (const hunk of hunks) {
1423
- const written = Array.from({ length: hunk.newCount }, () => birth);
1424
- const removed = splice(replay.lines, startOf(hunk), hunk.oldCount, written);
1425
- if (birth !== null) replay.figures.added += hunk.newCount;
1426
- if (sweep) continue;
1425
+ const reworked = (removed) => {
1426
+ if (sweep) return;
1427
1427
  for (const born of removed) {
1428
1428
  if (born !== null && commit.time - born <= options.reworkSeconds) {
1429
1429
  replay.figures.rewritten += 1;
1430
1430
  }
1431
1431
  }
1432
+ };
1433
+ if (change.binary) {
1434
+ reworked(replay.lines);
1435
+ replay.lines = [];
1436
+ } else {
1437
+ for (const hunk of [...change.hunks].sort((a, b) => b.oldStart - a.oldStart)) {
1438
+ const next = replaced(replay.lines, startOf(hunk), hunk.oldCount, hunk.newCount, birth);
1439
+ replay.lines = next.lines;
1440
+ if (birth !== null) replay.figures.added += hunk.newCount;
1441
+ reworked(next.removed);
1442
+ }
1432
1443
  }
1433
1444
  if (change.to === null) {
1434
1445
  replay.figures.deleted = true;
1435
1446
  done.push(replay.figures);
1436
- } else {
1437
- open.set(change.to, replay);
1447
+ continue;
1448
+ }
1449
+ const previous = open.get(change.to);
1450
+ if (previous !== void 0 && previous !== replay) {
1451
+ previous.figures.deleted = true;
1452
+ done.push(previous.figures);
1438
1453
  }
1454
+ open.set(change.to, replay);
1439
1455
  }
1440
1456
  }
1441
1457
  const files = [...done, ...[...open.values()].map((replay) => replay.figures)].filter((file) => file.added > 0).sort(
@@ -1462,7 +1478,16 @@ async function loadCodeChurnConfig(cwd) {
1462
1478
  if (!existsSync6(path2)) return { config: defineCodeChurn(), from: null, unreadable: null };
1463
1479
  try {
1464
1480
  const loaded = await import(pathToFileURL(path2).href);
1465
- return { config: adopt(loaded.default), from: CODE_CHURN_CONFIG_FILE, unreadable: null };
1481
+ const config = adopt(loaded.default);
1482
+ const problems = invalidSettings(config);
1483
+ if (problems.length > 0) {
1484
+ return {
1485
+ config: defineCodeChurn(),
1486
+ from: null,
1487
+ unreadable: `${CODE_CHURN_CONFIG_FILE}: ${problems.join("; ")}.`
1488
+ };
1489
+ }
1490
+ return { config, from: CODE_CHURN_CONFIG_FILE, unreadable: null };
1466
1491
  } catch (error) {
1467
1492
  return {
1468
1493
  config: defineCodeChurn(),
@@ -1514,11 +1539,9 @@ function sidePath(raw, prefix) {
1514
1539
  return path2.startsWith(prefix) ? path2.slice(prefix.length) : path2;
1515
1540
  }
1516
1541
  function samePath(rest) {
1517
- const unquoted = rest.trim();
1518
- if (unquoted.length % 2 === 0) return null;
1519
- const half = (unquoted.length - 1) / 2;
1520
- const left = unquoted.slice(0, half);
1521
- const right = unquoted.slice(half + 1);
1542
+ const header = rest.trim();
1543
+ const quoted = /^("(?:[^"\\]|\\.)*") ("(?:[^"\\]|\\.)*")$/.exec(header);
1544
+ const [left, right] = quoted ? [unquote(quoted[1] ?? ""), unquote(quoted[2] ?? "")] : header.length % 2 === 1 ? [header.slice(0, (header.length - 1) / 2), header.slice((header.length + 1) / 2)] : ["", ""];
1522
1545
  if (!left.startsWith("a/") || !right.startsWith("b/") || left.slice(2) !== right.slice(2)) {
1523
1546
  return null;
1524
1547
  }
@@ -1570,19 +1593,40 @@ function parsePatch(text) {
1570
1593
 
1571
1594
  // src/roles/code-churn/history/read.ts
1572
1595
  var DAY = 86400;
1573
- var MAX_BUFFER = 512 * 1024 * 1024;
1596
+ var MAX_BUFFER = 256 * 1024 * 1024;
1597
+ var PINNED = [
1598
+ "-c",
1599
+ "core.quotePath=false",
1600
+ "-c",
1601
+ "diff.algorithm=myers",
1602
+ "-c",
1603
+ "diff.indentHeuristic=true",
1604
+ "-c",
1605
+ "diff.renameLimit=1000"
1606
+ ];
1574
1607
  function git(cwd, args) {
1575
- const run = spawnSync3("git", ["-c", "core.quotePath=false", "--no-pager", ...args], {
1608
+ const run = spawnSync3("git", [...PINNED, "--no-pager", ...args], {
1576
1609
  cwd,
1577
1610
  encoding: "utf8",
1578
1611
  maxBuffer: MAX_BUFFER
1579
1612
  });
1580
- if (run.error) return { ok: false, said: `git could not run: ${run.error.message}` };
1613
+ if (run.error) {
1614
+ const code = run.error.code;
1615
+ if (code === "ENOENT") return { ok: false, said: GIT_MISSING };
1616
+ if (code === "ENOBUFS") {
1617
+ return {
1618
+ ok: false,
1619
+ said: `the history is larger than the ${MAX_BUFFER / 1024 / 1024} MB one run reads. Shorten \`window.periodDays\` in code-churn.config.mjs, then run this again`
1620
+ };
1621
+ }
1622
+ return { ok: false, said: `git could not run: ${run.error.message}` };
1623
+ }
1581
1624
  if (run.status !== 0) {
1582
1625
  return { ok: false, said: run.stderr.trim() || `git exited with ${run.status}` };
1583
1626
  }
1584
1627
  return { ok: true, out: run.stdout };
1585
1628
  }
1629
+ var GIT_MISSING = "git is not installed here, or not on the PATH, and code churn is read from git history";
1586
1630
  function describe(ref, label) {
1587
1631
  return label === ref ? ref : `${label} (${ref})`;
1588
1632
  }
@@ -1594,11 +1638,17 @@ function anchorOf(cwd, env) {
1594
1638
  if (!inRepository.ok) {
1595
1639
  return {
1596
1640
  ok: false,
1597
- reason: `this module is not in a git repository (${inRepository.said}), and code churn is read from its history.`
1641
+ reason: inRepository.said === GIT_MISSING ? `${GIT_MISSING}.` : `this module is not in a git repository (${inRepository.said}), and code churn is read from its history.`
1598
1642
  };
1599
1643
  }
1600
1644
  const shallow = git(cwd, ["rev-parse", "--is-shallow-repository"]);
1601
- if (!shallow.ok || shallow.out.trim() === "true") {
1645
+ if (!shallow.ok) {
1646
+ return {
1647
+ ok: false,
1648
+ reason: `git could not say whether this clone is shallow (${shallow.said}); git 2.15 or later is needed.`
1649
+ };
1650
+ }
1651
+ if (shallow.out.trim() === "true") {
1602
1652
  return {
1603
1653
  ok: false,
1604
1654
  reason: "this clone is shallow, so its history is cut short and every line in it would look newly written. Fetch the full history (`fetch-depth: 0` in CI, `git fetch --unshallow` locally), then run this again."
@@ -1636,16 +1686,12 @@ function readHistory(cwd, window, env = process.env) {
1636
1686
  if (!anchor.ok) return anchor;
1637
1687
  const periodEnd = anchor.time - window.reworkDays * DAY;
1638
1688
  const periodStart = periodEnd - window.periodDays * DAY;
1639
- const since = periodStart;
1640
- const range = [
1689
+ const patch = git(cwd, [
1690
+ "log",
1641
1691
  anchor.sha,
1642
1692
  "--first-parent",
1643
1693
  "--diff-merges=first-parent",
1644
- `--since=${isoOf(since)}`
1645
- ];
1646
- const patch = git(cwd, [
1647
- "log",
1648
- ...range,
1694
+ `--since=${isoOf(periodStart)}`,
1649
1695
  "--reverse",
1650
1696
  `--format=${COMMIT_MARK}%H %ct`,
1651
1697
  "-p",
@@ -3389,6 +3435,11 @@ function read(report) {
3389
3435
  const skipped = figures.sweeps === 0 ? "" : `, ${figures.sweeps} of them skipped as touching more than ${report.maxFilesPerCommit} files of the module`;
3390
3436
  return `Read: ${figures.commits} commit(s) of \`${report.base.ref}\` up to \`${report.base.commit}\`${skipped}.`;
3391
3437
  }
3438
+ function codeCell(path2) {
3439
+ const cell2 = path2.replace(/\|/g, "\\|");
3440
+ if (!cell2.includes("`")) return `\`${cell2}\``;
3441
+ return `\`\` ${cell2} \`\``;
3442
+ }
3392
3443
  function fileTable(report) {
3393
3444
  const shown = report.figures.files.filter((file) => file.rewritten > 0).slice(0, FILES_IN_RECAP);
3394
3445
  if (shown.length === 0) return [];
@@ -3397,7 +3448,7 @@ function fileTable(report) {
3397
3448
  "| Most rewritten | Added | Rewritten | Churn |",
3398
3449
  "| --- | ---: | ---: | ---: |",
3399
3450
  ...shown.map(
3400
- (file) => `| \`${file.path}\`${file.deleted ? " (deleted)" : ""} | ${file.added} | ${file.rewritten} | ${percent(fileRate(file))} |`
3451
+ (file) => `| ${codeCell(file.path)}${file.deleted ? " (deleted)" : ""} | ${file.added} | ${file.rewritten} | ${percent(fileRate(file))} |`
3401
3452
  )
3402
3453
  ];
3403
3454
  }
@@ -3810,6 +3861,7 @@ var GitAdapter = class extends BaseAdapter {
3810
3861
  code: 0,
3811
3862
  metrics: {
3812
3863
  files,
3864
+ historyRead: true,
3813
3865
  churn: figures.rate,
3814
3866
  added: figures.added,
3815
3867
  rewritten: figures.rewritten,
package/dist/index.js CHANGED
@@ -6,13 +6,13 @@ import {
6
6
  registerAdapters,
7
7
  resolve,
8
8
  setDefaultRunner
9
- } from "./chunk-TA4OTQMH.js";
9
+ } from "./chunk-IXMVCXKM.js";
10
10
  import {
11
11
  BaseAdapter
12
12
  } from "./chunk-FEDI4HHE.js";
13
13
  import "./chunk-XTBHIKFG.js";
14
14
  import "./chunk-BBNABWZ6.js";
15
- import "./chunk-5NBNAIFJ.js";
15
+ import "./chunk-BOGG3VZW.js";
16
16
  import "./chunk-PXTU5MPW.js";
17
17
  import "./chunk-4EIY7TTR.js";
18
18
  import "./chunk-O7REVMOC.js";
@@ -55,5 +55,14 @@ interface ResolvedCodeChurnConfig extends CodeChurnDefaults {
55
55
  }
56
56
  /** Resolve a module's declaration against this role's defaults. */
57
57
  declare function defineCodeChurn(input?: CodeChurnInput): ResolvedCodeChurnConfig;
58
+ /**
59
+ * The settings of a resolved config that cannot be measured with, one sentence each naming the
60
+ * setting and the value. Empty when the config is usable.
61
+ *
62
+ * ⛔ Checked rather than trusted: a negative window runs the period into the future, a `listed` of
63
+ * -1 drops the last file through `slice(0, -1)`, a cap of 0 makes every commit a sweep, an empty
64
+ * `include` measures nothing, and none of them says so. Each one is a figure that looks right.
65
+ */
66
+ declare function invalidSettings(config: CodeChurnDefaults): string[];
58
67
 
59
- export { type CodeChurnInput, type ResolvedCodeChurnConfig, defineCodeChurn };
68
+ export { type CodeChurnInput, type ResolvedCodeChurnConfig, defineCodeChurn, invalidSettings };
@@ -1,8 +1,10 @@
1
1
  import {
2
- defineCodeChurn
3
- } from "../../chunk-5NBNAIFJ.js";
2
+ defineCodeChurn,
3
+ invalidSettings
4
+ } from "../../chunk-BOGG3VZW.js";
4
5
  import "../../chunk-PXTU5MPW.js";
5
6
  export {
6
- defineCodeChurn
7
+ defineCodeChurn,
8
+ invalidSettings
7
9
  };
8
10
  //# sourceMappingURL=config.js.map
@@ -109,6 +109,48 @@ Measured on hublo/monorepo `main` f12da701121, period 2026-07-28 to 2026-10-26:
109
109
  - **Rework is not a defect by itself.** A feature built in steps rewrites its first draft on
110
110
  purpose.
111
111
 
112
+ ## How others read code churn
113
+
114
+ No large company publishes code churn as a productivity measure. Research supports it as a
115
+ **risk signal on a file or a module**, read over time and beside other figures. So this role
116
+ reports it per module, never per person, and never as a target.
117
+
118
+ | Who | Their reading | What this role takes from it |
119
+ | ----------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
120
+ | 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 |
121
+ | 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 |
122
+ | 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 |
123
+ | 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 |
124
+ | 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 |
125
+ | 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 |
126
+ | 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 |
127
+ | 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 |
128
+ | Vendor benchmarks (EM Tools, LinearB) | 15 to 25% usual, under 15% elite, 10 to 40% by product stage: they disagree | Printed beside the figure, never applied |
129
+
130
+ ## Every hypothesis and compromise, in one place
131
+
132
+ Each choice the figure depends on, why it was made, what it costs, and how a module moves it.
133
+ Measured on hublo/monorepo `main` f12da701121 unless said otherwise.
134
+
135
+ | # | Hypothesis or compromise | Why | What it costs, measured | Moved by |
136
+ | --- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------- |
137
+ | 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` |
138
+ | 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` |
139
+ | 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 |
140
+ | 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 |
141
+ | 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 |
142
+ | 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` |
143
+ | 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` |
144
+ | 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 |
145
+ | 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 |
146
+ | 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 |
147
+ | 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 |
148
+ | 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 |
149
+ | 13 | Binary files are skipped | They have no lines | none on the modules measured | not movable |
150
+ | 14 | No threshold, no gate; 15 to 25% and above 30% are printed as reference points | They come from industry write-ups, not from a study | A reader has to read the figure, not a colour | not movable |
151
+ | 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 |
152
+ | 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 |
153
+
112
154
  ## The config file, `code-churn.config.mjs`
113
155
 
114
156
  The shape of `static-analysis.config.mjs`. A setting the module leaves out keeps the role's value;
@@ -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).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hublo/sentinel",
3
- "version": "1.7.0-alpha.14",
3
+ "version": "1.7.0-alpha.16",
4
4
  "description": "One CLI that guards code health across Hublo repos: shared lint/typescript/build/test presets, static & dynamic analysis, and architecture checks.",
5
5
  "type": "module",
6
6
  "license": "MIT",