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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +3 -0
  2. package/dist/bin/sentinel.js +88 -81
  3. package/dist/{chunk-P6KTBQ2Q.js → chunk-2PRJJRJI.js} +24 -15
  4. package/dist/{chunk-THTXP2QU.js → chunk-APBEGLRI.js} +6 -6
  5. package/dist/chunk-APBEGLRI.js.map +1 -0
  6. package/dist/{chunk-F6ART7RH.js → chunk-HYXFUUF5.js} +14959 -6817
  7. package/dist/{chunk-4YQXLPJ5.js → chunk-LVY5NPOC.js} +2 -2
  8. package/dist/chunk-PXTU5MPW.js +9 -0
  9. package/dist/chunk-PXTU5MPW.js.map +1 -0
  10. package/dist/chunk-SHF46ALB.js +190 -0
  11. package/dist/chunk-SHF46ALB.js.map +1 -0
  12. package/dist/chunk-TMVKYXZ3.js +18 -0
  13. package/dist/chunk-TMVKYXZ3.js.map +1 -0
  14. package/dist/chunk-XYOIXC6A.js +126 -0
  15. package/dist/chunk-XYOIXC6A.js.map +1 -0
  16. package/dist/{chunk-ZNANJEMK.js → chunk-YUZB4LRJ.js} +35 -16
  17. package/dist/chunk-YUZB4LRJ.js.map +1 -0
  18. package/dist/chunk-ZZMYV576.js +297 -0
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +10 -5
  21. package/dist/{migrate-NWQ3LYER.js → migrate-X7PB2X7R.js} +237 -228
  22. package/dist/roles/arch/config.d.ts +25 -0
  23. package/dist/roles/arch/config.js +8 -0
  24. package/dist/roles/arch/config.js.map +1 -0
  25. package/dist/roles/build/nest/toolchain.js +3 -3
  26. package/dist/roles/code-churn/config.d.ts +92 -0
  27. package/dist/roles/code-churn/config.js +10 -0
  28. package/dist/roles/code-churn/config.js.map +1 -0
  29. package/dist/roles/sql/config.d.ts +68 -0
  30. package/dist/roles/sql/config.js +8 -0
  31. package/dist/roles/sql/config.js.map +1 -0
  32. package/dist/roles/static-analysis/config.js +2 -1
  33. package/dist/roles/test/setup/file-boundary.js +3 -3
  34. package/dist/roles/test/setup/jest-parity.js +4 -4
  35. package/dist/roles/test/setup/workspace-entry.js +2 -2
  36. package/dist/{validate-4V3EGTXN.js → validate-4GMB32V7.js} +2 -2
  37. package/docs/arch-adoption.md +201 -0
  38. package/docs/code-churn-adoption.md +237 -0
  39. package/docs/sql-adoption.md +672 -0
  40. package/docs/static-analysis-adoption.md +1 -1
  41. package/docs/static-analysis-study.md +49 -10
  42. package/docs/typescript-adoption.md +47 -6
  43. package/docs/typescript-traces.md +546 -6
  44. package/docs/using-sentinel.md +4 -2
  45. package/package.json +17 -1
  46. package/dist/chunk-THTXP2QU.js.map +0 -1
  47. package/dist/chunk-ZNANJEMK.js.map +0 -1
  48. /package/dist/{chunk-4YQXLPJ5.js.map → chunk-LVY5NPOC.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-ELZHIN6E.js";
4
4
  import {
5
5
  findWorkspaceRoot
6
- } from "./chunk-ZNANJEMK.js";
6
+ } from "./chunk-YUZB4LRJ.js";
7
7
 
8
8
  // src/roles/test/setup/workspace.ts
