@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,156 @@
1
+ # DI-discipline lens
2
+
3
+ A reusable audit method, not a ruleset. The rules it enforces are **data**: load
4
+ every rule page whose `Review lens` line names `di-discipline`
5
+ from the codebase under review and treat their text as authoritative. This file
6
+ describes only *how* the lens reads code — the concept, the inspection
7
+ procedure, and the output shape. It names no specific rule numbers, file paths,
8
+ type names, or library names; those live in the loaded rules and differ per
9
+ codebase.
10
+
11
+ ## Concept
12
+
13
+ This lens defends **dependency injection through composition** on both faces of
14
+ the code: every technical binding a unit needs — wall-clock time, process and
15
+ signal lifecycle, standard-library capabilities (filesystem, crypto, path, net),
16
+ and third-party services — arrives through a named port the unit receives as a
17
+ constructor parameter or function argument, never reached for through a global,
18
+ an ambient import, or the module system. Each port ships a default factory in
19
+ its own module so production wires the real implementation once at the
20
+ composition root and tests inject a fake of the same shape. The test face is the
21
+ mirror image: a unit test fakes *everything* outside the unit's boundary, and it
22
+ delivers those fakes the same way production delivers the real ones — through the
23
+ unit's own signature — so the unit is byte-identical under test and under
24
+ production and never knows which it received. The moment a test reaches for the
25
+ module system to control a dependency (mock an import, stub a global,
26
+ monkey-patch a binding), the unit's DI is wrong: the dependency was not a port.
27
+
28
+ Across codebases the concept recurs under different names (constructor
29
+ injection, hexagonal ports-and-adapters, "no ambient singletons", "depend on
30
+ abstractions"). The loaded rules tell you this codebase's exact shape: which
31
+ capabilities are named ports, the single permitted site for each ambient
32
+ binding (the wrapping factory), the default-factory naming convention, any
33
+ type-level constraint on context-consuming middleware, and the closed list of
34
+ banned test-faking mechanisms. Read them first; they override any default
35
+ intuition.
36
+
37
+ ## Loading the ruleset
38
+
39
+ 1. Resolve the rule pages: `rules/*/README.md` in the Hone install (the folder holding `core/` and `rules/`), and in each rule set the repository's `disciplines.json` names under `ruleSets`.
40
+ 2. Keep the pages whose `Review lens` line names `di-discipline`. **If no rule pages can be read at all, STOP and return CANNOT-REVIEW naming the rule-page paths you resolved** — an unloadable ruleset is never a codebase without discipline, and reviewing zero rules would emit a PASS that means nothing.
41
+ 3. Read each kept page in full, including its `## Exceptions` section and any examples, and the repository's `discipline-exceptions.json` entries for that discipline: those recorded exceptions (authorised locations and carve-outs) are the closed exception list — anything outside them is a finding. Where a rule names the single permitted site for an ambient binding (a factory file, a port-module directory), that is the *only* permitted site; everywhere else the same call is a violation.
42
+ 4. If zero rule pages name this lens in their `Review lens` line, report that the codebase declares no DI discipline and produce an empty finding set — do not invent rules.
43
+
44
+ ## Inspection procedure
45
+
46
+ This lens reads two faces and reports them separately: the **production side**
47
+ (are bindings ports, wired from defaults, threaded to the units that need them)
48
+ and the **test side** (are dependencies faked through the unit's own seam, or
49
+ reached for through the module system). Walk the diff for both.
50
+
51
+ ### Production side
52
+
53
+ - **Ambient binding outside its permitted site.** For each capability the rules
54
+ confine to a single factory (time construction, process/signal lifecycle, each
55
+ standard-library module), find every direct call to the raw global or stdlib
56
+ symbol. A hit inside the named factory module is the abstraction boundary —
57
+ pass. A hit anywhere else is a violation: the unit must instead receive a port
58
+ and call it. The raw symbols to grep are codebase knowledge — derive them from
59
+ the rules' literal text (the rule pages name them) and from the imports in
60
+ the diff, not a fixed list.
61
+ - **Consumer-signature gap.** A function or factory that *produces* a value from
62
+ an ambient capability (a timestamp, a unique id, a path join, a signal
63
+ handler) but does NOT take the corresponding port as a parameter is a
64
+ violation-in-waiting even if it currently delegates to a helper that itself
65
+ holds the raw call. The composition pathway must terminate at an injected port,
66
+ not at a buried global.
67
+ - **Missing default factory.** For every port type added or changed in the diff,
68
+ confirm a sibling default-factory function exists in the same module (the
69
+ production implementation). A port shipped without its default forces every
70
+ consumer to hand-roll the wiring and predicts test-side module-mocking
71
+ downstream — flag the absence preemptively. Conversely, consumers that
72
+ construct an ad-hoc object literal matching the port shape outside test code,
73
+ instead of importing the default factory, are reaching around the port.
74
+ - **Composition-root threading.** The boot path (the service-run entrypoint, the
75
+ app start module, the kernel composition) must call each default factory and
76
+ pass the port into the unit that declared it. A unit that *declares* a port
77
+ parameter but is never wired to one in the boot path is a threading violation;
78
+ a boot path that constructs a port inline instead of importing its factory is
79
+ the same gap from the other end.
80
+ - **Type-level context constraint.** Where the rules require context-consuming
81
+ middleware (or any generic that reads kernel-shipped context fields) to bind
82
+ its context type to the base-context constraint, an unbounded generic that
83
+ nonetheless reads those fields is a violation. The fix is the constraint, never
84
+ a runtime guard or an optional/fallback option — the constraint is what makes
85
+ pipeline composition provably correct at compile time. When such middleware
86
+ also carries a raw-global fallback for the field it should read from context,
87
+ that fallback is a separate ambient-binding finding on the same line.
88
+
89
+ ### Test side
90
+
91
+ - **Module-system interception.** Every test-faking mechanism that reaches the
92
+ module system rather than the unit's signature is a finding the instant it
93
+ appears — no further analysis of test outcome, library lineage, or local
94
+ ergonomics is needed. This covers module mocks, deferred module mocks, hoisted
95
+ mock infrastructure, global stubs (and their cleanup), the jest-API
96
+ equivalents, direct property assignment or property-descriptor patching on an
97
+ imported binding, proxy wrappers around a real module, HTTP-interception
98
+ libraries standing in for an injected client, and older rewire-style loaders.
99
+ The remediation is always identical: lift the faked dependency into the unit's
100
+ signature as a port, supply the production default at the composition root, and
101
+ inject the fake directly in the test.
102
+ - **The spy edge case — discriminate by attachment target.** A spy is the one
103
+ mechanism that requires per-call classification. A spy attached to a method on
104
+ a fake the test itself constructed and passed through the unit's seam is
105
+ *observation* — permitted; it reads interaction without replacing anything. A
106
+ spy attached to a method on an imported module (replacing or even merely
107
+ observing its real behaviour) is *module-system reach* — the same shape as a
108
+ module mock, a violation. The discriminator is solely **what object the spy is
109
+ attached to**: a DI-delivered fake (permitted) or an imported binding
110
+ (violation).
111
+ - **Fakes that are permitted are not mocks.** A test that constructs an object
112
+ literal, a factory-built fake, an in-memory implementation of a port, or a
113
+ recording test-double function, and delivers it through the unit's constructor
114
+ or argument, is the exact pattern the discipline channels toward — not a
115
+ finding. "Mock" in common speech covers both shapes; the rules treat them as
116
+ opposites. The affordance is the port's type; no library wraps it.
117
+ - **Boundary gap that forces a mock.** If a dependency the test needs to control
118
+ is *not in the unit's signature*, that is a structural finding even before any
119
+ mock appears: the unit needs a port added before DI-clean testing is possible.
120
+ A test-only subclass overriding a method, or a test-only env/flag the unit
121
+ reads to choose fake-vs-real, are both this gap surfacing — the fake should
122
+ arrive through the seam, and (for the env/flag case) the unit must not know it
123
+ is under test.
124
+
125
+ For each candidate on either side, decide finding vs non-finding strictly
126
+ against the loaded rules and their carve-outs — never against this file's prose
127
+ or a remembered version of some other codebase's rule. When a mechanism appears
128
+ that the rules' enumeration does not cover, surface it explicitly rather than
129
+ deciding it silently — extending the closed list is an amendment surface, not an
130
+ agent-time call.
131
+
132
+ ## Letter-vs-intent
133
+
134
+ The lens's catch-rate lives where the code reads injected but a dependency still
135
+ arrives ambiently. A unit whose signature declares a port yet whose body holds a
136
+ raw global call on a "convenience" path; a default factory present but the boot
137
+ path constructing the port inline beside it; a middleware generic that compiles
138
+ because its context happens to carry the field, yet is unbound so a different
139
+ pipeline would crash; a spy that looks like clean observation but is attached to
140
+ an imported module; an in-memory fake that is actually wired through a module
141
+ mock rather than the seam. A finding here must explain *how the code reads
142
+ DI-clean yet the dependency is still reached for ambiently*, grounded in the
143
+ specific loaded rule. Vague phrasings ("tight coupling", "hard to test") are the
144
+ lens's own failure mode.
145
+
146
+ ## Output shape
147
+
148
+ Report **two-sided** counts the review asks for: a production-side
149
+ block (ambient-binding violations by capability, missing default factories,
150
+ threading gaps, unbound context generics) and a test-side block
151
+ (module-interception violations by mechanism, spy classifications, structural
152
+ boundary gaps). Every finding is
153
+ `file:line | quoted code | <rule-id> | defect-named`, citing the loaded rule by
154
+ the discipline id and clause address on the rule page (for example `CD-9#result-failures`), and — for a test-side mock — naming the port
155
+ shape the remediating refactor would lift into the unit's signature. State the
156
+ rule-page paths you resolved and which rule ids you loaded under this lens.
@@ -0,0 +1,88 @@
1
+ # Errors-as-data lens
2
+
3
+ A reusable audit method, not a ruleset. The rules it enforces are **data**: load
4
+ every rule page whose `Review lens` line names `errors-as-data`
5
+ from the codebase under review and treat their text as authoritative. This file
6
+ describes only *how* the lens reads code — the concept, the inspection
7
+ procedure, and the output shape. It names no specific rule numbers, file paths,
8
+ type names, or library names; those live in the loaded rules and differ per
9
+ codebase.
10
+
11
+ ## Concept
12
+
13
+ This lens defends **error totality and throw discipline**: the idea that a
14
+ fallible operation declares its failure modes in its return type rather than
15
+ escaping through exceptions, and that exceptions are confined to a closed,
16
+ named set of contexts. The signature is the contract — a function that returns
17
+ a result-envelope type must enumerate, inside that type, every way its body can
18
+ fail. A throw that escapes a result-returning function silently breaks the
19
+ contract even though the signature still reads correct.
20
+
21
+ Across codebases the concept recurs under different names (a `Result`/`Either`
22
+ envelope, a tagged error union, a "no unchecked exceptions" rule). The loaded
23
+ rules tell you this codebase's exact shape: the envelope's discriminator, the
24
+ permitted throw contexts, whether error envelopes are data or classes, and the
25
+ construction/inspection idiom. Read them first; they override any default
26
+ intuition.
27
+
28
+ ## Loading the ruleset
29
+
30
+ 1. Resolve the rule pages: `rules/*/README.md` in the Hone install (the folder holding `core/` and `rules/`), and in each rule set the repository's `disciplines.json` names under `ruleSets`.
31
+ 2. Keep the pages whose `Review lens` line names `errors-as-data`. **If no rule pages can be read at all, STOP and return CANNOT-REVIEW naming the rule-page paths you resolved** — an unloadable ruleset is never a codebase without discipline, and reviewing zero rules would emit a PASS that means nothing.
32
+ 3. Read each kept page in full, including its `## Exceptions` section and the repository's `discipline-exceptions.json` entries for that discipline: those recorded exceptions (authorised locations and carve-outs) are the closed exception list — anything outside them is a finding. If a rule names exact permitted sites (files, factory names, class names), those are the only permitted sites.
33
+ 4. If zero rule pages name this lens in their `Review lens` line, report that the codebase declares no errors-as-data discipline and produce an empty finding set — do not invent rules.
34
+
35
+ ## Inspection procedure
36
+
37
+ Walk every signature/implementation pair in the diff. For each, the lens reads
38
+ the type against the body and asks where the body can defeat what the type
39
+ promises:
40
+
41
+ - **Escape via uncaught throw.** A function whose return type is the codebase's
42
+ failure-envelope shape, whose body `await`s or calls something that can throw
43
+ without catching and converting at the boundary, can escape the envelope. The
44
+ throw makes the signature a lie. (Which library calls throw is codebase
45
+ knowledge — derive it from the dependencies in the diff, not a fixed list.)
46
+ - **Under-enumerated failure type.** List every distinct way the body produces a
47
+ failure. Compare to the variants the envelope's error parameter enumerates. A
48
+ body that distinguishes failures the type collapses into one opaque variant —
49
+ or an error parameter that is the language's top/opaque error type rather than
50
+ a closed union — defeats totality. The discriminator over the error type is
51
+ the proof the type carries the failure modes.
52
+ - **Throw outside the permitted contexts.** Every throw site in non-throw-exempt
53
+ code must match one of the closed throw contexts the rules name. A throw that
54
+ reads as "defensive", "impossible state", or "this should never happen" is the
55
+ pattern the discipline forbids unless it sits in exactly a named context (e.g.
56
+ a genuinely type-unreachable exhaustion arm, or a named boot path) — and both
57
+ the context AND its preconditions (return type, reachability) must hold.
58
+ - **Error envelope authored as a class.** If the rules require error envelopes to
59
+ be plain data constructed by factory and inspected by type guard, an authored
60
+ error class (or a class extending the language's base error type) is a finding
61
+ except for the single class the rules explicitly permit, at its named site.
62
+ - **Discriminator / factory drift.** If the rules fix the envelope's
63
+ discriminator field and its construction factory names, flag accesses or
64
+ literals that use a superseded shape (an old boolean discriminator, a
65
+ hand-rolled lookalike, pre-migration factory names).
66
+
67
+ For each candidate, decide finding vs non-finding strictly against the loaded
68
+ rules and their carve-outs — never against this file's prose or a remembered
69
+ version of some other codebase's rule.
70
+
71
+ ## Letter-vs-intent
72
+
73
+ The lens's catch-rate lives in cases where the type reads correct but the rule
74
+ is defeated: a `Result`-typed function that can throw; an error parameter typed
75
+ as a closed union that nonetheless omits a failure mode the body produces; an
76
+ "unreachable" throw in a function that does not actually return the bottom type.
77
+ A finding here must explain *how the signature reads correct yet the rule is
78
+ defeated*, grounded in the specific loaded rule. Vague phrasings ("could throw",
79
+ "error handling looks weak") are the lens's own failure mode.
80
+
81
+ ## Output shape
82
+
83
+ Produce the counts the review asks for (e.g. throws by
84
+ classification, authored-error-classes by classification, under-enumerated error
85
+ types, superseded-discriminator accesses). Every finding is
86
+ `file:line | quoted code | <rule-id> | defect-named`, citing the loaded rule by
87
+ the discipline id and clause address on the rule page (for example `CD-9#result-failures`). State the rule-page paths you resolved and
88
+ which rule ids you loaded under this lens.
@@ -0,0 +1,193 @@
1
+ # Function-first lens
2
+
3
+ A reusable audit method, not a ruleset. The rules it enforces are **data**: load
4
+ every rule page whose `Review lens` line names `function-first`
5
+ from the codebase under review and treat their text as authoritative. This file
6
+ describes only *how* the lens reads code — the concept, the inspection
7
+ procedure, and the output shape. It names no specific rule numbers, file paths,
8
+ type names, or library names; those live in the loaded rules and differ per
9
+ codebase.
10
+
11
+ ## Concept
12
+
13
+ This lens defends **function-first composition**: the idea that behaviour is
14
+ expressed as functions and closures rather than authored classes, that iteration
15
+ is functional transformation rather than imperative loop shape, that third-party
16
+ libraries are reached only through a confined wrapping boundary, and that every
17
+ authored function takes a single named-field argument rather than a positional
18
+ list.
19
+
20
+ Four facets of the same stance:
21
+
22
+ - **No authored classes.** State and behaviour live in a factory that closes
23
+ over its data and returns a record of functions. A `class` declaration hides
24
+ state behind `this`; the closure makes the same state a private binding the
25
+ type system never exposes. The single permitted authored class (and the only
26
+ permitted `new X(...)` sites) are whatever the loaded rules name — typically a
27
+ lone boot-time error class plus external-library instantiations confined to
28
+ their wrapping factories.
29
+ - **Functional iteration only.** A loop body hides the transformation as
30
+ control-flow; the equivalent `map`/`reduce`/`flatMap`/`Array.from` chain names
31
+ the transformation as data. Counted loops name a counter where the operation
32
+ is what matters. Side-effect-only iteration is the one place an imperative
33
+ shape survives, and even then under a `void`-returning callback.
34
+ - **Third-party imports confined to wrapping factories.** A library is an
35
+ external dependency the domain should not see directly. Each library is
36
+ imported in exactly one wrapping-factory file (runtime *and* type-only); every
37
+ other module consumes the kernel-supplied factory output. The wrapping factory
38
+ *is* the function-first boundary for the library — it is where the unavoidable
39
+ `new X(...)` and the raw import are quarantined behind a function-shaped
40
+ surface.
41
+ - **Single-object-argument functions.** Every authored function takes exactly
42
+ one parameter; multiple values pass as named fields on an object. Positional
43
+ multi-argument signatures are forbidden except for callbacks whose signature is
44
+ dictated by an external-library contract — and those hand off to a named-field
45
+ helper at the earliest line.
46
+
47
+ Across codebases the concept recurs under different names (a "no classes" rule, a
48
+ "prefer pipelines over loops" rule, an "adapter boundary" or "ports and
49
+ adapters" rule, a "named parameters" or "options object" rule). The loaded rules
50
+ tell you this codebase's exact shape: which class is permitted and where, the
51
+ closed list of wrapping-factory files, the permitted iteration alternatives, and
52
+ the closed carve-out for positional callbacks. Read them first; they override any
53
+ default intuition.
54
+
55
+ ## Loading the ruleset
56
+
57
+ 1. Resolve the rule pages: `rules/*/README.md` in the Hone install (the folder holding `core/` and `rules/`), and in each rule set the repository's `disciplines.json` names under `ruleSets`.
58
+ 2. Keep the pages whose `Review lens` line names `function-first`. **If no rule pages can be read at all, STOP and return CANNOT-REVIEW naming the rule-page paths you resolved** — an unloadable ruleset is never a codebase without discipline, and reviewing zero rules would emit a PASS that means nothing.
59
+ 3. Read each kept page in full, including its `## Exceptions` section and the repository's `discipline-exceptions.json` entries for that discipline: those recorded exceptions (authorised locations and carve-outs) are the closed exception list — anything outside them is a finding. Where a rule names exact permitted sites (the one permitted class and its file, the closed table of wrapping-factory files, the closed list of library-callback signatures), those are the only permitted sites.
60
+ 4. If zero rule pages name this lens in their `Review lens` line, report that the codebase declares no function-first discipline and produce an empty finding set — do not invent rules.
61
+
62
+ ## Inspection procedure
63
+
64
+ Walk the changed source files (the rules' own carve-outs say whether test files
65
+ are in scope; default the class/iteration/arity passes to non-test `src/` unless
66
+ a rule states otherwise). Run four passes; each is a single mechanical sweep
67
+ followed by a per-site classification.
68
+
69
+ ### Class pass
70
+
71
+ Every `class` declaration in scope — exported or not, since the discipline is
72
+ per-declaration not per-export — is suspect until classified. For each, decide
73
+ one of three buckets:
74
+
75
+ - **justified.** The declaration is the single permitted authored class at its
76
+ named site, OR it is a `new X(...)` for an external-library class whose
77
+ wrapping-factory file the rules name AND the instance is held inside the
78
+ closure and never re-exported as a class. Cite the carve-out; no replacement.
79
+ - **closure-candidate.** The class carries genuine instance state that is
80
+ *mutated* across method calls (counters, caches, accumulating buffers,
81
+ subscription registries, in-flight tracking). Replacement: a factory closing
82
+ over `let`/`const` bindings, returning a record of functions; the state is
83
+ invisible to consumers and typed by the returned record. *Mutation is the
84
+ discriminator for this bucket.*
85
+ - **pure-fn-candidate.** Every method only reads a readonly stash (config held
86
+ on `this`) without mutation, or operates solely on its own arguments — the
87
+ class is a namespace with a constructor. Replacement: lift each method to a
88
+ module-level function taking the previously-`this` data as a named-field
89
+ argument; the constructor was a deferred first argument and usually collapses
90
+ entirely.
91
+
92
+ Hard heuristic when borderline: **if removing `this` from every method body
93
+ leaves the bodies readable, it's pure-fn; if `this` carries state that genuinely
94
+ advances between calls and is private to the surface, it's closure.** Try the
95
+ substitution mentally; the bucket falls out. If neither test applies cleanly —
96
+ the class is doing several things at once (mutable state *and* derived config
97
+ reads *and* a state-machine identity that arguably deserves its own aggregate) —
98
+ do not invent a fourth bucket and do not pick the closest fit. Surface it as
99
+ `rubric-resistant` and note that a modelling/decomposition lens likely needs to
100
+ split it before this lens can classify the pieces. Single-lens dispatch means
101
+ this lens surfaces ambiguity rather than resolving it.
102
+
103
+ **Closure-candidate that holds context-supplied ports.** When a closure-candidate
104
+ holds port references that the codebase already threads through a shared context
105
+ object (a clock, a logger, a correlation id, or any port carried on the
106
+ composition-side context type), the right rewrite is not "inject the ports
107
+ through the factory" — it is a closure that *binds the context generic* so the
108
+ ports come from context. If the codebase has a rule constraining the
109
+ composition-side generic to extend a context base type, name it as the companion
110
+ citation for this case (the rewrite is "make it a closure that binds the context
111
+ generic", not merely "make it a closure"). That generic-binding rule is owned by
112
+ another lens — cite it as a cross-reference, do not claim it as this lens's. Port
113
+ state that is *not* carried on the shared context (a domain-specific adapter)
114
+ instead goes through an explicit factory closing over those bindings — the plain
115
+ closure-candidate rewrite.
116
+
117
+ ### Iteration pass
118
+
119
+ Every imperative loop site in scope is a candidate. Classify the body and name
120
+ the composition replacement:
121
+
122
+ - **Pure transformation** (the body builds a result from each element) →
123
+ `map`/`reduce`/`flatMap`/`filter`/`Array.from`.
124
+ - **Sequential async with order dependence** → a `reduce` over a Promise chain.
125
+ - **Counted production** (the body emits a value per index) →
126
+ `Array.from({ length }, (_, index) => makeValue(index))`; if it folds into an
127
+ accumulator, chain that with `reduce`.
128
+ - **Side-effect-only** (logging, registering listeners, emitting events) →
129
+ `forEach` whose callback explicitly returns `void` and never `return`s a value.
130
+
131
+ A counted loop that merely indexes into an array (`items[index]`) is a disguised
132
+ element-iteration loop — replace as a transformation, not as a counted
133
+ production. A decrement loop is still a counted-loop finding; the rule covers
134
+ counter-shaped `for`, not a direction. An async-iterator loop has no source-side
135
+ carve-out unless the rules grant one — lift it into a Promise-reduce pipeline or
136
+ an event `forEach` handler by shape.
137
+
138
+ ### Wrapping-factory pass
139
+
140
+ Every raw third-party import (runtime *or* type-only) and every `new X(...)` for
141
+ an external-library class is a candidate. For each: is the importing/instantiating
142
+ file on the rules' closed list of wrapping-factory files for that library? If
143
+ yes → justified. If the library is on the list but the file is not, the import is
144
+ in the wrong place — a function-first finding with a DI/port cross-reference (the
145
+ raw import escaping its wrapping factory is both a structural and a
146
+ boundary-discipline defect; name the boundary lens as the cross-reference). A
147
+ `new X(...)` for a class the codebase itself authored is a finding twice over —
148
+ the class should not have been authored, and the instantiation is the symptom.
149
+
150
+ ### Arity pass
151
+
152
+ Every authored function with two or more parameters is a candidate — and the
153
+ direct sweep is load-bearing because any lint backstop for parameter count is
154
+ typically configured looser than the rule's intent of exactly one. For each: is
155
+ it a callback whose signature is fixed by an external-library contract in the
156
+ rules' closed carve-out list (array-method callbacks, the test framework's
157
+ `test`/`describe`, JS event handlers, the HTTP-framework handler signature)? If
158
+ yes → pass, and confirm the body hands off to a named-field helper at the
159
+ earliest line. Otherwise → finding; the replacement collapses the positional list
160
+ into one named-field object. A lint-suppression annotation placed on a multi-arg
161
+ authored signature to silence the parameter-count check is itself a finding — the
162
+ suppression is masking the rule.
163
+
164
+ For each candidate across all four passes, decide finding vs non-finding strictly
165
+ against the loaded rules and their carve-outs — never against this file's prose or
166
+ a remembered version of some other codebase's rule.
167
+
168
+ ## Letter-vs-intent
169
+
170
+ The lens's catch-rate lives where the surface reads innocent but the stance is
171
+ defeated: a counted `for` that is really element iteration in disguise; a
172
+ "namespace" class that is a pure-fn-candidate dressed as an object; a closure
173
+ that re-injects ports the context already carries instead of binding the context
174
+ generic; a type-only import of a raw library that slips past a runtime-only
175
+ import scan; a lint-suppression that converts a multi-arg signature from a finding
176
+ into apparent compliance. A finding here must explain *how the surface reads
177
+ acceptable yet the rule is defeated*, grounded in the specific loaded rule. Vague
178
+ phrasings ("this could be more functional", "feels imperative") are the lens's own
179
+ failure mode — every finding commits to a bucket or a named replacement.
180
+
181
+ ## Output shape
182
+
183
+ Produce the counts the review asks for across all four axes — class
184
+ declarations by classification (justified / closure-candidate / pure-fn-candidate
185
+ / rubric-resistant), imperative-loop sites by kind (element-iteration vs counted),
186
+ raw-library-import and `new X(...)` sites by in-factory vs out-of-factory, and
187
+ multi-argument authored signatures by carve-out vs finding. Every finding is
188
+ `file:line | quoted code | <rule-id> | defect-named`, citing the loaded rule by
189
+ the discipline id and clause address on the rule page (for example `CD-9#result-failures`), plus the bucket or the named-field/composition
190
+ replacement. Where a finding touches another lens's rule (the context-generic
191
+ binding, the port/boundary discipline), name that as a cross-reference — do not
192
+ re-tag or re-own it. State the rule-page paths you resolved and which rule
193
+ ids you loaded under this lens.
@@ -0,0 +1,127 @@
1
+ # Naming lens
2
+
3
+ A reusable audit method, not a ruleset. The rules it enforces are **data**: load
4
+ every rule page whose `Review lens` line names `naming` from the
5
+ codebase under review and treat their text as authoritative. This file describes
6
+ only *how* the lens reads code — the concept, the inspection procedure, and the
7
+ output shape. It names no specific rule numbers, file paths, type names, or tool
8
+ names; those live in the loaded rules and differ per codebase.
9
+
10
+ ## Concept
11
+
12
+ This lens defends **names as the documentation**: identifiers, file names, and
13
+ folder names must carry the meaning, so the codebase needs no prose to explain
14
+ itself. It has three intertwined strands:
15
+
16
+ - **Identifier meaning.** Every binding site names what it holds. Shorthand and
17
+ single-letter names (a loop index, a one-letter callback parameter) and filler
18
+ words (the generic "data", "value", "result", "info", "params" family) are
19
+ banned because they push the meaning off the page. A short scope is no excuse —
20
+ a reduce-callback parameter or a tuple destructure carries meaning the same way
21
+ a top-level declaration does. Filler words are typically rescued by a
22
+ domain-prefixed compound (the prefix carries the meaning the suffix lacks),
23
+ while shorthand usually has no rescue at all.
24
+ - **No comments.** Prose comments and doc-comment blocks are banned outright;
25
+ only a closed set of machine-meaningful annotations (a tracked TODO, a
26
+ tool-suppression directive) is permitted, and each carries a mandatory tracker
27
+ reference so every escape hatch is owned by a spec or issue.
28
+ - **File and folder names.** Files and folders are named for the abstraction they
29
+ contain, never for a category. A categorical name (the "utils / helpers /
30
+ common / types / misc" family) is the smell of a *missing primitive* — the
31
+ abstraction those contents share has not been found and named. A re-export
32
+ grab-bag barrel sits in the same family.
33
+
34
+ Across codebases the concept recurs under different names (a style guide's
35
+ "intention-revealing names", a "no junk-drawer modules" rule, a "self-documenting
36
+ code" principle). The loaded rules tell you this codebase's exact lists: which
37
+ shorthand and filler tokens are banned, what domain-prefix carve-out exists, which
38
+ filenames and folders are categorical, which annotation forms are permitted and
39
+ their required tracker format, and the case shape filenames must follow. Read them
40
+ first; they override any default intuition.
41
+
42
+ ## Loading the ruleset
43
+
44
+ 1. Resolve the rule pages: `rules/*/README.md` in the Hone install (the folder holding `core/` and `rules/`), and in each rule set the repository's `disciplines.json` names under `ruleSets`.
45
+ 2. Keep the pages whose `Review lens` line names `naming`. **If no rule pages can be read at all, STOP and return CANNOT-REVIEW naming the rule-page paths you resolved.** That is an unloadable ruleset, never a codebase without discipline. Reviewing zero rules would emit a PASS that means nothing.
46
+ 3. Read each kept page in full, including its `## Exceptions` section and the repository's `discipline-exceptions.json` entries for that discipline: those recorded exceptions (authorised locations and carve-outs) are the closed exception list — anything outside them is a finding. Carve-outs that name an exact permitted token (the single allowed single-character name), an exact permitted file (the one allowed barrel root), or a version history are load-bearing: a carve-out the current rule page reinstated or reverted changes the finding count, so cite the version when one is in play.
47
+ 4. If zero rule pages name this lens in their `Review lens` line, report that the codebase declares no naming discipline and produce an empty finding set — do not invent rules.
48
+
49
+ ## Inspection procedure
50
+
51
+ Walk every added or renamed identifier, comment, file, and folder in the diff.
52
+
53
+ - **Shorthand / single-letter identifiers.** Check every binding site against the
54
+ loaded shorthand list: function and lambda parameters, `const`/`let`
55
+ declarations, destructure aliases, tuple destructures, and array-method
56
+ callbacks (map / filter / reduce / find / every / some). Short scope is not a
57
+ defence — a reduce accumulator or a `[k, v]` tuple is in scope. The only
58
+ exempt single-character name is the one the carve-out names, and only when an
59
+ external function-signature contract forces an unused positional parameter; if
60
+ the signature is the codebase's own to change and the parameter is unused, the
61
+ fix is to drop the parameter, not to name it with the placeholder.
62
+ - **Filler-word identifiers.** Check the same binding sites against the loaded
63
+ filler list. A bare filler word is a finding; the rescue is the
64
+ domain-prefixed compound the rule permits (the prefix is what carries the
65
+ meaning). Watch the type-vs-binding distinction: a *type* named with a filler
66
+ suffix can be fine when its prefix does the meaning-carrying work, while a
67
+ *parameter* of that type named bare is still a finding because the call site
68
+ loses what it is for. The domain-prefix carve-out typically covers only the
69
+ filler category, not the shorthand category — confirm against the loaded rule.
70
+ - **Comments and annotations.** Any prose comment or doc-comment block is a
71
+ finding. For each annotation directive (a tracked TODO, a tool-suppression
72
+ line), check it against the closed permitted set and confirm the mandatory
73
+ tracker reference is present and well-formed — a bare directive missing its
74
+ tracker is a finding, and a directive form outside the permitted set (a
75
+ non-tracked marker keyword, a suppression for a tool the codebase does not use)
76
+ is a finding regardless of tracker.
77
+ - **Categorical filenames and folders.** Match every added/renamed file against
78
+ the loaded forbidden-filename list and every path segment against the
79
+ forbidden-folder list. The only permitted re-export barrel is the one site the
80
+ rule names (the package public-surface root); any other per-folder barrel is a
81
+ finding. When the obvious name would have been a categorical one, name the
82
+ finding as a *missing primitive*: ask what the contents share and state the
83
+ re-derived abstraction name as the fix.
84
+ - **Case-shape and scoped overrides.** Filenames bind to a case convention the
85
+ rule states (a kebab/Pascal split by file kind). A name in the wrong case is a
86
+ finding *unless* a scoped filenaming-convention override is in force for that
87
+ path. Treat the closed list of such overrides as data alongside the rules:
88
+ - For each override scope, glob-match it against the diff file list; a scope
89
+ the diff touches is "in play".
90
+ - A touched override that the spec neither narrows (drops for a now-renamed
91
+ subset) nor retires, while it had the opportunity, is the finding — cite the
92
+ override's recorded retirement spec/condition when one exists.
93
+ - A newly-introduced override scope is a finding by default; it is admissible
94
+ only with an accompanying exception record in `discipline-exceptions.json` naming a retirement
95
+ spec or condition. An override with no retirement plan is not admissible.
96
+ - A per-file suppression of the filenaming rule still carries the
97
+ tracker-reference requirement — a bare one is a finding under the comment /
98
+ annotation strand above.
99
+
100
+ For each candidate, decide finding vs non-finding strictly against the loaded
101
+ rules and their carve-outs — never against this file's prose or a remembered
102
+ version of some other codebase's rule.
103
+
104
+ ## Letter-vs-intent
105
+
106
+ The lens's catch-rate lives where a name passes a superficial check but defeats
107
+ the rule: a filler word that *looks* domain-prefixed but whose prefix carries no
108
+ domain meaning; a single-character name claimed as an external-contract
109
+ placeholder that is in fact a name the author didn't think of; a file whose name
110
+ dodges the literal forbidden list yet is still a category dressed up (a "core" or
111
+ "base" junk-drawer); an override that survives untouched through the one spec that
112
+ could have retired it. A finding here must explain *how the name reads acceptable
113
+ yet the rule is defeated*, grounded in the specific loaded rule. Vague phrasings
114
+ ("name is unclear", "this file is a bit of a grab-bag") are the lens's own failure
115
+ mode — name the exact banned token, the exact missing primitive, or the exact
116
+ absent tracker.
117
+
118
+ ## Output shape
119
+
120
+ Produce the counts the review asks for (e.g. shorthand identifiers,
121
+ filler-word identifiers, categorical filenames, categorical folders, untracked or
122
+ forbidden annotations, scoped overrides to narrow/retire). Every finding is
123
+ `file:line | quoted code | <rule-id> | defect-named`, citing the loaded rule by
124
+ the discipline id and clause address on the rule page (for example `CD-9#result-failures`) and naming the expected replacement (the
125
+ domain-meaningful identifier, the re-derived abstraction filename, or the
126
+ tracker-completed annotation). State the rule-page paths you resolved and
127
+ which rule ids you loaded under this lens.