@hailstails/hone 0.0.0-stage → 0.1.0-pre.2

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 (186) hide show
  1. package/ADOPTING.md +314 -0
  2. package/LICENSE +17 -0
  3. package/MIGRATING.md +238 -0
  4. package/README.md +216 -2
  5. package/THIRD-PARTY-NOTICES.md +354 -0
  6. package/chunks/chunk-233U4FBA.js +42 -0
  7. package/chunks/chunk-7ZJZZBSS.js +14909 -0
  8. package/chunks/chunk-HBY4ZWSP.js +79 -0
  9. package/chunks/chunk-HJA4CX7C.js +24 -0
  10. package/chunks/chunk-NZLE2WMY.js +35 -0
  11. package/chunks/chunk-QWA6OVLC.js +11 -0
  12. package/chunks/chunk-TRCB27ET.js +202 -0
  13. package/core/check/tool-command.js +2305 -0
  14. package/docs/adding-a-discipline-or-mechanism.md +195 -0
  15. package/docs/why-chain-contract.md +78 -0
  16. package/mechanisms/audit/CD-1/any-cast.js +81 -0
  17. package/mechanisms/audit/CD-1/piece.json +13 -0
  18. package/mechanisms/audit/CD-10/piece.json +13 -0
  19. package/mechanisms/audit/CD-10/throws-in-tests.js +49 -0
  20. package/mechanisms/audit/CD-14/class-syntax.js +70 -0
  21. package/mechanisms/audit/CD-14/piece.json +13 -0
  22. package/mechanisms/audit/CD-15/loops.js +40 -0
  23. package/mechanisms/audit/CD-15/piece.json +13 -0
  24. package/mechanisms/audit/CD-17/clock-sources.js +29 -0
  25. package/mechanisms/audit/CD-17/piece.json +13 -0
  26. package/mechanisms/audit/CD-19/import-boundaries.js +80 -0
  27. package/mechanisms/audit/CD-19/piece.json +13 -0
  28. package/mechanisms/audit/CD-2/cast-expressions.js +81 -0
  29. package/mechanisms/audit/CD-2/piece.json +13 -0
  30. package/mechanisms/audit/CD-23/export-test-sibling.js +56 -0
  31. package/mechanisms/audit/CD-23/piece.json +13 -0
  32. package/mechanisms/audit/CD-25/dependency-isolation.js +53 -0
  33. package/mechanisms/audit/CD-25/piece.json +13 -0
  34. package/mechanisms/audit/CD-26/module-mocking.js +51 -0
  35. package/mechanisms/audit/CD-26/piece.json +13 -0
  36. package/mechanisms/audit/CD-27/piece.json +13 -0
  37. package/mechanisms/audit/CD-27/test-body-logic.js +107 -0
  38. package/mechanisms/audit/CD-3/compiler-overrides.js +955 -0
  39. package/mechanisms/audit/CD-3/piece.json +49 -0
  40. package/mechanisms/audit/CD-43/boolean-signatures.js +55 -0
  41. package/mechanisms/audit/CD-43/piece.json +13 -0
  42. package/mechanisms/audit/CD-44/parameter-mutation.js +92 -0
  43. package/mechanisms/audit/CD-44/piece.json +13 -0
  44. package/mechanisms/audit/CD-47/hermetic-git-spawns.js +44 -0
  45. package/mechanisms/audit/CD-47/piece.json +13 -0
  46. package/mechanisms/audit/CD-5/comments-directives.js +73 -0
  47. package/mechanisms/audit/CD-5/piece.json +13 -0
  48. package/mechanisms/audit/CD-6/identifier-names.js +132 -0
  49. package/mechanisms/audit/CD-6/piece.json +13 -0
  50. package/mechanisms/audit/CD-7/categorical-paths.js +55 -0
  51. package/mechanisms/audit/CD-7/piece.json +13 -0
  52. package/mechanisms/audit/CD-7a/factory-return-types.js +42 -0
  53. package/mechanisms/audit/CD-7a/piece.json +13 -0
  54. package/mechanisms/audit/CD-8/piece.json +13 -0
  55. package/mechanisms/audit/CD-8/switch-defaults.js +43 -0
  56. package/mechanisms/audit/runner/README.md +38 -0
  57. package/mechanisms/audit/runner/runner.js +546 -0
  58. package/mechanisms/eslint/CD-1/README.md +12 -0
  59. package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +50 -0
  60. package/mechanisms/eslint/CD-1/piece.json +23 -0
  61. package/mechanisms/eslint/CD-10/README.md +9 -0
  62. package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +55 -0
  63. package/mechanisms/eslint/CD-10/piece.json +15 -0
  64. package/mechanisms/eslint/CD-14/README.md +11 -0
  65. package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +88 -0
  66. package/mechanisms/eslint/CD-14/piece.json +31 -0
  67. package/mechanisms/eslint/CD-27/README.md +12 -0
  68. package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +83 -0
  69. package/mechanisms/eslint/CD-27/piece.json +23 -0
  70. package/mechanisms/eslint/CD-40/README.md +7 -0
  71. package/mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js +16 -0
  72. package/mechanisms/eslint/CD-40/piece.json +21 -0
  73. package/mechanisms/eslint/CD-41/README.md +12 -0
  74. package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +228 -0
  75. package/mechanisms/eslint/CD-41/piece.json +23 -0
  76. package/mechanisms/eslint/CD-42/README.md +9 -0
  77. package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +75 -0
  78. package/mechanisms/eslint/CD-42/piece.json +15 -0
  79. package/mechanisms/eslint/CD-44/README.md +7 -0
  80. package/mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js +16 -0
  81. package/mechanisms/eslint/CD-44/piece.json +20 -0
  82. package/mechanisms/eslint/CD-6/README.md +9 -0
  83. package/mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js +16 -0
  84. package/mechanisms/eslint/CD-6/piece.json +217 -0
  85. package/mechanisms/eslint/CD-7/README.md +9 -0
  86. package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +52 -0
  87. package/mechanisms/eslint/CD-7/piece.json +15 -0
  88. package/mechanisms/eslint/runner/README.md +43 -0
  89. package/mechanisms/eslint/runner/runner.js +4248 -0
  90. package/methods/README.md +18 -0
  91. package/methods/lenses/clean-architecture.md +167 -0
  92. package/methods/lenses/decomposition.md +159 -0
  93. package/methods/lenses/defended-on-intent.md +178 -0
  94. package/methods/lenses/di-discipline.md +156 -0
  95. package/methods/lenses/errors-as-data.md +88 -0
  96. package/methods/lenses/function-first.md +193 -0
  97. package/methods/lenses/naming.md +127 -0
  98. package/methods/lenses/test-discipline.md +166 -0
  99. package/methods/lenses/type-soundness.md +135 -0
  100. package/methods/lenses/zod-boundary.md +158 -0
  101. package/package.json +65 -4
  102. package/rules/CD-1/README.md +43 -0
  103. package/rules/CD-1/discipline.json +185 -0
  104. package/rules/CD-10/README.md +55 -0
  105. package/rules/CD-10/discipline.json +133 -0
  106. package/rules/CD-11/README.md +19 -0
  107. package/rules/CD-11/discipline.json +12 -0
  108. package/rules/CD-12/README.md +19 -0
  109. package/rules/CD-12/discipline.json +12 -0
  110. package/rules/CD-13/README.md +19 -0
  111. package/rules/CD-13/discipline.json +12 -0
  112. package/rules/CD-14/README.md +54 -0
  113. package/rules/CD-14/discipline.json +173 -0
  114. package/rules/CD-15/README.md +48 -0
  115. package/rules/CD-15/discipline.json +73 -0
  116. package/rules/CD-16/README.md +17 -0
  117. package/rules/CD-17/README.md +42 -0
  118. package/rules/CD-17/discipline.json +51 -0
  119. package/rules/CD-18/README.md +19 -0
  120. package/rules/CD-18/discipline.json +12 -0
  121. package/rules/CD-19/README.md +45 -0
  122. package/rules/CD-19/discipline.json +65 -0
  123. package/rules/CD-2/README.md +43 -0
  124. package/rules/CD-2/discipline.json +65 -0
  125. package/rules/CD-20/README.md +17 -0
  126. package/rules/CD-21/README.md +19 -0
  127. package/rules/CD-21/discipline.json +12 -0
  128. package/rules/CD-22/README.md +19 -0
  129. package/rules/CD-22/discipline.json +12 -0
  130. package/rules/CD-23/README.md +41 -0
  131. package/rules/CD-23/discipline.json +57 -0
  132. package/rules/CD-24/README.md +17 -0
  133. package/rules/CD-25/README.md +43 -0
  134. package/rules/CD-25/discipline.json +57 -0
  135. package/rules/CD-26/README.md +42 -0
  136. package/rules/CD-26/discipline.json +57 -0
  137. package/rules/CD-27/README.md +51 -0
  138. package/rules/CD-27/discipline.json +233 -0
  139. package/rules/CD-28/README.md +19 -0
  140. package/rules/CD-28/discipline.json +12 -0
  141. package/rules/CD-29/README.md +19 -0
  142. package/rules/CD-29/discipline.json +12 -0
  143. package/rules/CD-3/README.md +48 -0
  144. package/rules/CD-3/discipline.json +363 -0
  145. package/rules/CD-30/README.md +19 -0
  146. package/rules/CD-30/discipline.json +12 -0
  147. package/rules/CD-31/README.md +19 -0
  148. package/rules/CD-31/discipline.json +12 -0
  149. package/rules/CD-32/README.md +19 -0
  150. package/rules/CD-32/discipline.json +12 -0
  151. package/rules/CD-33/README.md +19 -0
  152. package/rules/CD-33/discipline.json +12 -0
  153. package/rules/CD-34/README.md +19 -0
  154. package/rules/CD-34/discipline.json +12 -0
  155. package/rules/CD-39/README.md +19 -0
  156. package/rules/CD-39/discipline.json +12 -0
  157. package/rules/CD-4/README.md +19 -0
  158. package/rules/CD-4/discipline.json +12 -0
  159. package/rules/CD-40/README.md +45 -0
  160. package/rules/CD-40/discipline.json +58 -0
  161. package/rules/CD-41/README.md +60 -0
  162. package/rules/CD-41/discipline.json +124 -0
  163. package/rules/CD-42/README.md +53 -0
  164. package/rules/CD-42/discipline.json +61 -0
  165. package/rules/CD-43/README.md +43 -0
  166. package/rules/CD-43/discipline.json +65 -0
  167. package/rules/CD-44/README.md +54 -0
  168. package/rules/CD-44/discipline.json +111 -0
  169. package/rules/CD-45/README.md +19 -0
  170. package/rules/CD-45/discipline.json +12 -0
  171. package/rules/CD-46/README.md +13 -0
  172. package/rules/CD-47/README.md +47 -0
  173. package/rules/CD-47/discipline.json +57 -0
  174. package/rules/CD-5/README.md +46 -0
  175. package/rules/CD-5/discipline.json +65 -0
  176. package/rules/CD-6/README.md +57 -0
  177. package/rules/CD-6/discipline.json +165 -0
  178. package/rules/CD-7/README.md +52 -0
  179. package/rules/CD-7/discipline.json +142 -0
  180. package/rules/CD-7a/README.md +44 -0
  181. package/rules/CD-7a/discipline.json +57 -0
  182. package/rules/CD-8/README.md +48 -0
  183. package/rules/CD-8/discipline.json +57 -0
  184. package/rules/CD-9/README.md +19 -0
  185. package/rules/CD-9/discipline.json +12 -0
  186. package/rules/README.md +52 -0