9
9
  function isMissingModule(error) {
@@ -60,4 +60,4 @@ export {
60
60
  installWorkspaceSetup,
61
61
  pinWorkspaceTimezone
62
62
  };
63
- //# sourceMappingURL=chunk-4YQXLPJ5.js.map
63
+ //# sourceMappingURL=chunk-LVY5NPOC.js.map
@@ -0,0 +1,9 @@
1
+ // src/shared/deep-merge.ts
2
+ function isPlainObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+
6
+ export {
7
+ isPlainObject
8
+ };
9
+ //# sourceMappingURL=chunk-PXTU5MPW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/deep-merge.ts"],"sourcesContent":["/**\n * Is this a plain JSON object?\n *\n * The file is named for a `deepMerge` that no longer exists. It was written when the engine\n * merged JSON in memory and wrote the result; that approach was replaced by editing the\n * document IN PLACE with jsonc-parser, so a project's comments, key order and formatting\n * survive a `merge-json` op. Nothing has called `deepMerge` since, except its own recursion,\n * so it went.\n *\n * What remains is the predicate the in-place merge still needs, to decide whether a value is\n * a branch to walk into or a leaf to set.\n */\n\n/** True for a mergeable plain object (not null, not an array). */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n"],"mappings":";AAcO,SAAS,cAAc,OAAkD;AAC9E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;","names":[]}
@@ -0,0 +1,190 @@
1
+ import {
2
+ isPlainObject
3
+ } from "./chunk-PXTU5MPW.js";
4
+
5
+ // src/roles/sql/presets/shared.json
6
+ var shared_default = {
7
+ migrations: {
8
+ include: ["**/migrations/*/migration.sql"],
9
+ exclude: []
10
+ },
11
+ unsafe: {
12
+ includeTests: true,
13
+ tests: [
14
+ "**/{test,tests,__tests__,e2e,fixtures,mocks,__mocks__,test-utils}/**",
15
+ "**/*.{spec,test,integration-spec,e2e-spec,steps,test-util,mock}.{ts,mts,cts}"
16
+ ]
17
+ },
18
+ ignore: ["**/node_modules/**", "**/dist/**", "**/coverage/**"],
19
+ pgVersion: "16.8",
20
+ rules: {}
21
+ };
22
+
23
+ // src/roles/sql/presets/squawk-rules.json
24
+ var squawk_rules_default = {
25
+ squawk: "2.72.0",
26
+ rules: [
27
+ "adding-field-with-default",
28
+ "adding-foreign-key-constraint",
29
+ "adding-not-nullable-field",
30
+ "adding-required-field",
31
+ "adding-serial-primary-key-field",
32
+ "ban-add-column",
33
+ "ban-add-composite-attribute",
34
+ "ban-add-enum-value",
35
+ "ban-alter-database-options",
36
+ "ban-alter-domain-with-add-constraint",
37
+ "ban-alter-extension",
38
+ "ban-alter-function-options",
39
+ "ban-alter-generated-expression",
40
+ "ban-alter-identity",
41
+ "ban-alter-policy-condition",
42
+ "ban-alter-policy-roles",
43
+ "ban-alter-role-options",
44
+ "ban-alter-row-level-security",
45
+ "ban-alter-sequence-values",
46
+ "ban-alter-system-options",
47
+ "ban-alter-view-options",
48
+ "ban-char-field",
49
+ "ban-concurrent-index-creation-in-transaction",
50
+ "ban-create-domain-with-constraint",
51
+ "ban-create-policy",
52
+ "ban-detach-inheritance",
53
+ "ban-disable-trigger",
54
+ "ban-drop-column",
55
+ "ban-drop-constraint",
56
+ "ban-drop-database",
57
+ "ban-drop-default",
58
+ "ban-drop-domain",
59
+ "ban-drop-extension",
60
+ "ban-drop-function",
61
+ "ban-drop-generated-expression",
62
+ "ban-drop-index",
63
+ "ban-drop-not-null",
64
+ "ban-drop-policy",
65
+ "ban-drop-schema",
66
+ "ban-drop-sequence",
67
+ "ban-drop-table",
68
+ "ban-drop-trigger",
69
+ "ban-drop-type",
70
+ "ban-drop-view",
71
+ "ban-duplicate-column-assignments",
72
+ "ban-new-write-restriction",
73
+ "ban-replace-view-function",
74
+ "ban-replica-identity",
75
+ "ban-revoke",
76
+ "ban-set-default",
77
+ "ban-set-schema",
78
+ "ban-truncate-cascade",
79
+ "ban-uncommitted-transaction",
80
+ "changing-column-type",
81
+ "constraint-missing-not-valid",
82
+ "disallowed-unique-constraint",
83
+ "identifier-too-long",
84
+ "prefer-bigint-over-int",
85
+ "prefer-bigint-over-smallint",
86
+ "prefer-identity",
87
+ "prefer-repack",
88
+ "prefer-robust-stmts",
89
+ "prefer-text-field",
90
+ "prefer-timestamp-tz",
91
+ "renaming-column",
92
+ "renaming-object",
93
+ "renaming-table",
94
+ "require-concurrent-index-creation",
95
+ "require-concurrent-index-deletion",
96
+ "require-concurrent-partition-detach",
97
+ "require-concurrent-reindex",
98
+ "require-enum-value-ordering",
99
+ "require-lock-timeout",
100
+ "require-statement-timeout",
101
+ "require-table-schema",
102
+ "transaction-nesting"
103
+ ],
104
+ optIn: [
105
+ "ban-add-column",
106
+ "ban-add-composite-attribute",
107
+ "ban-add-enum-value",
108
+ "ban-alter-database-options",
109
+ "ban-alter-extension",
110
+ "ban-alter-function-options",
111
+ "ban-alter-generated-expression",
112
+ "ban-alter-policy-condition",
113
+ "ban-alter-policy-roles",
114
+ "ban-alter-role-options",
115
+ "ban-alter-row-level-security",
116
+ "ban-alter-sequence-values",
117
+ "ban-alter-system-options",
118
+ "ban-alter-view-options",
119
+ "ban-create-policy",
120
+ "ban-detach-inheritance",
121
+ "ban-disable-trigger",
122
+ "ban-drop-index",
123
+ "ban-drop-policy",
124
+ "ban-drop-trigger",
125
+ "ban-new-write-restriction",
126
+ "ban-replace-view-function",
127
+ "ban-replica-identity",
128
+ "ban-revoke",
129
+ "ban-set-default",
130
+ "require-table-schema"
131
+ ],
132
+ aliases: {
133
+ "prefer-timestamptz": ["prefer-timestamp-tz"],
134
+ "require-timeout-settings": ["require-lock-timeout", "require-statement-timeout"]
135
+ }
136
+ };
137
+
138
+ // src/roles/sql/preset-data.ts
139
+ var TARGET = "sql";
140
+ var SQL_CONFIG_FILE = "sql.config.mjs";
141
+ var REPORT_DIR = "sql-report";
142
+ var SCRIPTS = {
143
+ console: "sql",
144
+ json: "sql:json",
145
+ html: "sql:html"
146
+ };
147
+ var defaults = shared_default;
148
+ var squawkRules = squawk_rules_default;
149
+
150
+ // src/roles/sql/configs/define.ts
151
+ function mergeInto(base, patch) {
152
+ if (!isPlainObject(patch)) return base;
153
+ if (!isPlainObject(base)) return patch;
154
+ const out = { ...base };
155
+ for (const [key, value] of Object.entries(patch)) {
156
+ out[key] = isPlainObject(value) ? mergeInto(out[key], value) : value;
157
+ }
158
+ return out;
159
+ }
160
+ function leafPaths(patch, prefix = "") {
161
+ if (!isPlainObject(patch)) return prefix ? [prefix] : [];
162
+ return Object.entries(patch).flatMap(
163
+ ([key, value]) => leafPaths(value, prefix ? `${prefix}.${key}` : key)
164
+ );
165
+ }
166
+ var INPUT_KEYS = ["root", "overrides"];
167
+ function defineSql(input = {}) {
168
+ const unknown = Object.keys(input).filter((key) => !INPUT_KEYS.includes(key));
169
+ if (unknown.length > 0) {
170
+ throw new Error(
171
+ `defineSql takes ${INPUT_KEYS.map((key) => `\`${key}\``).join(" and ")}; ${unknown.map((key) => `\`${key}\``).join(", ")} would be ignored.`
172
+ );
173
+ }
174
+ return {
175
+ ...mergeInto(defaults, input.overrides),
176
+ root: input.root ?? null,
177
+ moved: leafPaths(input.overrides).sort()
178
+ };
179
+ }
180
+
181
+ export {
182
+ TARGET,
183
+ SQL_CONFIG_FILE,
184
+ REPORT_DIR,
185
+ SCRIPTS,
186
+ defaults,
187
+ squawkRules,
188
+ defineSql
189
+ };
190
+ //# sourceMappingURL=chunk-SHF46ALB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/roles/sql/presets/shared.json","../src/roles/sql/presets/squawk-rules.json","../src/roles/sql/preset-data.ts","../src/roles/sql/configs/define.ts"],"sourcesContent":["{\n \"migrations\": {\n \"include\": [\"**/migrations/*/migration.sql\"],\n \"exclude\": []\n },\n \"unsafe\": {\n \"includeTests\": true,\n \"tests\": [\n \"**/{test,tests,__tests__,e2e,fixtures,mocks,__mocks__,test-utils}/**\",\n \"**/*.{spec,test,integration-spec,e2e-spec,steps,test-util,mock}.{ts,mts,cts}\"\n ]\n },\n \"ignore\": [\"**/node_modules/**\", \"**/dist/**\", \"**/coverage/**\"],\n \"pgVersion\": \"16.8\",\n \"rules\": {}\n}\n","{\n \"squawk\": \"2.72.0\",\n \"rules\": [\n \"adding-field-with-default\",\n \"adding-foreign-key-constraint\",\n \"adding-not-nullable-field\",\n \"adding-required-field\",\n \"adding-serial-primary-key-field\",\n \"ban-add-column\",\n \"ban-add-composite-attribute\",\n \"ban-add-enum-value\",\n \"ban-alter-database-options\",\n \"ban-alter-domain-with-add-constraint\",\n \"ban-alter-extension\",\n \"ban-alter-function-options\",\n \"ban-alter-generated-expression\",\n \"ban-alter-identity\",\n \"ban-alter-policy-condition\",\n \"ban-alter-policy-roles\",\n \"ban-alter-role-options\",\n \"ban-alter-row-level-security\",\n \"ban-alter-sequence-values\",\n \"ban-alter-system-options\",\n \"ban-alter-view-options\",\n \"ban-char-field\",\n \"ban-concurrent-index-creation-in-transaction\",\n \"ban-create-domain-with-constraint\",\n \"ban-create-policy\",\n \"ban-detach-inheritance\",\n \"ban-disable-trigger\",\n \"ban-drop-column\",\n \"ban-drop-constraint\",\n \"ban-drop-database\",\n \"ban-drop-default\",\n \"ban-drop-domain\",\n \"ban-drop-extension\",\n \"ban-drop-function\",\n \"ban-drop-generated-expression\",\n \"ban-drop-index\",\n \"ban-drop-not-null\",\n \"ban-drop-policy\",\n \"ban-drop-schema\",\n \"ban-drop-sequence\",\n \"ban-drop-table\",\n \"ban-drop-trigger\",\n \"ban-drop-type\",\n \"ban-drop-view\",\n \"ban-duplicate-column-assignments\",\n \"ban-new-write-restriction\",\n \"ban-replace-view-function\",\n \"ban-replica-identity\",\n \"ban-revoke\",\n \"ban-set-default\",\n \"ban-set-schema\",\n \"ban-truncate-cascade\",\n \"ban-uncommitted-transaction\",\n \"changing-column-type\",\n \"constraint-missing-not-valid\",\n \"disallowed-unique-constraint\",\n \"identifier-too-long\",\n \"prefer-bigint-over-int\",\n \"prefer-bigint-over-smallint\",\n \"prefer-identity\",\n \"prefer-repack\",\n \"prefer-robust-stmts\",\n \"prefer-text-field\",\n \"prefer-timestamp-tz\",\n \"renaming-column\",\n \"renaming-object\",\n \"renaming-table\",\n \"require-concurrent-index-creation\",\n \"require-concurrent-index-deletion\",\n \"require-concurrent-partition-detach\",\n \"require-concurrent-reindex\",\n \"require-enum-value-ordering\",\n \"require-lock-timeout\",\n \"require-statement-timeout\",\n \"require-table-schema\",\n \"transaction-nesting\"\n ],\n \"optIn\": [\n \"ban-add-column\",\n \"ban-add-composite-attribute\",\n \"ban-add-enum-value\",\n \"ban-alter-database-options\",\n \"ban-alter-extension\",\n \"ban-alter-function-options\",\n \"ban-alter-generated-expression\",\n \"ban-alter-policy-condition\",\n \"ban-alter-policy-roles\",\n \"ban-alter-role-options\",\n \"ban-alter-row-level-security\",\n \"ban-alter-sequence-values\",\n \"ban-alter-system-options\",\n \"ban-alter-view-options\",\n \"ban-create-policy\",\n \"ban-detach-inheritance\",\n \"ban-disable-trigger\",\n \"ban-drop-index\",\n \"ban-drop-policy\",\n \"ban-drop-trigger\",\n \"ban-new-write-restriction\",\n \"ban-replace-view-function\",\n \"ban-replica-identity\",\n \"ban-revoke\",\n \"ban-set-default\",\n \"require-table-schema\"\n ],\n \"aliases\": {\n \"prefer-timestamptz\": [\"prefer-timestamp-tz\"],\n \"require-timeout-settings\": [\"require-lock-timeout\", \"require-statement-timeout\"]\n }\n}\n","/**\n * The SQL role's values: what it reads, where it writes, and what a module may move.\n *\n * ## What this role guards, and in which order\n *\n * The study behind it (`docs/sql-verification-study.md`, HUB-45374, issue #150) measured where our\n * SQL lives and set the order, cheapest first:\n *\n * 1. **migrations**, read by squawk. On the monorepo (`main` 0eb8be6550d, 2026-11-14): 871\n * `migration.sql` across 21 modules, 135 of them added by 84 pull requests in five weeks.\n * 2. **the `Unsafe` calls** (`$queryRawUnsafe`, `$executeRawUnsafe`), read by a rule of ours. 226\n * calls the same day: 23 in production code, 203 in tests. And `Prisma.raw`, whose text is SQL\n * inside a tagged query, by the same rule under its own name: 97 calls on `main` f12da701121.\n *\n * 3. **the SQL of tagged templates** (`$queryRaw`, `$executeRaw`, `Prisma.sql`), read with\n * PostgreSQL's own parser (`libpg-query`) by rules of ours, the 19 May incident's first (#178):\n * 1 587 templates on `main` 837abe3f29c, 91 % of the production ones read alone.\n *\n * The ORM chain comes later, in this same role.\n *\n * ## Which modules: the ones that hold SQL, whatever their preset\n *\n * Decided from what the module HOLDS, never from its preset, which is the rule sentinel already\n * follows: the build role reads its own Vite config rather than trusting a preset. A preset says\n * which stack a module is written in, not whether it talks to a database. `libs/nest/signal-bus`\n * is `nest` (its code imports `@nestjs/`) and holds no SQL at all, it carries signals over Redis;\n * `libs/nest/db-main` holds 442 of the 871 migrations. Both are `nest`, and only one concerns this\n * role.\n *\n * So the role applies to every preset, like six of the seven before it, and `--init` skips a module\n * holding neither a migration nor an `Unsafe` call. A front end holds neither, so it is skipped\n * with no line of code about front ends. Measured with dry runs on `apps/front/host-admin`,\n * `libs/front/components`, `libs/nest/signal-bus` (skipped), `libs/nest/db-main` and `network`\n * (adopted).\n */\nimport sharedData from './presets/shared.json'\nimport squawkRulesData from './presets/squawk-rules.json'\n\n/** The target this role serves, and the flag that runs it: `sentinel --run --sql`. */\nexport const TARGET = 'sql'\n\n/** The file a module writes at its root to move a setting. Optional at every moment. */\nexport const SQL_CONFIG_FILE = 'sql.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 = 'sql-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: 'sql',\n json: 'sql:json',\n html: 'sql:html',\n} as const\n\n/** A rule's level. `off` is a module's decision, and the report prints it as one. */\nexport type Severity = 'off' | 'warn' | 'error'\n\nexport interface SqlDefaults {\n /** The migration files squawk reads, as globs relative to the module. */\n migrations: {\n /**\n * ⛔ `migration.sql` BY NAME, and that is what keeps the rollback scripts out. Beside the 871\n * migrations sit 385 `down.sql`, 2 `drop.sql` and one `donw.sql`: scripts a human runs by hand,\n * which Prisma never applies. Reading them would report every `DROP` they are made of, for a\n * file that never reaches production through a deploy. Naming the file Prisma applies, rather\n * than excluding the others, also keeps out the misspelling nobody would think to exclude.\n */\n include: string[]\n /** Migrations a module chooses not to read. Empty by default. */\n exclude: string[]\n }\n /** What the `Unsafe` rule reads. */\n unsafe: {\n /**\n * Read the tests too. ON by default: 203 of the 226 `Unsafe` calls are in tests, and a call\n * that is safe today is not safe by construction tomorrow. A module that decides otherwise sets\n * it to false, and the report says so; the decision is the team's.\n */\n includeTests: boolean\n /**\n * What counts as a test, by PATH. Measured on the monorepo before it was written: the filter\n * `*.spec.*` alone let 149 test calls through as production, because `*.integration-spec.ts`,\n * `*.steps.ts`, `tests/database/` and `*.test-util.ts` are all test code and none of them\n * matches it.\n */\n tests: string[]\n }\n /** Directories never read, whatever the includes say. */\n ignore: string[]\n /**\n * The PostgreSQL version squawk checks against, since some rules depend on it.\n *\n * 16.8 is the version the monorepo pins (`postgres:16.8`, in its integration tests and its\n * database tooling). The role reads what the repository declares and never asks production.\n */\n pgVersion: string\n /**\n * Each rule's level, by name. Empty means every rule at its default, `warn` in this version: the\n * role refuses nothing while its adoption runs.\n */\n rules: Record<string, Severity>\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 `SqlDefaults` above, since JSON carries none.\n */\nexport const defaults: SqlDefaults = sharedData as SqlDefaults\n\n/**\n * squawk's rule names, for the version sentinel pins: what `rules` in `sql.config.mjs` may name.\n *\n * Data about the tool rather than a preset, kept beside the presets like `build`'s\n * `requirements.json`. Taken from squawk's own source at the pinned tag\n * (`crates/squawk_linter/src/lib.rs`, the names a finding carries and `is_opt_in`), and held to the\n * binary by a test: every name here is accepted by the installed squawk, and the version here is\n * the version installed, so a squawk bump that renames a rule fails the build instead of a module.\n *\n * - `rules`, the names findings carry. `unused-ignore` is left out: squawk reports it about its own\n * ignore comments, and refuses it in a config.\n * - `optIn`, the rules squawk runs only when a config names them.\n * - `aliases`, names squawk accepts that no finding carries. A level set on one would never meet a\n * finding, so the role refuses it and names the rule(s) it stands for.\n */\nexport interface SquawkRules {\n squawk: string\n rules: string[]\n optIn: string[]\n aliases: Record<string, string[]>\n}\n\nexport const squawkRules: SquawkRules = squawkRulesData\n","/**\n * `defineSql`: what a module imports to declare its own SQL settings.\n *\n * ```js\n * // sql.config.mjs\n * import { defineSql } from '@hublo/sentinel/sql'\n *\n * export default defineSql({\n * root: import.meta.dirname,\n * overrides: { unsafe: { includeTests: false } },\n * })\n * ```\n *\n * The shape of `defineStaticAnalysis`, for the two reasons stated there. A function receives the\n * module's INTENT, the keys it actually passed, and merges them here, so setting one key never\n * drops its siblings: a spread in the module's file would replace the whole `unsafe` block to set\n * `includeTests`, and lose `tests` with nobody seeing it. And the defaults are never copied into a\n * module, so a changed default reaches every module at the next release instead of leaving stale\n * 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 settings no longer\n * compare, and the reader has to be told.\n */\nimport { isPlainObject } from '../../../shared/deep-merge.js'\nimport { defaults, type SqlDefaults } 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 SqlInput {\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<SqlDefaults>\n}\n\nexport interface ResolvedSqlConfig extends SqlDefaults {\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. `rules` is a record, so\n * a module naming one rule keeps the levels of every other.\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/** The keys `defineSql` reads. */\nconst INPUT_KEYS: readonly string[] = ['root', 'overrides']\n\n/** Resolve a module's declaration against this role's defaults. */\nexport function defineSql(input: SqlInput = {}): ResolvedSqlConfig {\n // ⛔ `override:` for `overrides:` would otherwise resolve to the defaults in silence, the module\n // believing it moved a setting. Thrown, so the loader names the file and the key.\n const unknown = Object.keys(input).filter((key) => !INPUT_KEYS.includes(key))\n if (unknown.length > 0) {\n throw new Error(\n `defineSql takes ${INPUT_KEYS.map((key) => `\\`${key}\\``).join(' and ')}; ` +\n `${unknown.map((key) => `\\`${key}\\``).join(', ')} would be ignored.`,\n )\n }\n return {\n ...mergeInto(defaults, input.overrides),\n root: input.root ?? null,\n moved: leafPaths(input.overrides).sort(),\n }\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,18 @@
1
+ import {
2
+ isPlainObject
3
+ } from "./chunk-PXTU5MPW.js";
4
+
5
+ // src/roles/arch/configs/define.ts
6
+ function defineArch(input = {}) {
7
+ const severity = isPlainObject(input.overrides?.severity) ? { ...input.overrides?.severity } : {};
8
+ return {
9
+ root: input.root ?? null,
10
+ severity,
11
+ moved: Object.keys(severity).map((rule) => `severity.${rule}`).sort()
12
+ };
13
+ }
14
+
15
+ export {
16
+ defineArch
17
+ };
18
+ //# sourceMappingURL=chunk-TMVKYXZ3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/roles/arch/configs/define.ts"],"sourcesContent":["/**\n * `defineArch`: what a module imports to declare its own architecture settings.\n *\n * ```js\n * // arch.config.mjs\n * import { defineArch } from '@hublo/sentinel/arch'\n *\n * export default defineArch({\n * root: import.meta.dirname,\n * overrides: { severity: { G3: 'warn' } },\n * })\n * ```\n *\n * The shape of `defineStaticAnalysis` and `defineSql`, as CONTRIBUTING asks of every analysis role.\n * Which decision applies is not here: the repository's map says it, so a module cannot point\n * itself at another rule set. What a module may move is how hard each rule bites in it.\n *\n * `overrides` REPLACES what it names, and every path it sets lands in `moved`, so the report says\n * a level is the module's own and not the decision's.\n */\nimport { isPlainObject } from '../../../shared/deep-merge.js'\n\n/** A rule's level in one module: `off` skips it, which no rule set may say. */\nexport type ModuleSeverity = 'error' | 'warn' | 'off'\n\n/** What a module may move. */\nexport interface ArchOverrides {\n /** A level per rule, by the rule's name in the decision's rule set. */\n severity?: Record<string, ModuleSeverity>\n}\n\n/** What a module's config file passes. Everything is optional, including the file itself. */\nexport interface ArchInput {\n /** The module's own directory, normally `import.meta.dirname`. */\n root?: string\n overrides?: ArchOverrides\n}\n\nexport interface ResolvedArchConfig {\n /** The module's directory, or null when its config file did not say. */\n root: string | null\n /** The levels the module set, by rule. The others come from the map, then the rule set. */\n severity: Record<string, ModuleSeverity>\n /** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */\n moved: string[]\n}\n\n/** Resolve a module's declaration. */\nexport function defineArch(input: ArchInput = {}): ResolvedArchConfig {\n const severity = isPlainObject(input.overrides?.severity)\n ? { ...(input.overrides?.severity as Record<string, ModuleSeverity>) }\n : {}\n return {\n root: input.root ?? null,\n severity,\n moved: Object.keys(severity)\n .map((rule) => `severity.${rule}`)\n .sort(),\n }\n}\n"],"mappings":";;;;;AAgDO,SAAS,WAAW,QAAmB,CAAC,GAAuB;AACpE,QAAM,WAAW,cAAc,MAAM,WAAW,QAAQ,IACpD,EAAE,GAAI,MAAM,WAAW,SAA4C,IACnE,CAAC;AACL,SAAO;AAAA,IACL,MAAM,MAAM,QAAQ;AAAA,IACpB;AAAA,IACA,OAAO,OAAO,KAAK,QAAQ,EACxB,IAAI,CAAC,SAAS,YAAY,IAAI,EAAE,EAChC,KAAK;AAAA,EACV;AACF;","names":[]}
@@ -0,0 +1,126 @@
1
+ import {
2
+ isPlainObject
3
+ } from "./chunk-PXTU5MPW.js";
4
+
5
+ // src/roles/code-churn/presets/shared.json
6
+ var shared_default = {
7
+ window: {
8
+ reworkDays: 21,
9
+ periodDays: 90
10
+ },
11
+ maxFilesPerCommit: 100,
12
+ levels: {
13
+ minimumAdded: 500,
14
+ low: 3,
15
+ above: 11,
16
+ watch: 16
17
+ },
18
+ include: ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,svelte,vue}"],
19
+ includeTests: false,
20
+ tests: [
21
+ "**/{test,tests,__tests__,e2e,fixtures,mocks,__mocks__,test-utils}/**",
22
+ "**/*.{spec,test,integration-spec,e2e-spec,steps,test-util,mock}.{ts,tsx,mts,cts,js,jsx}"
23
+ ],
24
+ ignore: [
25
+ "**/node_modules/**",
26
+ "**/dist/**",
27
+ "**/build/**",
28
+ "**/coverage/**",
29
+ "**/*.d.{ts,mts,cts}",
30
+ "**/*.generated.*",
31
+ "**/*.gen.*",
32
+ "**/generated/**"
33
+ ],
34
+ listed: 10
35
+ };
36
+
37
+ // src/roles/code-churn/preset-data.ts
38
+ var TARGET = "code-churn";
39
+ var CODE_CHURN_CONFIG_FILE = "code-churn.config.mjs";
40
+ var REPORT_DIR = "code-churn-report";
41
+ var SCRIPTS = {
42
+ console: "code-churn",
43
+ json: "code-churn:json",
44
+ html: "code-churn:html"
45
+ };
46
+ var defaults = shared_default;
47
+
48
+ // src/roles/code-churn/configs/define.ts
49
+ function mergeInto(base, patch) {
50
+ if (!isPlainObject(patch)) return base;
51
+ if (!isPlainObject(base)) return patch;
52
+ const out = { ...base };
53
+ for (const [key, value] of Object.entries(patch)) {
54
+ out[key] = isPlainObject(value) ? mergeInto(out[key], value) : value;
55
+ }
56
+ return out;
57
+ }
58
+ function leafPaths(patch, prefix = "") {
59
+ if (!isPlainObject(patch)) return prefix ? [prefix] : [];
60
+ return Object.entries(patch).flatMap(
61
+ ([key, value]) => leafPaths(value, prefix ? `${prefix}.${key}` : key)
62
+ );
63
+ }
64
+ function defineCodeChurn(input = {}) {
65
+ return {
66
+ ...mergeInto(defaults, input.overrides),
67
+ root: input.root ?? null,
68
+ moved: leafPaths(input.overrides).sort()
69
+ };
70
+ }
71
+ function invalidSettings(config) {
72
+ const problems = [];
73
+ const positive = (path, value) => {
74
+ if (!Number.isInteger(value) || value < 1) {
75
+ problems.push(`${path} must be a whole number of 1 or more, got ${JSON.stringify(value)}`);
76
+ }
77
+ };
78
+ const strings = (path, value, allowEmpty) => {
79
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
80
+ problems.push(`${path} must be a list of globs, got ${JSON.stringify(value)}`);
81
+ } else if (!allowEmpty && value.length === 0) {
82
+ problems.push(`${path} must name at least one glob, or nothing is measured`);
83
+ }
84
+ };
85
+ positive("window.reworkDays", config.window?.reworkDays);
86
+ positive("window.periodDays", config.window?.periodDays);
87
+ positive("maxFilesPerCommit", config.maxFilesPerCommit);
88
+ positive("levels.minimumAdded", config.levels?.minimumAdded);
89
+ const percentage = (path, value) => {
90
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0 || value > 100) {
91
+ problems.push(
92
+ `${path} must be a percentage above 0 and at most 100, got ${JSON.stringify(value)}`
93
+ );
94
+ }
95
+ };
96
+ percentage("levels.low", config.levels?.low);
97
+ percentage("levels.above", config.levels?.above);
98
+ percentage("levels.watch", config.levels?.watch);
99
+ const { low, above, watch } = config.levels ?? {};
100
+ if (typeof low === "number" && typeof above === "number" && typeof watch === "number" && !(low < above && above < watch)) {
101
+ problems.push(`levels must rise: low < above < watch, got ${low}, ${above}, ${watch}`);
102
+ }
103
+ if (!Number.isInteger(config.listed) || config.listed < 0) {
104
+ problems.push(
105
+ `listed must be a whole number of 0 or more, got ${JSON.stringify(config.listed)}`
106
+ );
107
+ }
108
+ if (typeof config.includeTests !== "boolean") {
109
+ problems.push(`includeTests must be true or false, got ${JSON.stringify(config.includeTests)}`);
110
+ }
111
+ strings("include", config.include, false);
112
+ strings("tests", config.tests, true);
113
+ strings("ignore", config.ignore, true);
114
+ return problems;
115
+ }
116
+
117
+ export {
118
+ TARGET,
119
+ CODE_CHURN_CONFIG_FILE,
120
+ REPORT_DIR,
121
+ SCRIPTS,
122
+ defaults,
123
+ defineCodeChurn,
124
+ invalidSettings
125
+ };
126
+ //# sourceMappingURL=chunk-XYOIXC6A.js.map
@@ -0,0 +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 \"levels\": {\n \"minimumAdded\": 500,\n \"low\": 3,\n \"above\": 11,\n \"watch\": 16\n },\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 \"**/*.gen.*\",\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 /**\n * Where a module's figure stands, in percent, and below how many added lines it has none.\n *\n * Calibrated on hublo/monorepo `main` f12da701121 (2026-07-28 to 2026-10-26): of the 113 sentinel\n * modules, 33 added no line and 44 fewer than 500 (26 in the median), where one rewrite moves the\n * figure by points; over the 36 others, the 25th, 75th and 90th percentiles are 3.1, 11.4 and\n * 15.9%, rounded DOWN to 3, 11 and 16. They say where a module stands among those modules, never\n * whether its code is good, and are recalibrated by a sweep at each stable release.\n */\n levels: {\n /** Below this many lines added in the period, the module is `quiet`: no percentage stated. */\n minimumAdded: number\n /** Under this, `low`. */\n low: number\n /** Over this, `above`. Between `low` and it, `usual`. */\n above: number\n /** Over this, `watch`. */\n watch: number\n }\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 /**\n * Files never measured, whatever `include` says: generated and built output. `*.gen.*` is\n * TanStack Router's `routeTree.gen.ts`, regenerated on every route change (career, console and\n * host-admin on hublo/monorepo): measured, it was one of host-admin's most changed files.\n */\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, levels that do not rise put every module in two bands at once, and\n * 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 positive('levels.minimumAdded', config.levels?.minimumAdded)\n const percentage = (path: string, value: unknown): void => {\n if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0 || value > 100) {\n problems.push(\n `${path} must be a percentage above 0 and at most 100, got ${JSON.stringify(value)}`,\n )\n }\n }\n percentage('levels.low', config.levels?.low)\n percentage('levels.above', config.levels?.above)\n percentage('levels.watch', config.levels?.watch)\n const { low, above, watch } = config.levels ?? {}\n if (\n typeof low === 'number' &&\n typeof above === 'number' &&\n typeof watch === 'number' &&\n !(low < above && above < watch)\n ) {\n problems.push(`levels must rise: low < above < watch, got ${low}, ${above}, ${watch}`)\n }\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":"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","names":[]}
@@ -180,9 +180,24 @@ function ensureReleaseAgeAllowList(root, dryRun) {
180
180
  return `allow-listed ${own} under ${RELEASE_AGE_KEY} in ${WORKSPACE_YAML}`;
181
181
  }
182
182
  var GIT_IGNORE = ".gitignore";
183
- var REPORT_DIR_NAME = "static-analysis-report";
184
- var REPORT_PATTERN = `${REPORT_DIR_NAME}/`;
185
- var REPORT_HEADER = "# @hublo/sentinel: static analysis reports, written inside each module";
183
+ var REPORT_DIRS = {
184
+ "static-analysis": {
185
+ dir: "static-analysis-report",
186
+ header: "# @hublo/sentinel: static analysis reports, written inside each module",
187
+ label: "the static analysis role"
188
+ },
189
+ sql: {
190
+ dir: "sql-report",
191
+ header: "# @hublo/sentinel: sql reports, written inside each module",
192
+ label: "the sql role"
193
+ },
194
+ "code-churn": {
195
+ dir: "code-churn-report",
196
+ header: "# @hublo/sentinel: code churn reports, written inside each module",
197
+ label: "the code churn role"
198
+ }
199
+ };
200
+ var ignores = (text, dir) => text.split("\n").some((line) => line.trim().replace(/^\//, "").replace(/\/$/, "") === dir);
186
201
  var PRETTIER_IGNORE = ".prettierignore";
187
202
  var EXCLUSION_HEADER = "# @hublo/sentinel: modules formatted by oxfmt, not by the root Prettier";
188
203
  var ROOT_PRETTIER_CONFIGS = [
@@ -230,19 +245,21 @@ ${pattern}
230
245
  }
231
246
  return `excluded ${rel} from the root Prettier (${PRETTIER_IGNORE}): it formats itself now`;
232
247
  }
233
- function ensureReportIgnored(root, dryRun) {
248
+ function ensureReportIgnored(root, role, dryRun) {
249
+ const entry = REPORT_DIRS[role];
250
+ if (entry === void 0) return void 0;
251
+ const pattern = `${entry.dir}/`;
234
252
  const path = join2(root, GIT_IGNORE);
235
253
  const existing = existsSync2(path) ? readFileSync2(path, "utf8") : "";
236
- const already = existing.split("\n").some((line) => line.trim().replace(/^\//, "").replace(/\/$/, "") === REPORT_DIR_NAME);
237
- if (already) return void 0;
238
- if (dryRun) return `would ignore ${REPORT_PATTERN} in the root ${GIT_IGNORE}`;
254
+ if (ignores(existing, entry.dir)) return void 0;
255
+ if (dryRun) return `would ignore ${pattern} in the root ${GIT_IGNORE}`;
239
256
  const prefix = existing.trim() === "" ? "" : `${existing.replace(/\n*$/, "")}
240
257
 
241
258
  `;
242
- writeFileSync(path, `${prefix}${REPORT_HEADER}
243
- ${REPORT_PATTERN}
259
+ writeFileSync(path, `${prefix}${entry.header}
260
+ ${pattern}
244
261
  `);
245
- return `ignored ${REPORT_PATTERN} in the root ${GIT_IGNORE}`;
262
+ return `ignored ${pattern} in the root ${GIT_IGNORE}`;
246
263
  }
247
264
  function ensureWorkspacePrep(opts) {
248
265
  const dryRun = Boolean(opts.dryRun);
@@ -250,7 +267,7 @@ function ensureWorkspacePrep(opts) {
250
267
  ensureI18nextSingleton(opts.root, dryRun),
251
268
  ensureReleaseAgeAllowList(opts.root, dryRun),
252
269
  opts.formattedModule === void 0 ? void 0 : ensureFormatterExclusion(opts.root, opts.formattedModule, dryRun),
253
- opts.analysedModule === true ? ensureReportIgnored(opts.root, dryRun) : void 0
270
+ ...Object.keys(REPORT_DIRS).filter((role) => opts.adoptedRoles?.includes(role) === true).map((role) => ensureReportIgnored(opts.root, role, dryRun))
254
271
  ].filter((message) => message !== void 0);
255
272
  }
256
273
  function inspectWorkspacePrep(root) {
@@ -283,11 +300,13 @@ function inspectWorkspacePrep(root) {
283
300
  }
284
301
  const ignorePath = join2(root, GIT_IGNORE);
285
302
  if (existsSync2(ignorePath)) {
286
- const ignored = readFileSync2(ignorePath, "utf8").split("\n").some((line) => line.trim().replace(/^\//, "").replace(/\/$/, "") === REPORT_DIR_NAME);
287
- if (ignored) {
303
+ const ignoreText = readFileSync2(ignorePath, "utf8");
304
+ for (const [role, entry] of Object.entries(REPORT_DIRS)) {
305
+ if (!ignores(ignoreText, entry.dir)) continue;
306
+ const pattern = `${entry.dir}/`;
288
307
  entries.push({
289
- rule: `${GIT_IGNORE} \u2192 ${REPORT_PATTERN}`,
290
- reason: `the static analysis role writes its json and html into \`<module>/${REPORT_PATTERN}\`, and one unanchored line at the root covers every module instead of creating a \`${GIT_IGNORE}\` in each one. Unlike the override above it changes no resolution and no build, so a stale one costs a single unused line. It retires when no module declares a \`static-analysis\` script any more, which the adoption report counts and this read deliberately does not: it would have to sweep every module.`
308
+ rule: `${GIT_IGNORE} \u2192 ${pattern}`,
309
+ reason: `${entry.label} writes its report files into \`<module>/${pattern}\`, and one unanchored line at the root covers every module instead of creating a \`${GIT_IGNORE}\` in each one. Unlike the override above it changes no resolution and no build, so a stale one costs a single unused line. It retires when no module declares a \`${role}\` script any more, which the adoption report counts and this read deliberately does not: it would have to sweep every module.`
291
310
  });
292
311
  }
293
312
  }
@@ -318,4 +337,4 @@ export {
318
337
  ensureWorkspacePrep,
319
338
  inspectWorkspacePrep
320
339
  };
321
- //# sourceMappingURL=chunk-ZNANJEMK.js.map
340
+ //# sourceMappingURL=chunk-YUZB4LRJ.js.map