@@ -0,0 +1,195 @@
1
+ # Adding a discipline or a mechanism
2
+
3
+ Core names no discipline and no mechanism, so adding either one is a matter of adding files in the right places. This guide lists those files, the import boundaries they must keep, and, for a mechanism with its own exception formats, how each format maps to an exception kind.
4
+
5
+ Terms used below:
6
+
7
+ - A **discipline** is a rule a repository can adopt, with an id such as `CD-14`, made of one or more **clauses**.
8
+ - A **mechanism** is a tool that checks clauses, such as the TypeScript `audit` or `eslint`. Each mechanism has one **runner**.
9
+ - A **piece** is one discipline's code for one mechanism, written in that mechanism's own extension format.
10
+ - A **rule set** is a directory holding `rules/` and `mechanisms/` folders. The rule set shipped with core is `shared`; a repository can add its own and name them in `disciplines.json`.
11
+ - A **native channel** is a way the tool itself lets a team exempt or weaken a rule, outside core's exception records.
12
+
13
+ ## Adding a discipline
14
+
15
+ ### 1. The discipline file
16
+
17
+ Create `rules/<DisciplineId>/discipline.json` in a rule set. The id is two to four capital letters, a hyphen and a number, with an optional lower-case letter (`CD-14`, `PD-1`, `CD-7a`), and must match the folder name.
18
+
19
+ ```json
20
+ {
21
+ "version": 1,
22
+ "id": "PD-1",
23
+ "clauses": [ ]
24
+ }
25
+ ```
26
+
27
+ Each clause is either mechanical or judgement:
28
+
29
+ - A **mechanical** clause has `id`, `summary`, `mechanisms` (the mechanism ids allowed to check it), `anchor` and `cases`. `anchor` is `{ "kind": "keyword", "keyword": "<token>" }` when hits sit on a token in the source, or `{ "kind": "file" }` for a clause about a path, whose hits are at line 1, column 0.
30
+ - A **judgement** clause has `id`, `summary` and `"enforcedBy": "review"`. It records the requirement but cannot be selected; review enforces it.
31
+
32
+ Clause ids are lower-case words joined by hyphens, and are unique within the discipline.
33
+
34
+ ### 2. The shared cases
35
+
36
+ A mechanical clause's `cases` hold `flag` and `allow` lists. Each case is `{ "name", "fileName", "source", "expectedLines" }`: a flag case lists the lines that must be flagged (at least one), and an allow case lists none. `fileName` is a repository path and may be a declaration file such as `x.d.ts`. There must be at least one of each.
37
+
38
+ The cases are shared by every mechanism the clause lists. A mechanism conforms for a clause when, run over each case's source, it flags exactly the expected lines. That is how two mechanisms are held to the same verdict: CD-14's `class-syntax` cases are run through both the walker and the ESLint runner.
39
+
40
+ ### 3. A piece per mechanism
41
+
42
+ For each mechanism in a clause's `mechanisms` list, add a piece folder `mechanisms/<MechanismId>/<DisciplineId>/` in the same rule set, holding `piece.json` and the piece's source.
43
+
44
+ ```json
45
+ {
46
+ "version": 1,
47
+ "discipline": "PD-1",
48
+ "mechanism": "audit",
49
+ "clauses": [{ "clause": "no-tmp-files", "settings": { "module": "no-tmp-files.ts" } }]
50
+ }
51
+ ```
52
+
53
+ `discipline` and `mechanism` must match the folder names, every `clause` must exist in the discipline, and no clause may appear twice. Core reads only this envelope. `settings` belongs to the runner, which parses it with its own schema:
54
+
55
+ - **audit:** `{ "module": "<file>.ts" }`, a path inside the piece folder; a `.js` module is accepted too, which is what the built package's pieces name. The module exports `check`, typed with `import type { WalkerPiece }` from `mechanisms/audit/runner/walker-piece.ts`. See `mechanisms/audit/runner/README.md`.
56
+ - **eslint:** `{ "pluginNamespace", "pluginModule", "rule" }`. `pluginModule` is a `.ts` or `.js` path inside the piece folder whose default export is an ESLint plugin; `rule` must be a key of its `rules`. The rule id is `<pluginNamespace>/<rule>`. The namespace `hone-core` is reserved for Hone's own machinery, and two selected clauses may not share a rule id, or a namespace with different plugin modules. CD-14's piece is `mechanisms/eslint/CD-14/piece.json`, pointing at the rule `no-class-authoring` in `cd14/cd14.eslint-plugin.ts` under the namespace `hone`.
57
+
58
+ A runner reports a bad `settings` value, a module that fails to load or does not match its schema, or a missing rule as `piece-invalid`.
59
+
60
+ ### 4. Tests
61
+
62
+ Give each piece source file a co-located `.test.ts`. A piece's test runs the clause's shared cases through its runner and checks the flagged lines:
63
+
64
+ - an audit piece calls `conform` on an audit runner (`mechanisms/audit/CD-14/class-syntax.test.ts` builds one with `createWalkerRunner` and the real TypeScript parse port);
65
+ - an ESLint piece calls the ESLint port's `lintSourceCases` with its plugin (`mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.test.ts`).
66
+
67
+ A path-only audit piece reads no source, so its test can prepare `check` and call `prepareFile` directly on each path, as the probe's does. The runner's own suite runs core's `checkConformance` over every shared piece it serves (see "Adding a mechanism", step 4). FR-8's import checks (below) cover the new files with no change.
68
+
69
+ ### Worked example: the probe discipline
70
+
71
+ `tests/probe-rule-set/` is a test-only rule set, named `probe`, holding one discipline written exactly as a team would write its own. It was added beside CD-14 with no change to core or to the audit runner.
72
+
73
+ - `tests/probe-rule-set/rules/PD-1/discipline.json` declares one mechanical clause, `no-tmp-files`: mechanisms `["audit"]`, anchor `{ "kind": "file" }`, one flag case (`src/scratch.tmp.ts`, line 1) and one allow case (`src/kept.ts`, no lines).
74
+ - `tests/probe-rule-set/mechanisms/audit/PD-1/piece.json` maps that clause to the module `no-tmp-files.ts`.
75
+ - `tests/probe-rule-set/mechanisms/audit/PD-1/no-tmp-files.ts` exports `check`, an audit piece that completes each file from its path alone: a hit at line 1 for a path ending `.tmp.ts`, none otherwise. It reads no file, so the walker never parses on its behalf.
76
+ - `no-tmp-files.test.ts` tests `check` directly; the probe has no conformance test of its own.
77
+ - The piece imports only a type, `WalkerPiece`, from the audit runner, as a path relative to its own file. Type imports are erased when Node runs the source, so the path matters only to typechecking.
78
+
79
+ A repository selects it by naming the rule set and the clause:
80
+
81
+ ```json
82
+ {
83
+ "version": 1,
84
+ "ruleSets": { "probe": "probe" },
85
+ "clauses": { "probe/PD-1#no-tmp-files": "audit", "CD-23#export-test-sibling": "audit" }
86
+ }
87
+ ```
88
+
89
+ `tests/probe-check.integration.test.ts` runs that selection: the probe flags `src/scratch.tmp.ts`, CD-23 flags `src/kept.ts` for its missing test sibling, and the audit runner parses each file once even though two disciplines are selected.
90
+
91
+ ## Adding a mechanism
92
+
93
+ ### 1. The runner
94
+
95
+ Create `mechanisms/<MechanismId>/runner/runner.ts`. The id is lower-case words joined by hyphens. The module has one named export, `runner`, built by a factory in its own file so the runner's tests can call the factory with fakes. The ESLint runner's `runner.ts`:
96
+
97
+ ```ts
98
+ export const runner = toolchainBoundEmbeddedRunner({
99
+ toolchain: loadEslintToolchain({ peers: defaultEslintToolchainPeers }),
100
+ projectedKinds: ESLINT_PROJECTED_KINDS,
101
+ runnerOf: (toolchain) =>
102
+ createEslintRunner({
103
+ fileText: createDefaultFileTextPort({}),
104
+ modules: createDefaultModuleLoaderPort({}),
105
+ path: createDefaultPathPort({}),
106
+ eslint: createEslintPort({ toolchain }),
107
+ }),
108
+ });
109
+ ```
110
+
111
+ A runner whose tool comes from the adopting repository declares that tool as a peer dependency with a `ToolchainRequirement` that says whether the peer is `required`, as `typescript` is for the audit mechanism, or `optional`, as the ESLint toolchain is, matching the package's `peerDependenciesMeta`, and whose floor is the oldest release its API use is tested on, and is given a `PeerToolchain`: the package location port (`core/platform-ports/package-location-port.ts`) and a dynamic import per package. It loads each package through `loadedPeer` (`core/mechanism-port/toolchain-requirement.ts`) and binds itself to the result with `toolchainBoundStandaloneRunner` or `toolchainBoundEmbeddedRunner` (`core/mechanism-port/toolchain-bound-runner.ts`), which build the runner once. A missing, unloadable or out-of-range tool is the failure `toolchain-unavailable`, and one that resolves from inside the installed core package is `toolchain-shadowed`, both before any piece loads.
112
+
113
+ Core loads `runner.ts` once per check and parses the export with its own schema (`core/mechanism-port/runner-module-schema.ts`). An unknown exception path, a missing member or a member that is not a function is the load failure `runner-invalid`. Core also parses everything a runner returns; a value outside its schema, a hit for a clause or file it was not asked about, or a call that throws or rejects is `runner-invalid-output`, and the check exits `2`. A runner reports its own failures as a `RunnerFailure` (`core/mechanism-port/runner-failure.ts`): `piece-invalid`, `tool-failed`, `file-unreadable`, `file-unparseable`, `plugin-conflict`, `team-config-unloadable`, `runner-invalid-output`, `toolchain-unavailable` or `toolchain-shadowed`.
114
+
115
+ Use core's ports (`core/platform-ports/`) for files, module loading and paths, and wrap the tool itself in one factory file that is the only place the tool's package is imported. The audit mechanism's is `typescript-parse.ts`; the ESLint runner's is `eslint-toolchain.ts` (`eslint`, `@typescript-eslint/parser`, `@typescript-eslint/eslint-plugin` and `typescript`), with `inline-config-parser.ts` the only importer of `@eslint/plugin-kit`.
116
+
117
+ ### 2. Choose an exception path
118
+
119
+ A runner declares `exceptionPath`, which tells core how the tool's own exception formats are handled.
120
+
121
+ - **Standalone** (`"standalone"`): the tool has no exception format of its own, or none the repository can write to. The runner implements `run`, which returns raw hits for the selected clauses with no exception applied, and `conform`, which runs a clause over its shared cases without reading any repository file. Core applies `discipline-exceptions.json` itself. The audit mechanism is standalone. The author's contract is `StandaloneRunner` in `core/mechanism-port/runner-module-schema.ts`.
122
+ - **Embedded** (`"embedded"`): the tool has its own ignore, override, suppression or inline formats, which the team's own run of the tool honours. The runner reports every native channel that touches a selected clause, and writes a projection so the team's run honours the recorded exceptions. ESLint is embedded. The author's contract is `EmbeddedRunner` in `core/mechanism-port/embedded-runner-module-schema.ts`; see "Embedded mechanisms" below.
123
+
124
+ Core knows only these two paths. A mechanism that fits neither would need a change to core.
125
+
126
+ ### 3. The runner's other files
127
+
128
+ - `mechanisms/<MechanismId>/runner/piece-type-packages.json`: a JSON array of the packages a piece may import types from. The audit mechanism's is `["typescript"]` and the ESLint runner's is `["eslint"]`. It is not the runtime list.
129
+ - `mechanisms/<MechanismId>/runner/README.md`: the runner's runtime requirements, its piece contract and its piece settings. See `mechanisms/audit/runner/README.md` and `mechanisms/eslint/runner/README.md`.
130
+ - A co-located `.test.ts` for every source file.
131
+
132
+ ### 4. Conformance
133
+
134
+ Each runner's suite runs core's `checkConformance` (`core/conformance/conformance.ts`) over the real runner as core loads it, for every shared clause its pieces serve. It calls the runner's `conform` and compares the flagged lines with each case's expected lines; the runner conforms for a clause when the result is ok and lists no failures. The audit mechanism's is `mechanisms/audit/runner/walker-conformance.test.ts`; the ESLint runner's is in `mechanisms/eslint/runner/native-exceptions.integration.test.ts`. Conformance runs the real tool in memory, because the tool's verdict is what is being checked.
135
+
136
+ ### 5. Selecting it
137
+
138
+ To let a clause use the new mechanism, add the mechanism id to that clause's `mechanisms` list and add a piece for it (see "Adding a discipline", step 3). Until a clause lists it, a repository cannot select it.
139
+
140
+ ## Import boundaries (FR-8)
141
+
142
+ These hold for every discipline and mechanism. Tests under `core/check/` check them over every file in the install and the probe rule set, so a new file is covered with no change, with one exception: a new mechanism's wrapping file, the one runner file allowed to import its tool, must be added by name to the lists in `core/check/vendor-imports.test.ts`, which name each mechanism's wrapping files and vendors.
143
+
144
+ - **Core names no discipline and no mechanism.** No file under `core/` may contain a discipline id or mechanism id found in the install, or import anything under `mechanisms/` or `rules/` (`core/check/core-names-no-mechanism.test.ts`). Core reaches a runner only by loading its `runner.ts` at run time.
145
+ - **A runner names no discipline.** No file in a `mechanisms/<MechanismId>/runner/` folder may contain a discipline id.
146
+ - **A piece reaches only its own mechanism's runner, core, and its own discipline's files** (`core/check/piece-imports.test.ts`). A relative import from a piece in `mechanisms/<MechanismId>/<DisciplineId>/` must resolve inside exactly one of: that piece folder; the same rule set's `rules/<DisciplineId>/`; the install's `mechanisms/<MechanismId>/runner/`; or the install's `core/`. Another mechanism's piece for the same discipline is out of reach.
147
+ - **A piece imports a package only as a type**, and only a package its runner lists in `piece-type-packages.json`. A value import of a package, including a `node:` module, and any dynamic import are refused. An audit piece gets TypeScript's runtime API as an argument, so it never imports `typescript` as a value; an ESLint rule gets everything it needs from ESLint's rule context.
148
+
149
+ ## Embedded mechanisms
150
+
151
+ An embedded runner has the same `run` and `conform` as a standalone one, plus:
152
+
153
+ - `projectedKinds`: the native exception kinds its own projection writes. Only these kinds can be matched by a record.
154
+ - `run` also receives the repository's exception records for that mechanism, so it can regenerate the projection and compare it. It returns hits, the native exceptions it found, and the projection's state: `current`, `out-of-date`, `missing` or `not-included`. A projection that is missing or not included means the mechanism did not run: core lists `mechanism-not-run` and the check fails. An out-of-date one is a projection problem and also fails.
155
+ - `project`: writes the projection file and returns its path with `written` or `unchanged`. `hone project` calls it.
156
+
157
+ Core passes every record for the mechanism to both calls, forfeited or not, and never passes the touched set. A forfeited file carve-out therefore stays in the projection and still matches its native exception; core's check reports it as `forfeited` and fails the run. Keep it that way: a runner must not compute forfeiture or read the touched set itself, so that whether a forfeited carve-out stays pushed down remains core's decision. No test checks this; it is a rule for review.
158
+
159
+ ### Native channels
160
+
161
+ Writing an embedded mechanism means listing every native channel the tool has and mapping each one to an exception kind core understands (`nativeExceptionSchema` in `core/mechanism-port/embedded-run-report-schema.ts`). A native exception is accepted only when its kind is in the runner's `projectedKinds` and a record in `discipline-exceptions.json` covers it; every other native exception is reported as unrecorded and fails the run, whether or not it currently hides a finding.
162
+
163
+ The ESLint runner's map. "Checked file" means a tracked `.ts`, `.tsx`, `.mts` or `.cts` file; "selected rule" means the rule id of a selected clause's ESLint piece.
164
+
165
+ | ESLint native channel | Exception kind | Can a record cover it? |
166
+ | --- | --- | --- |
167
+ | a checked file the team's configuration ignores (for example a global `ignores` block); reported for every selected clause | `ignore` | no |
168
+ | a checked file on which the team's resolved configuration leaves a selected rule below `"error"` (`"warn"`, `"off"` or not set) | `config-override` | yes |
169
+ | an entry for a selected rule in any tracked file named `eslint-suppressions.json`, or in a file named by `--suppressions-location` in a tracked `package.json` script | `suppression-entry` | no |
170
+ | an `eslint-disable`, `eslint-disable-line` or `eslint-disable-next-line` comment naming a selected rule, or naming no rule | `inline-disable` | no |
171
+ | an `/* eslint ... */` comment configuring a selected rule, or one that cannot be parsed | `inline-rule-config` | no |
172
+ | an option in an ESLint invocation in a tracked `package.json` script that weakens or replaces a selected rule's configuration: `--rule` or `--suppress-rule` naming it, or `--suppress-all`, `--ignore-pattern`, `-c`/`--config`, `--no-config-lookup`, `--parser`, `--parser-options` or `--plugin` | `command-line-option` | no |
173
+
174
+ The ESLint runner declares `projectedKinds: ["config-override"]`. A record covers a `config-override` on its own file (authorised location or file carve-out) or on every file (clause-wide carve-out).
175
+
176
+ How the runner finds each channel (`mechanisms/eslint/runner/`):
177
+
178
+ - `ignore` and `config-override` come from a query instance of ESLint on the team's own configuration (`eslint-instance.ts`): `isPathIgnored` and `calculateConfigForFile` per checked file. A configuration that fails to load is `team-config-unloadable`; one that registers a different module under a selected piece's namespace is `plugin-conflict`.
179
+ - `inline-disable` and `inline-rule-config` come from a reserved rule, `<reservedNamespace>/inline-config` (currently `hone-core/inline-config`), that runs in core's governance lint and reads each file's inline configuration comments with `@eslint/plugin-kit` (`inline-config-parser.ts`). `eslint-enable` and other directives such as `/* global */` are not reported.
180
+ - `suppression-entry` comes from `suppressions-scanner.ts`. Keys in a tracked `eslint-suppressions.json` are read relative to its folder; keys in a file named by `--suppressions-location` are read relative to the `package.json` that names it.
181
+ - `command-line-option` comes from `package-script-scanner.ts`, which parses every tracked `package.json` and splits each script into commands. A command is an ESLint invocation when a token is `eslint`, starts `eslint@`, or ends `/eslint` or `/eslint.js`. A script with an unterminated quote is `tool-failed`.
182
+
183
+ Hits come from a separate governance instance that uses only the runner's configuration: the selected rules and the inline-config rule at `"error"` on `**/*.{ts,tsx,mts,cts}`, parsed with `@typescript-eslint/parser`, with the team's configuration file, ignores, suppressions and inline configuration all off. No native channel can change core's findings.
184
+
185
+ Options passed outside a `package.json` script (a CI step, an editor setting, a wrapper script) are not found. They cannot change core's verdict, but core cannot check whether such a run honours the records.
186
+
187
+ ### The ESLint projection
188
+
189
+ `projection.ts` writes `disciplines.eslint.mjs` at the repository root. It imports each piece's plugin module by a path relative to the repository root, then exports, in order: one block per plugin namespace enabling its selected rules at `"error"` on `**/*.{ts,tsx,mts,cts}`; one block per authorised location or file carve-out turning those rules `"off"` for that file (the path escaped as a glob); and one block per clause-wide carve-out turning them `"off"` everywhere. Block names start with `reservedNamespace` (currently `hone-core/`). The output is sorted, so the same selection and records always produce the same text.
190
+
191
+ The team spreads its default export last in its flat config; the projection is the only supported way to adopt the rules. On each check the runner first compares the file with what it would write now (`missing`, or `out-of-date` if it differs). It then checks the projection's effect through the query instance, in two directions. Every selected rule must be set, at any severity, on at least one checked file that is not ignored, when there is one. Every record whose file is checked must leave its rules at severity `0` on that file, or on every checked file for a clause-wide carve-out. If either fails, the result is `not-included` with no hits. The second direction catches a team that enables a rule another way, for example through a piece's own fragment such as `mechanisms/eslint/CD-14/cd14.eslint.ts`, without importing the projection.
192
+
193
+ ### Runtime
194
+
195
+ The ESLint mechanism runs on the repository's own toolchain, declared as optional peers: `eslint` `^9.12.0 || ^10.0.0`, and `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` `^8.56.0` (the latter for the pieces that reuse its rules). TypeScript is the parser's peer and the audit mechanism's, at `>=4.8.4 <7.0.0`. `@eslint/plugin-kit` is core's own dependency, imported directly because a transitive copy does not resolve under strict package managers. The development pins are `eslint` 10.11.0 and, as `eslint-9`, 9.39.5, with typescript-eslint 8.71.2, and each range's floor under a `-floor` alias; the integration suite runs on all four lines, against the consumer repositories in `mechanisms/eslint/runner/test-fixtures/`.
@@ -0,0 +1,78 @@
1
+ # The why-chain contract
2
+
3
+ A why-chain explains why an exception is needed. It starts at the symptom, which is the exception itself, and traces cause to cause until it reaches a root that someone owns. Every new or edited `whyChain` in `discipline-exceptions.json` follows this contract, and core refuses one that breaks a mechanical rule; a chain written before it is handled as [below](#chains-written-to-the-earlier-contract).
4
+
5
+ The contract keeps exactly five whys. What it fixes is the shape of the chain. A chain that lists five objections ("why not X?", "why only this file?") or restates one reason five times is not a chain: each why must ask why the answer before it is true.
6
+
7
+ ## Shape
8
+
9
+ ```json
10
+ "whyChain": {
11
+ "whys": [
12
+ { "why": "Why does the audit refuse tracker ids in carve-out names?", "because": "The audit's name matcher accepts only lowercase slugs, and tracker ids carry uppercase letters.", "evidence": "tools/audit/name-matcher.ts:14" },
13
+ { "why": "Why does the name matcher accept only lowercase slugs?", "because": "It was copied from the branch-name validator, which lowercases because git refs fold case on Windows.", "evidence": "tools/git/branch-name.ts:8" },
14
+ { "why": "Why was the matcher copied from the branch-name validator?", "because": "No shared slug type existed when the audit landed, so each tool wrote its own pattern.", "evidence": "PR #212, merged 2026-07-02" },
15
+ { "why": "Why did no shared slug type exist when the audit landed?", "because": "The values package that now holds RepoPath was split out two months after the audit.", "evidence": "packages/values/package.json:3" },
16
+ { "why": "Why was the values package split out after the audit?", "because": "The split waited on the monorepo move, which left older tools on their own patterns.", "evidence": "docs/decisions/0007-monorepo.md:21" }
17
+ ],
18
+ "rootCause": "Older tools still carry patterns written before the monorepo move gave them shared value types.",
19
+ "rootCheck": "`git grep -n slugPattern tools/` today still returns tools/audit/name-matcher.ts:14 and no import from packages/values.",
20
+ "readback": "Older tools still carry pre-monorepo patterns, therefore the audit never adopted the shared slug type, therefore its matcher copied the branch-name validator's lowercase rule, therefore the audit refuses tracker ids in carve-out names.",
21
+ "owner": "capture 01a0b421"
22
+ }
23
+ ```
24
+
25
+ | Field | What it holds |
26
+ |---|---|
27
+ | `whys` | Exactly five steps. Why 1 asks about the symptom. Each later `why` asks why the previous `because` is true, and names what that answer said. |
28
+ | `because` | The cause, with something new in it: a cause, not the previous answer in other words. |
29
+ | `evidence` | Where the cause can be checked again: a path, a line, a record or PR number, a measurement or a link. |
30
+ | `rootCause` | The cause behind the fifth answer: a found fact or an owned decision, never a symptom or a restatement such as "no time" or "out of scope". |
31
+ | `rootCheck` | What you ran or read today that shows the root still holds, and what it showed, with a path, record, measurement or link. |
32
+ | `readback` | The chain read from the root back to the symptom, joined with "therefore". |
33
+ | `owner` | Who owns the root: a record, a capture id, or the holder of the reserved authority. |
34
+
35
+ `rootCheck` and `readback` are a pair. A chain that has either one is a causal chain and needs both.
36
+
37
+ ## What core checks
38
+
39
+ These checks work on the words of the chain. Core lowercases the text, splits camelCase identifiers and paths into words, and drops function words (articles, pronouns, possessives, prepositions and common adverbs), words under three letters and bare numbers. It then reduces inflections to a crude stem, so "copied" and "copies" match. The stem is crude: a few pairs still split ("agree" and "agreed") and a few unrelated words meet ("plan" and "plane"). It uses no language model.
40
+
41
+ 1. **Five steps, each answered.** Core keeps the earlier floor: exactly five whys, a non-blank `why`, a `because` and `evidence` of at least 12 characters that are not one repeated character, a `rootCause` that does not open with a stock restatement, and an `owner`.
42
+ 2. **Evidence can be checked again.** Every `evidence` and the `rootCheck` must hold a path (`a/b`), a file name, a link, or a number. A file name starts a word and ends in a lowercase extension of one to ten letters or digits (`name.ext`, `vitest.config.ts`, `*.fixture.ts`), or is a dotfile (`.gitignore`); a name with no extension, such as `Makefile`, needs its path. Prose such as "the redirects documentation" is refused, and "e.g.", "i.e.", "a.k.a.", "etc.", "a.m.", "p.m.", and a standalone "and/or", "n/a", "w/o" or "yes/no" don't count. This is a floor: any path-shaped word passes, whether or not it points at the cause.
43
+ 3. **Each answer introduces a cause.** An answer's new words are the words that appear in neither why 1's question nor any earlier answer. An answer whose new words are fewer than a quarter of its content words restates the symptom or an earlier answer, and is refused. When this was set, every answer in the pilot's chains brought in at least a third new words, 4 of 496 later answers in one consumer's file fell below a quarter (each repeating the answers before it), and a chain restating one reason fell below it by its third answer.
44
+ 4. **Each why asks about the previous answer.** Why 1 must hold at least one content word; core does not compare it with the entry's `reason`, `clause` or `file`. Why 2 to why 5 must each use at least one of the previous answer's new words. A question that only reuses the symptom's words, or names its subject by pronoun ("why is that enough?"), is refused, and the refusal lists the words it could have named.
45
+ 5. **The root is the fifth answer's cause.** `rootCause` must use at least one of the fifth answer's new words.
46
+ 6. **The readback names the root and the symptom.** `readback` must contain "therefore", use at least one word of `rootCause`, and use at least two words of why 1's question (all of them when it has fewer), in any order.
47
+
48
+ A refusal names the step and what to fix. With why 3 of the example above changed to "Why is that enough?", the report lists:
49
+
50
+ ```text
51
+ exceptions[0] why-chain-refused ✖ does not ask about the cause why 2's answer gave: ask why that answer is true, naming its cause (copied, branch, validator, git, refs, fold, case, windows)\n → at whys[2].why
52
+ ```
53
+
54
+ ## What review still judges
55
+
56
+ The checks catch a chain's shape, not whether it is true. A chain can pass every check and still be wrong. Whoever reviews a change to `discipline-exceptions.json` judges:
57
+
58
+ - whether why 1 asks about this entry's own exception, since check 4 only needs it to hold a content word;
59
+ - whether each answer is true, and whether its evidence supports it;
60
+ - whether each link is a real cause, not an objection that happens to reuse a word from the previous answer ("Why is a recorded check enough?" after an answer that mentions a check passes check 4 and is still an objection);
61
+ - whether the root is the right root: if the root changed, the exception would no longer be needed;
62
+ - whether the `rootCheck` really tests today's state, rather than citing a path that has nothing to do with the root;
63
+ - whether the `readback` follows the chain from the root back to the symptom, since check 6 doesn't read its order;
64
+ - whether a rule is being used as a cause. A rule is the test the chain is judged by, not a reason inside it;
65
+ - whether an answer with more than one cause follows each one, or says why a branch carries no weight;
66
+ - a restatement in different words. Check 3 catches an answer that mostly reuses earlier words; one reworded in fresh synonyms passes it.
67
+
68
+ ## Chains written to the earlier contract
69
+
70
+ A chain with neither `rootCheck` nor `readback` is a legacy chain, written before this contract. It is judged against `--base-revision`, the same way imported records are:
71
+
72
+ - **Unchanged since the base revision:** judged by the earlier floor (check 1 only), and accepted when it passes. Reordering keys inside the chain counts as an edit.
73
+ - **New or edited since the base revision:** judged by this contract and refused until it is rewritten. The refusal says so.
74
+ - **No base revision, or git cannot read the base:** the record is judged by the earlier floor and accepted when it passes, and the run reports `legacy-chain-unmeasured`, which fails the verdict. Pass `--base-revision`, or rewrite every legacy chain.
75
+ - **A base whose `discipline-exceptions.json` does not parse:** the base holds no entries, so every legacy chain counts as new and is refused.
76
+ - **The `project` command** reads no base revision. It projects legacy chains as it always did, and reports nothing about them.
77
+
78
+ This grace period has no end date. A legacy chain stays accepted until its entry is touched, so a repository that wants every chain causal rewrites them on purpose. Section 8 of `MIGRATING.md` in the Hone source gives the steps.
@@ -0,0 +1,81 @@
1
+ import {
2
+ folderScope
3
+ } from "../../../chunks/chunk-QWA6OVLC.js";
4
+ import "../../../chunks/chunk-NZLE2WMY.js";
5
+
6
+ // mechanisms/audit/CD-1/any-cast.ts
7
+ var SNIPPET_MAX_LENGTH = 80;
8
+ var ZOD_MODULE_SPECIFIER_PATTERN = /^zod(\/.*)?$/;
9
+ var CD1_ANY_PATTERN = /\bas\s+any\b|:\s*any\b|<any>/;
10
+ var sourceEligibility = (request) => {
11
+ if (!request.file.endsWith(".ts") && !request.file.endsWith(".tsx")) return "excluded";
12
+ if (folderScope({ file: request.file }) === "generated") return "excluded";
13
+ return "eligible";
14
+ };
15
+ var namesImportedFromZod = (request) => new Set(
16
+ request.sourceFile.statements.flatMap((statement) => {
17
+ if (!request.syntaxApi.isImportDeclaration(statement)) return [];
18
+ if (!request.syntaxApi.isStringLiteral(statement.moduleSpecifier)) return [];
19
+ if (!ZOD_MODULE_SPECIFIER_PATTERN.test(statement.moduleSpecifier.text)) return [];
20
+ const namedBindings = statement.importClause?.namedBindings;
21
+ if (namedBindings === void 0 || !request.syntaxApi.isNamedImports(namedBindings)) return [];
22
+ return namedBindings.elements.map((element) => element.name.text);
23
+ })
24
+ );
25
+ var castPermission = (request) => {
26
+ if (!request.syntaxApi.isAsExpression(request.node)) return "forbidden";
27
+ const typeNode = request.node.type;
28
+ if (typeNode.kind === request.syntaxApi.SyntaxKind.UnknownKeyword) return "permitted";
29
+ if (request.syntaxApi.isTypeReferenceNode(typeNode) && request.syntaxApi.isIdentifier(typeNode.typeName)) {
30
+ const typeName = typeNode.typeName.text;
31
+ if (typeName === "const" || request.zodImportedNames.has(typeName)) return "permitted";
32
+ if (request.syntaxApi.isPropertyAccessExpression(request.node.expression) && request.node.expression.name.text === "value" && (typeName === "ReadonlyArray" || typeName === "Array")) return "permitted";
33
+ }
34
+ if (!request.syntaxApi.isIndexedAccessTypeNode(typeNode)) return "forbidden";
35
+ const objectType = typeNode.objectType;
36
+ const indexType = typeNode.indexType;
37
+ if (request.syntaxApi.isTypeReferenceNode(objectType) && request.syntaxApi.isIdentifier(objectType.typeName) && objectType.typeName.text === "Tool" && request.syntaxApi.isLiteralTypeNode(indexType) && request.syntaxApi.isStringLiteral(indexType.literal) && indexType.literal.text === "inputSchema") return "permitted";
38
+ return "forbidden";
39
+ };
40
+ var snippetAt = (request) => {
41
+ const snippet = request.sourceFile.text.slice(request.position, request.position + SNIPPET_MAX_LENGTH).replace(/\n/g, " ");
42
+ return snippet.length === SNIPPET_MAX_LENGTH ? `${snippet}\u2026` : snippet;
43
+ };
44
+ var check = {
45
+ prepare: ({ clauses, syntaxApi }) => ({
46
+ outcome: "ok",
47
+ value: {
48
+ prepareFile: ({ file }) => {
49
+ if (sourceEligibility({ file }) === "excluded") {
50
+ return { outcome: "ok", value: { kind: "skipped" } };
51
+ }
52
+ return {
53
+ outcome: "ok",
54
+ value: {
55
+ kind: "syntax",
56
+ begin: ({ sourceFile, anchorAt }) => {
57
+ const zodImportedNames = namesImportedFromZod({ sourceFile, syntaxApi });
58
+ const hits = [];
59
+ return {
60
+ enter: ({ node }) => {
61
+ if (!syntaxApi.isAsExpression(node) && !syntaxApi.isTypeAssertionExpression(node)) return;
62
+ if (castPermission({ node, syntaxApi, zodImportedNames }) === "permitted") return;
63
+ const position = node.getStart(sourceFile);
64
+ const snippet = snippetAt({ sourceFile, position });
65
+ if (!CD1_ANY_PATTERN.test(snippet)) return;
66
+ const anchor = anchorAt({ position });
67
+ hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
68
+ },
69
+ finish: () => hits
70
+ };
71
+ }
72
+ }
73
+ };
74
+ },
75
+ finish: () => ({ outcome: "ok", value: [] })
76
+ }
77
+ })
78
+ };
79
+ export {
80
+ check
81
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 1,
3
+ "discipline": "CD-1",
4
+ "mechanism": "audit",
5
+ "clauses": [
6
+ {
7
+ "clause": "any-cast",
8
+ "settings": {
9
+ "module": "any-cast.js"
10
+ }
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 1,
3
+ "discipline": "CD-10",
4
+ "mechanism": "audit",
5
+ "clauses": [
6
+ {
7
+ "clause": "throws-in-tests",
8
+ "settings": {
9
+ "module": "throws-in-tests.js"
10
+ }
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,49 @@
1
+ import {
2
+ folderScope
3
+ } from "../../../chunks/chunk-QWA6OVLC.js";
4
+ import "../../../chunks/chunk-NZLE2WMY.js";
5
+
6
+ // mechanisms/audit/CD-10/throws-in-tests.ts
7
+ var testFileEligibility = (request) => {
8
+ if (folderScope({ file: request.file }) === "generated") return "skipped";
9
+ return request.file.endsWith(".test.ts") || request.file.endsWith(".test.tsx") ? "eligible" : "skipped";
10
+ };
11
+ var snippetAt = (request) => {
12
+ const snippet = request.source.slice(request.position, request.position + 80).replace(/\n/g, " ");
13
+ return snippet.length === 80 ? `${snippet}\u2026` : snippet;
14
+ };
15
+ var check = {
16
+ prepare: ({ clauses, syntaxApi }) => ({
17
+ outcome: "ok",
18
+ value: {
19
+ prepareFile: ({ file }) => {
20
+ if (testFileEligibility({ file }) === "skipped") {
21
+ return { outcome: "ok", value: { kind: "skipped" } };
22
+ }
23
+ return {
24
+ outcome: "ok",
25
+ value: {
26
+ kind: "syntax",
27
+ begin: ({ sourceFile, anchorAt }) => {
28
+ const hits = [];
29
+ return {
30
+ enter: ({ node }) => {
31
+ if (!syntaxApi.isThrowStatement(node)) return;
32
+ const position = node.getStart(sourceFile);
33
+ const anchor = anchorAt({ position });
34
+ const snippet = snippetAt({ source: sourceFile.text, position });
35
+ hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
36
+ },
37
+ finish: () => hits
38
+ };
39
+ }
40
+ }
41
+ };
42
+ },
43
+ finish: () => ({ outcome: "ok", value: [] })
44
+ }
45
+ })
46
+ };
47
+ export {
48
+ check
49
+ };
@@ -0,0 +1,70 @@
1
+ import {
2
+ folderScope
3
+ } from "../../../chunks/chunk-QWA6OVLC.js";
4
+ import "../../../chunks/chunk-NZLE2WMY.js";
5
+
6
+ // mechanisms/audit/CD-14/class-syntax.ts
7
+ var TYPESCRIPT_SOURCE_ENDINGS = [".ts", ".tsx", ".mts", ".cts"];
8
+ var DECLARATION_FILE_ENDINGS = [".d.ts", ".d.mts", ".d.cts"];
9
+ var sourceEligibility = (request) => folderScope({ file: request.file }) === "authored" && TYPESCRIPT_SOURCE_ENDINGS.some((ending) => request.file.endsWith(ending)) && !DECLARATION_FILE_ENDINGS.some((ending) => request.file.endsWith(ending)) ? "eligible" : "excluded";
10
+ var ownAmbience = (request) => request.syntaxApi.canHaveModifiers(request.node) && (request.syntaxApi.getModifiers(request.node) ?? []).some(
11
+ (modifier) => modifier.kind === request.syntaxApi.SyntaxKind.DeclareKeyword
12
+ ) ? "ambient" : "runtime";
13
+ var enclosingAmbience = (request) => {
14
+ if (request.syntaxApi.isSourceFile(request.node)) {
15
+ return "runtime";
16
+ }
17
+ if (request.syntaxApi.isModuleDeclaration(request.node) && ownAmbience(request) === "ambient") {
18
+ return "ambient";
19
+ }
20
+ return enclosingAmbience({ syntaxApi: request.syntaxApi, node: request.node.parent });
21
+ };
22
+ var classKeywordOf = (request) => request.node.getChildren(request.tree).find((child) => child.kind === request.syntaxApi.SyntaxKind.ClassKeyword);
23
+ var lineTextAt = (request) => {
24
+ const { line } = request.tree.getLineAndCharacterOfPosition(request.position);
25
+ const starts = request.tree.getLineStarts();
26
+ return request.tree.text.slice(starts[line] ?? 0, starts[line + 1] ?? request.tree.text.length).trim();
27
+ };
28
+ var authoredClassKeyword = (request) => {
29
+ if (!request.syntaxApi.isClassLike(request.node)) return void 0;
30
+ if (ownAmbience(request) === "ambient" || enclosingAmbience({ syntaxApi: request.syntaxApi, node: request.node.parent }) === "ambient") {
31
+ return void 0;
32
+ }
33
+ return classKeywordOf(request);
34
+ };
35
+ var check = {
36
+ prepare: ({ clauses, syntaxApi }) => ({
37
+ outcome: "ok",
38
+ value: {
39
+ prepareFile: ({ file }) => {
40
+ if (sourceEligibility({ file }) === "excluded") {
41
+ return { outcome: "ok", value: { kind: "skipped" } };
42
+ }
43
+ return {
44
+ outcome: "ok",
45
+ value: {
46
+ kind: "syntax",
47
+ begin: ({ sourceFile, anchorAt }) => {
48
+ const hits = [];
49
+ return {
50
+ enter: ({ node }) => {
51
+ const keyword = authoredClassKeyword({ syntaxApi, node, tree: sourceFile });
52
+ if (keyword === void 0) return;
53
+ const position = keyword.getStart(sourceFile);
54
+ const anchor = anchorAt({ position });
55
+ const snippet = lineTextAt({ tree: sourceFile, position });
56
+ hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
57
+ },
58
+ finish: () => hits
59
+ };
60
+ }
61
+ }
62
+ };
63
+ },
64
+ finish: () => ({ outcome: "ok", value: [] })
65
+ }
66
+ })
67
+ };
68
+ export {
69
+ check
70
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 1,
3
+ "discipline": "CD-14",
4
+ "mechanism": "audit",
5
+ "clauses": [
6
+ {
7
+ "clause": "class-syntax",
8
+ "settings": {
9
+ "module": "class-syntax.js"
10
+ }
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,40 @@
1
+ import {
2
+ folderScope
3
+ } from "../../../chunks/chunk-QWA6OVLC.js";
4
+ import "../../../chunks/chunk-NZLE2WMY.js";
5
+
6
+ // mechanisms/audit/CD-15/loops.ts
7
+ var sourceEligibility = (request) => {
8
+ if (!request.file.endsWith(".ts") && !request.file.endsWith(".tsx")) return "excluded";
9
+ if (folderScope({ file: request.file }) === "generated") return "excluded";
10
+ return "eligible";
11
+ };
12
+ var FOR_OF = /\bfor\s*(?:await\s*)?\(\s*(?:const|let|var)?[^;()]*\bof\b/;
13
+ var COUNTED_FOR = /\bfor\s*\([^)]*;[^)]*;[^)]*\)/;
14
+ var WHILE_LOOP = /\bwhile\s*\(/;
15
+ var check = {
16
+ prepare: ({ clauses }) => ({
17
+ outcome: "ok",
18
+ value: {
19
+ prepareFile: ({ file, readText }) => {
20
+ if (sourceEligibility({ file }) === "excluded") {
21
+ return { outcome: "ok", value: { kind: "skipped" } };
22
+ }
23
+ const text = readText();
24
+ if (text.outcome === "failed") return text;
25
+ const hits = text.value.split(/\r?\n/).flatMap((line, index) => {
26
+ const trimmed = line.trim();
27
+ if (trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*")) return [];
28
+ const collapsed = trimmed.replace(/\s+/g, " ");
29
+ const snippet = collapsed.length > 80 ? `${collapsed.slice(0, 80)}\u2026` : collapsed;
30
+ return [FOR_OF, COUNTED_FOR, WHILE_LOOP].flatMap((pattern) => pattern.test(line) ? clauses.map((clause) => ({ clause: clause.address, anchor: { line: index + 1, column: 0 }, snippet })) : []);
31
+ });
32
+ return { outcome: "ok", value: { kind: "complete", hits } };
33
+ },
34
+ finish: () => ({ outcome: "ok", value: [] })
35
+ }
36
+ })
37
+ };
38
+ export {
39
+ check
40
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 1,
3
+ "discipline": "CD-15",
4
+ "mechanism": "audit",
5
+ "clauses": [
6
+ {
7
+ "clause": "loops",
8
+ "settings": {
9
+ "module": "loops.js"
10
+ }
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,29 @@
1
+ import {
2
+ folderScope
3
+ } from "../../../chunks/chunk-QWA6OVLC.js";
4
+ import "../../../chunks/chunk-NZLE2WMY.js";
5
+
6
+ // mechanisms/audit/CD-17/clock-sources.ts
7
+ var sourceEligibility = (request) => {
8
+ if (!request.file.endsWith(".ts") && !request.file.endsWith(".tsx")) return "excluded";
9
+ if (folderScope({ file: request.file }) === "generated") return "excluded";
10
+ return "eligible";
11
+ };
12
+ var check = {
13
+ prepare: ({ clauses }) => ({
14
+ outcome: "ok",
15
+ value: {
16
+ prepareFile: ({ file, readText }) => {
17
+ if (sourceEligibility({ file }) === "excluded") return { outcome: "ok", value: { kind: "skipped" } };
18
+ const text = readText();
19
+ if (text.outcome === "failed") return text;
20
+ const hits = text.value.split("\n").flatMap((line, index) => /\bDate\.now\(\)/.test(line) || /\bnew\x20Date\b/.test(line) ? clauses.map((clause) => ({ clause: clause.address, anchor: { line: index + 1, column: 0 }, snippet: line.trim() })) : []);
21
+ return { outcome: "ok", value: { kind: "complete", hits } };
22
+ },
23
+ finish: () => ({ outcome: "ok", value: [] })
24
+ }
25
+ })
26
+ };
27
+ export {
28
+ check
29
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 1,
3
+ "discipline": "CD-17",
4
+ "mechanism": "audit",
5
+ "clauses": [
6
+ {
7
+ "clause": "clock-sources",
8
+ "settings": {
9
+ "module": "clock-sources.js"
10
+ }
11
+ }
12
+ ]
13
+ }