hecks 1.4.0 → 1.5.0

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 (267) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hecks/adapters/driven/claude_code.rb +65 -0
  3. data/lib/hecks/adapters/driven/folder.rb +73 -0
  4. data/lib/hecks/adapters/driven/google_authentication.rb +25 -4
  5. data/lib/hecks/adapters/driven/governance_authorization.rb +57 -6
  6. data/lib/hecks/adapters/driven/heki/journal.rb +8 -0
  7. data/lib/hecks/adapters/driven/heki/saga_store.rb +53 -7
  8. data/lib/hecks/adapters/driven/heki/snapshot.rb +1 -1
  9. data/lib/hecks/adapters/driven/heki.rb +93 -2
  10. data/lib/hecks/adapters/driven/identity_registry.rb +10 -0
  11. data/lib/hecks/adapters/driven/in_memory_ordering.rb +22 -0
  12. data/lib/hecks/adapters/driven/in_process_key_vault.adapter +3 -0
  13. data/lib/hecks/adapters/driven/in_process_key_vault.rb +53 -0
  14. data/lib/hecks/adapters/driven/lambda/client.rb +35 -7
  15. data/lib/hecks/adapters/driven/lambda.rb +43 -2
  16. data/lib/hecks/adapters/driven/local_storage.rb +67 -1
  17. data/lib/hecks/adapters/driven/memory.rb +13 -13
  18. data/lib/hecks/adapters/driven/mock_stripe_adapter.rb +20 -0
  19. data/lib/hecks/adapters/driven/prism.rb +46 -7
  20. data/lib/hecks/adapters/driven/secure_random_identity.rb +3 -0
  21. data/lib/hecks/adapters/driven/system_clock.rb +3 -0
  22. data/lib/hecks/adapters/driven/tenant_provisioner.adapter +3 -0
  23. data/lib/hecks/adapters/driven/tenant_provisioner.rb +66 -0
  24. data/lib/hecks/adapters/driven.rb +2 -0
  25. data/lib/hecks/adapters/driving/github_webhook.rb +14 -1
  26. data/lib/hecks/behaviors/dsl.rb +58 -0
  27. data/lib/hecks/behaviors/expectations.rb +168 -7
  28. data/lib/hecks/behaviors/ir.rb +11 -0
  29. data/lib/hecks/behaviors/rspec.rb +8 -0
  30. data/lib/hecks/behaviors/runner.rb +19 -0
  31. data/lib/hecks/behaviors.rb +8 -0
  32. data/lib/hecks/bluebook/aggregate.rb +30 -0
  33. data/lib/hecks/bluebook/assembly/aggregate_assembly.rb +7 -0
  34. data/lib/hecks/bluebook/assembly/build.rb +25 -4
  35. data/lib/hecks/bluebook/assembly/contract.rb +66 -14
  36. data/lib/hecks/bluebook/assembly/contracts.rb +24 -19
  37. data/lib/hecks/bluebook/assembly/marks.rb +143 -14
  38. data/lib/hecks/bluebook/assembly/specializer.rb +19 -0
  39. data/lib/hecks/bluebook/assembly.rb +25 -7
  40. data/lib/hecks/bluebook/attribute.rb +17 -3
  41. data/lib/hecks/bluebook/behaviour/aggregate.rb +32 -0
  42. data/lib/hecks/bluebook/behaviour/attribute.rb +13 -0
  43. data/lib/hecks/bluebook/behaviour/chapter.rb +55 -2
  44. data/lib/hecks/bluebook/behaviour/command.rb +33 -3
  45. data/lib/hecks/bluebook/behaviour/domain_port.rb +20 -0
  46. data/lib/hecks/bluebook/behaviour/entity.rb +12 -0
  47. data/lib/hecks/bluebook/behaviour/hexagon.rb +26 -0
  48. data/lib/hecks/bluebook/behaviour/lifecycle.rb +23 -2
  49. data/lib/hecks/bluebook/behaviour/policy.rb +34 -9
  50. data/lib/hecks/bluebook/behaviour/process_manager.rb +32 -1
  51. data/lib/hecks/bluebook/behaviour/query.rb +5 -0
  52. data/lib/hecks/bluebook/behaviour/read_model.rb +21 -0
  53. data/lib/hecks/bluebook/behaviour/traits.rb +36 -0
  54. data/lib/hecks/bluebook/behaviour/value_object.rb +17 -5
  55. data/lib/hecks/bluebook/chapter.rb +23 -0
  56. data/lib/hecks/bluebook/command.rb +53 -8
  57. data/lib/hecks/bluebook/domain_port.rb +25 -0
  58. data/lib/hecks/bluebook/dsl/aggregate_builder.rb +196 -37
  59. data/lib/hecks/bluebook/dsl/attribute_collector.rb +79 -42
  60. data/lib/hecks/bluebook/dsl/binding_proxy.rb +59 -0
  61. data/lib/hecks/bluebook/dsl/bluebook_builder/validation.rb +385 -53
  62. data/lib/hecks/bluebook/dsl/bluebook_builder.rb +135 -21
  63. data/lib/hecks/bluebook/dsl/command_builder.rb +189 -27
  64. data/lib/hecks/bluebook/dsl/entity_builder.rb +139 -9
  65. data/lib/hecks/bluebook/dsl/hecksagon_builder.rb +41 -0
  66. data/lib/hecks/bluebook/dsl/identity_declaration.rb +23 -6
  67. data/lib/hecks/bluebook/dsl/policy_builder.rb +60 -19
  68. data/lib/hecks/bluebook/dsl/process_manager_builder.rb +79 -15
  69. data/lib/hecks/bluebook/dsl/query_builder.rb +33 -4
  70. data/lib/hecks/bluebook/dsl/read_model_builder.rb +102 -27
  71. data/lib/hecks/bluebook/dsl/rule_reference.rb +60 -8
  72. data/lib/hecks/bluebook/dsl/translation_builder.rb +146 -40
  73. data/lib/hecks/bluebook/dsl/value_object_builder.rb +55 -7
  74. data/lib/hecks/bluebook/entity.rb +29 -0
  75. data/lib/hecks/bluebook/expression/ast_json.rb +115 -23
  76. data/lib/hecks/bluebook/expression/ast_reader.rb +29 -0
  77. data/lib/hecks/bluebook/expression/canonical_form.rb +48 -9
  78. data/lib/hecks/bluebook/expression/evaluator.rb +207 -29
  79. data/lib/hecks/bluebook/expression/resolver/block_predicates.rb +36 -0
  80. data/lib/hecks/bluebook/expression/resolver.rb +320 -77
  81. data/lib/hecks/bluebook/hexagon.rb +34 -0
  82. data/lib/hecks/bluebook/lifecycle.rb +11 -0
  83. data/lib/hecks/bluebook/meta_validator/adapter_judge.rb +1 -0
  84. data/lib/hecks/bluebook/meta_validator/judge.rb +30 -26
  85. data/lib/hecks/bluebook/meta_validator/plan.rb +43 -8
  86. data/lib/hecks/bluebook/meta_validator/port_judge.rb +1 -0
  87. data/lib/hecks/bluebook/meta_validator/readings.rb +157 -7
  88. data/lib/hecks/bluebook/meta_validator/reconstruction.rb +24 -4
  89. data/lib/hecks/bluebook/meta_validator/shapes.rb +141 -0
  90. data/lib/hecks/bluebook/meta_validator/syntax_boot.rb +149 -23
  91. data/lib/hecks/bluebook/meta_validator/translation_judge.rb +5 -4
  92. data/lib/hecks/bluebook/meta_validator/world_judge.rb +1 -0
  93. data/lib/hecks/bluebook/meta_validator.rb +180 -84
  94. data/lib/hecks/bluebook/model_check.rb +268 -24
  95. data/lib/hecks/bluebook/pattern_subset.rb +23 -1
  96. data/lib/hecks/bluebook/process_manager.rb +13 -0
  97. data/lib/hecks/bluebook/project_discovery.rb +5 -0
  98. data/lib/hecks/bluebook/project_loader.rb +40 -0
  99. data/lib/hecks/bluebook/project_register.rb +44 -0
  100. data/lib/hecks/bluebook/query.rb +27 -0
  101. data/lib/hecks/bluebook/read_model.rb +21 -1
  102. data/lib/hecks/bluebook/reference.rb +21 -8
  103. data/lib/hecks/bluebook/smoke_test.rb +29 -6
  104. data/lib/hecks/bluebook/synthesizer.rb +34 -0
  105. data/lib/hecks/bluebook/translation.rb +30 -1
  106. data/lib/hecks/bluebook/value_object.rb +23 -5
  107. data/lib/hecks/bluebook.rb +3 -4
  108. data/lib/hecks/codemod.rb +107 -20
  109. data/lib/hecks/construct.rb +15 -1
  110. data/lib/hecks/corpus.rb +146 -25
  111. data/lib/hecks/deploy/bluebook/deploy.hecksagon +19 -0
  112. data/lib/hecks/doc/reference.rb +185 -16
  113. data/lib/hecks/embryonaut_bluebook.rb +32 -9
  114. data/lib/hecks/facade/handle.rb +76 -3
  115. data/lib/hecks/facade/surface/aggregate_door.rb +8 -0
  116. data/lib/hecks/forms/field_shape.rb +3 -0
  117. data/lib/hecks/forms/page.rb +14 -0
  118. data/lib/hecks/forms/port_argument.rb +12 -0
  119. data/lib/hecks/forms/query_form_renderer.rb +63 -0
  120. data/lib/hecks/forms/record_renderer.rb +58 -0
  121. data/lib/hecks/forms/record_table.rb +27 -0
  122. data/lib/hecks/forms/reference_options.rb +24 -0
  123. data/lib/hecks/forms/value_object_shape.rb +10 -0
  124. data/lib/hecks/fqn.rb +58 -0
  125. data/lib/hecks/framework/bluebook/privacy.bluebook +155 -0
  126. data/lib/hecks/framework/oidc.json +15 -0
  127. data/lib/hecks/framework.rb +43 -20
  128. data/lib/hecks/freezer.rb +17 -1
  129. data/lib/hecks/fuzzing/bounded_exhaustive_expressions.rb +159 -24
  130. data/lib/hecks/fuzzing/combination_miner.rb +59 -0
  131. data/lib/hecks/fuzzing/concurrent_dispatch.rb +109 -8
  132. data/lib/hecks/fuzzing/coverage_campaign.rb +56 -13
  133. data/lib/hecks/fuzzing/differential.rb +34 -0
  134. data/lib/hecks/fuzzing/domain_generator.rb +188 -11
  135. data/lib/hecks/fuzzing/era_boundary.rb +45 -15
  136. data/lib/hecks/fuzzing/form_census.rb +86 -0
  137. data/lib/hecks/fuzzing/generated_domain_check.rb +76 -0
  138. data/lib/hecks/fuzzing/invalid_value_generator.rb +39 -0
  139. data/lib/hecks/fuzzing/isolated_boot.rb +79 -22
  140. data/lib/hecks/fuzzing/nondeterministic.rb +13 -1
  141. data/lib/hecks/fuzzing/persistence_parity.rb +95 -3
  142. data/lib/hecks/fuzzing/properties/corrections.rb +25 -0
  143. data/lib/hecks/fuzzing/properties/dispatch_and_mutations.rb +158 -14
  144. data/lib/hecks/fuzzing/properties/guards.rb +44 -0
  145. data/lib/hecks/fuzzing/properties/invariants_and_aggregation.rb +48 -0
  146. data/lib/hecks/fuzzing/properties/lifecycle_and_replay.rb +18 -0
  147. data/lib/hecks/fuzzing/properties/outbox.rb +49 -11
  148. data/lib/hecks/fuzzing/properties/querying.rb +68 -14
  149. data/lib/hecks/fuzzing/properties.rb +24 -15
  150. data/lib/hecks/fuzzing/qa_settings.rb +12 -0
  151. data/lib/hecks/fuzzing/replay.rb +137 -29
  152. data/lib/hecks/fuzzing/rotation_priority.rb +41 -21
  153. data/lib/hecks/fuzzing/rust_gap_manifest.rb +46 -20
  154. data/lib/hecks/fuzzing/self_consistency.rb +189 -40
  155. data/lib/hecks/fuzzing/sequence_generator/adversary.rb +12 -6
  156. data/lib/hecks/fuzzing/sequence_generator/step_builder.rb +1 -1
  157. data/lib/hecks/fuzzing/sequence_generator.rb +47 -0
  158. data/lib/hecks/fuzzing/shrinker.rb +114 -2
  159. data/lib/hecks/fuzzing/structural_skips.rb +18 -4
  160. data/lib/hecks/fuzzing/sweep_depth.rb +8 -0
  161. data/lib/hecks/fuzzing/target_capabilities.rb +61 -14
  162. data/lib/hecks/fuzzing/value_generator.rb +98 -10
  163. data/lib/hecks/grammar/evolve.rb +178 -2
  164. data/lib/hecks/grammar.rb +46 -0
  165. data/lib/hecks/ir.rb +38 -7
  166. data/lib/hecks/language/hecksagon/hecksagon.bluebook +11 -0
  167. data/lib/hecks/literal.rb +32 -0
  168. data/lib/hecks/naming.rb +88 -7
  169. data/lib/hecks/ports/access_control.rb +5 -10
  170. data/lib/hecks/ports/authorization.rb +3 -6
  171. data/lib/hecks/ports/identity_assignment.rb +1 -2
  172. data/lib/hecks/ports/identity_resolution.rb +1 -2
  173. data/lib/hecks/ports/key_vault.port +6 -0
  174. data/lib/hecks/ports/key_vault.rb +58 -0
  175. data/lib/hecks/ports/persistence/plugins/era/postgres_era/lineage/tail_merge.rb +6 -0
  176. data/lib/hecks/ports/persistence/plugins/era/postgres_era/lineage_manager/minter.rb +38 -2
  177. data/lib/hecks/ports/persistence/plugins/era/translation/audit/layer_two.rb +6 -0
  178. data/lib/hecks/ports/persistence/plugins/era/translation/rule_compiler.rb +40 -0
  179. data/lib/hecks/ports/persistence/plugins/era/translation/scaffold/differ.rb +92 -1
  180. data/lib/hecks/ports/persistence/plugins/era/translation/scaffold/renderer.rb +15 -0
  181. data/lib/hecks/ports/persistence/plugins/era/translation/scaffold/writer.rb +8 -0
  182. data/lib/hecks/ports/query/in_memory.rb +39 -6
  183. data/lib/hecks/ports/query/ordering.rb +15 -0
  184. data/lib/hecks/ports.rb +1 -0
  185. data/lib/hecks/projections/bootstrap_table.rb +43 -8
  186. data/lib/hecks/projections/diagrams.rb +243 -7
  187. data/lib/hecks/projections/glossary/html.rb +88 -0
  188. data/lib/hecks/projections/glossary/markdown.rb +47 -0
  189. data/lib/hecks/projections/glossary/mermaid.rb +48 -0
  190. data/lib/hecks/projections/glossary/sentences.rb +105 -0
  191. data/lib/hecks/projections/glossary.rb +161 -19
  192. data/lib/hecks/projections/model/deviations.rb +44 -0
  193. data/lib/hecks/projections/model.rb +51 -1
  194. data/lib/hecks/projections/oidc.rb +40 -3
  195. data/lib/hecks/projections/parser_table.rb +49 -8
  196. data/lib/hecks/projections/reference.rb +12 -0
  197. data/lib/hecks/projections/rust_vocabulary.rb +219 -16
  198. data/lib/hecks/projections/shape.rb +8 -0
  199. data/lib/hecks/projections/statements.rb +63 -16
  200. data/lib/hecks/projections/vocabulary.rb +17 -0
  201. data/lib/hecks/projector/cli_projector.rb +218 -10
  202. data/lib/hecks/projector/docs_projector.rb +145 -19
  203. data/lib/hecks/projector/exporter.rb +65 -11
  204. data/lib/hecks/projector/ir_projector.rb +6 -0
  205. data/lib/hecks/projector/narrate_projector.rb +136 -15
  206. data/lib/hecks/projector/target.rb +29 -5
  207. data/lib/hecks/projector.rb +74 -6
  208. data/lib/hecks/query_ir.rb +47 -0
  209. data/lib/hecks/query_specification/common/null_policy.rb +5 -3
  210. data/lib/hecks/rendering.rb +6 -0
  211. data/lib/hecks/router/namespace_installer.rb +13 -0
  212. data/lib/hecks/router.rb +55 -0
  213. data/lib/hecks/runtime/aggregate_lock.rb +9 -0
  214. data/lib/hecks/runtime/boot_gates.rb +18 -0
  215. data/lib/hecks/runtime/caller.rb +32 -0
  216. data/lib/hecks/runtime/capability_graph.rb +11 -0
  217. data/lib/hecks/runtime/command_interpreter/argument_gate.rb +23 -21
  218. data/lib/hecks/runtime/command_interpreter/mutation_applier.rb +14 -15
  219. data/lib/hecks/runtime/command_interpreter.rb +42 -17
  220. data/lib/hecks/runtime/command_rules/admissibility.rb +165 -14
  221. data/lib/hecks/runtime/command_rules/arithmetic.rb +17 -5
  222. data/lib/hecks/runtime/command_rules/references.rb +118 -28
  223. data/lib/hecks/runtime/dependency_planning.rb +45 -0
  224. data/lib/hecks/runtime/dispatcher.rb +28 -50
  225. data/lib/hecks/runtime/entity_element.rb +161 -8
  226. data/lib/hecks/runtime/entity_interpreter.rb +44 -9
  227. data/lib/hecks/runtime/errors.rb +18 -4
  228. data/lib/hecks/runtime/event.rb +10 -5
  229. data/lib/hecks/runtime/identity.rb +71 -3
  230. data/lib/hecks/runtime/instance.rb +67 -7
  231. data/lib/hecks/runtime/interpreting.rb +13 -5
  232. data/lib/hecks/runtime/invocation.rb +118 -36
  233. data/lib/hecks/runtime/loader.rb +94 -8
  234. data/lib/hecks/runtime/outbox.rb +145 -7
  235. data/lib/hecks/runtime/policy_interpreter.rb +22 -9
  236. data/lib/hecks/runtime/port_operation_interpreter.rb +20 -0
  237. data/lib/hecks/runtime/query_interpreter.rb +40 -12
  238. data/lib/hecks/runtime/reaction_invocation.rb +53 -8
  239. data/lib/hecks/runtime/read_model_interpreter.rb +23 -7
  240. data/lib/hecks/runtime/rebuild_sweep.rb +28 -0
  241. data/lib/hecks/runtime/reference_hop.rb +42 -0
  242. data/lib/hecks/runtime/refusal_wording.rb +50 -0
  243. data/lib/hecks/runtime/registry/saga_persistence.rb +11 -0
  244. data/lib/hecks/runtime/registry/verification.rb +119 -4
  245. data/lib/hecks/runtime/registry.rb +157 -4
  246. data/lib/hecks/runtime/remote_dispatcher.rb +92 -6
  247. data/lib/hecks/runtime/routing.rb +27 -2
  248. data/lib/hecks/runtime/saga_interpreter/correlation.rb +10 -12
  249. data/lib/hecks/runtime/saga_interpreter.rb +27 -13
  250. data/lib/hecks/runtime/tenant_check.rb +26 -6
  251. data/lib/hecks/runtime/tenant_scope.rb +18 -0
  252. data/lib/hecks/runtime/value/coercion.rb +255 -33
  253. data/lib/hecks/runtime/value/entity_list_coercion.rb +102 -30
  254. data/lib/hecks/runtime/value.rb +50 -0
  255. data/lib/hecks/runtime.rb +32 -0
  256. data/lib/hecks/storehouse.rb +305 -9
  257. data/lib/hecks/tenancy/bluebook/tenancy.bluebook +130 -0
  258. data/lib/hecks/tenancy/bluebook/tenancy.hecksagon +32 -0
  259. data/lib/hecks/version.rb +1 -1
  260. data/lib/hecks.rb +79 -1
  261. data/lib/rubocop/cop/hecks/fallback_hash_lookup.rb +8 -0
  262. data/lib/rubocop/cop/hecks/sequential_hash_rename_in_loop.rb +12 -2
  263. data/lib/rubocop/cop/hecks/thread_shared_ivar_mutation.rb +29 -5
  264. metadata +11 -5
  265. data/lib/hecks/codemod/legacy_dispatch_args.rb +0 -299
  266. data/lib/hecks/codemod/legacy_dispatch_recorder.rb +0 -186
  267. data/lib/hecks/deprecation.rb +0 -95
@@ -22,6 +22,7 @@ module Hecks
22
22
  class TranslationJudge
23
23
  attr_reader :refusals
24
24
 
25
+ # @param translation [Bluebook::Translation] the built translation to judge
25
26
  def initialize(translation)
26
27
  @translation = translation
27
28
  @refusals = []
@@ -43,10 +44,10 @@ module Hecks
43
44
  # their own runtime. `TranslationBuilder#aggregate` appends every
44
45
  # block to a plain Array (`@aggregates << builder.build`) with no
45
46
  # dedup — two `aggregate "Account" do ... end` blocks in the same
46
- # translation are syntactically legal and reach here for real. Left
47
- # unrescued, the second Declare's `AlreadyExists` crashed straight
48
- # through `call_translation` instead of becoming a clean refusal —
49
- # confirmed via direct dispatch before this fix.
47
+ # translation are syntactically legal and reach here for real.
48
+ # Left unrescued, the second Declare's `AlreadyExists` would crash
49
+ # straight through `call_translation` instead of becoming a clean
50
+ # refusal — confirmed via direct dispatch.
50
51
  def offer(label)
51
52
  yield
52
53
  rescue Runtime::GivenNotMet, Runtime::InvariantViolation, Runtime::TypeMismatch,
@@ -10,6 +10,7 @@ module Hecks
10
10
  class WorldJudge
11
11
  attr_reader :refusals
12
12
 
13
+ # @param world [Bluebook::World] the built world to judge
13
14
  def initialize(world)
14
15
  @world = world
15
16
  @refusals = []
@@ -16,9 +16,11 @@ module Hecks
16
16
  # `given`/`invariant` here, where they are declarations any reader of the
17
17
  # meta-domain can consume instead of behavior buried in a builder.
18
18
  #
19
- # **This migration is partial, not done**. As of this writing the meta-domain
20
- # declares 62 given/invariant/ensures rules (`Hecks::QueryIR.collect_rules`
21
- # against `grammar_registry.bluebook("Bluebook")` enumerates them) —
19
+ # ## This migration is partial, not done
20
+ #
21
+ # As of this writing the meta-domain declares 62 given/invariant/ensures
22
+ # rules (`Hecks::QueryIR.collect_rules` against
23
+ # `grammar_registry.bluebook("Bluebook")` enumerates them) —
22
24
  # `spec/meta_rule_reachability_spec.rb` is what proves, per declaration,
23
25
  # not per verb, that most of them still lack a spec exercising the
24
26
  # refusal at all (see that file's own KNOWN_GAPS for the current count).
@@ -35,12 +37,13 @@ module Hecks
35
37
  # So: "delete language/bluebook/ and validation stops" is true for the 62
36
38
  # rules actually declared here, and false for whatever a builder's own
37
39
  # `raise Malformed` still checks — the language does not yet own its own
38
- # enforcement end to end, and this comment used to claim it already did.
39
- # The self-hosting mechanism itself is real and is the point worth
40
- # keeping : a self-description that only describes is indistinguishable
41
- # from enforcement, and the first version of this file was deleted for
42
- # exactly that reason. What is not yet real is that self-hosting being
43
- # the whole of validation.
40
+ # enforcement end to end. The self-hosting mechanism itself is real and
41
+ # is the point worth keeping : a self-description that only describes is
42
+ # indistinguishable from enforcement, and the first version of this file
43
+ # was deleted for exactly that reason. What is not yet real is that
44
+ # self-hosting being the whole of validation.
45
+ #
46
+ # ## Isolation
44
47
  #
45
48
  # The meta-domain is loaded once and its registry reused ; each bluebook is
46
49
  # judged in a fresh in-memory store so no domain can see another's records.
@@ -97,6 +100,9 @@ module Hecks
97
100
  # is only the first pass. Once every grammar file is loaded and merged,
98
101
  # grammar_registry judges the language through itself and keeps the
99
102
  # assembled result (the fixpoint, made load-bearing).
103
+ #
104
+ # @return [Boolean] whether the language's own grammar is still
105
+ # loading raw, unjudged
100
106
  def self.bootstrapping? = @bootstrapping
101
107
 
102
108
  # A chapter may be split across files, so it cannot be judged until
@@ -123,8 +129,17 @@ module Hecks
123
129
  # Re-judging one already assembled — a framework member pulled in
124
130
  # earlier by `uses_framework`, say — would re-run Assembly and hand
125
131
  # out a second set of classes for a graph something already holds.
132
+ #
133
+ # @return [Boolean] whether `call` is currently queuing chapters
134
+ # instead of judging them
126
135
  def self.deferring? = @deferring
127
136
 
137
+ # Opens the two-phase-load window: every chapter `call` sees while
138
+ # the block runs is queued (see `deferred_chapters`) rather than
139
+ # judged immediately.
140
+ #
141
+ # @yield the caller's own load of every file in one chapter window
142
+ # @return [Object] the block's own return value
128
143
  def self.defer
129
144
  previous = @deferring
130
145
  @deferring = true
@@ -133,8 +148,22 @@ module Hecks
133
148
  @deferring = previous
134
149
  end
135
150
 
151
+ # The chapters queued while `defer`'s block ran, awaiting
152
+ # `judge_deferred!`.
153
+ #
154
+ # @return [Array<String>] each deferred chapter's own `hecks_name`,
155
+ # queued during the current or most recent `defer` window
136
156
  def self.deferred_chapters = @deferred_chapters ||= []
137
157
 
158
+ # Judges every chapter queued by `defer`, once each, then clears the
159
+ # queue.
160
+ #
161
+ # @param registry [Runtime::Registry, nil] the registry to judge
162
+ # against; a no-op if `nil`
163
+ # @return [void]
164
+ # @raise [DSL::Malformed] if a chapter's own whole-chapter battery
165
+ # (`BluebookBuilder.validate_assembled!`) or the meta-domain itself
166
+ # (`call`) refuses it
138
167
  def self.judge_deferred!(registry)
139
168
  pending = deferred_chapters.uniq
140
169
  @deferred_chapters = []
@@ -178,30 +207,32 @@ module Hecks
178
207
 
179
208
  # `&& !@forcing_fixpoint` — see `while_forcing_fixpoint` below, whose own
180
209
  # window must win even while a growth spec's `while_disabled` is open,
181
- # for the reason recorded there. Otherwise the same stack-restore shape
182
- # `while_shadow_parsing`/`while_forcing_fixpoint` use, not a bare env
183
- # toggle any more — it used to be exactly that (`ENV["HECKS_META_
184
- # VALIDATION"] == "off"`, read directly, with no `previous`/`ensure` of
185
- # its own), and the gap between "bare toggle" and "stack-restore" was
186
- # not cosmetic: a test's temporary window could reach code it was never
187
- # meant to touch. If `grammar_registry`'s one-time lazy build (below)
188
- # happened to land inside that window, every language chapter got
189
- # cached in its raw, never-judged form for the rest of the process —
190
- # `unmark_scalar`'s String->Integer/Boolean fix (assembly/marks.rb)
191
- # never ran, so a `Command`'s own `required: true` stayed
192
- # `required: "true"` forever after, permanently memoized. Found live:
193
- # an intermittent, parallel_rspec-only ir_golden_spec.rb failure,
194
- # order-dependent on whether identifier_numeric_coercion_growth_spec.rb's
210
+ # for the reason recorded there. Uses the same stack-restore shape
211
+ # `while_shadow_parsing`/`while_forcing_fixpoint` use, deliberately not
212
+ # a bare env toggle (`ENV["HECKS_META_VALIDATION"] == "off"`, read
213
+ # directly, with no `previous`/`ensure` of its own): the gap between
214
+ # "bare toggle" and "stack-restore" is not cosmetic — a test's
215
+ # temporary window could reach code it was never meant to touch. If
216
+ # `grammar_registry`'s one-time lazy build (below) happens to land
217
+ # inside that window, every language chapter gets cached in its raw,
218
+ # never-judged form for the rest of the process — `unmark_scalar`'s
219
+ # String->Integer/Boolean fix (assembly/marks.rb) never runs, so a
220
+ # `Command`'s own `required: true` stays `required: "true"` forever
221
+ # after, permanently memoized. Found live: an intermittent,
222
+ # parallel_rspec-only ir_golden_spec.rb failure, order-dependent on
223
+ # whether identifier_numeric_coercion_growth_spec.rb's
195
224
  # disabled-validation window raced the one lazy build in its own worker
196
225
  # process — reproduced in isolation by disabling validation before the
197
226
  # first `grammar_registry` call. `&& !@forcing_fixpoint` was the first
198
- # fix and is kept ; converting `@disabled` itself to this shape closes
199
- # the gap for every other caller of `while_disabled`, not just the one
200
- # race that was actually observed — nothing outside this file reads
201
- # `ENV["HECKS_META_VALIDATION"]` any more (confirmed: every one of the
202
- # dozen growth specs that used to hand-roll `previous = ENV[...] ;
203
- # ENV[...] = "off" ; ... ; ensure ENV[...] = previous` now calls
204
- # `while_disabled` instead), so there is no bare global left to race.
227
+ # fix and is kept ; `@disabled` itself uses this same stack-restore
228
+ # shape to close the gap for every other caller of `while_disabled`,
229
+ # not just the one race that was actually observed — nothing outside
230
+ # this file reads `ENV["HECKS_META_VALIDATION"]` (every growth spec
231
+ # calls `while_disabled` instead), so there is no bare global left to
232
+ # race.
233
+ #
234
+ # @return [Boolean] whether meta-domain judging is currently switched
235
+ # off (and not overridden by a fixpoint build in progress)
205
236
  def self.disabled? = @disabled && !@forcing_fixpoint
206
237
 
207
238
  # The same stack-restore shape `while_shadow_parsing`/`while_forcing_
@@ -211,6 +242,9 @@ module Hecks
211
242
  # bounded window around one boot, never a flag meant to survive past
212
243
  # it, so the flag itself is scoped in the same `previous`/`ensure`
213
244
  # shape rather than a plain assignment a caller could forget to undo.
245
+ #
246
+ # @yield the caller's own boot, with `disabled?` true throughout
247
+ # @return [Object] the block's own return value
214
248
  def self.while_disabled
215
249
  previous = @disabled
216
250
  @disabled = true
@@ -230,13 +264,19 @@ module Hecks
230
264
  # the meta-domain, never duplicated as a builder's own `raise
231
265
  # Malformed` (`vision`'s own comment: "moved to the language").
232
266
  #
233
- # Mirrors `defer`'s own stack-restore shape, not `disabled?`'s bare
234
- # env toggle — this must never leak past the one shadow-parse call
235
- # that set it, the same reason `ConstShim.with`/`.active?`
236
- # (bluebook/dsl/const_shim.rb) restores in an `ensure` rather than
237
- # being flipped and left.
267
+ # Mirrors `defer`'s own stack-restore shape — this must never leak
268
+ # past the one shadow-parse call that set it, the same reason
269
+ # `ConstShim.with`/`.active?` (bluebook/dsl/const_shim.rb) restores in
270
+ # an `ensure` rather than being flipped and left.
271
+ #
272
+ # @return [Boolean] whether frozen era text is currently being
273
+ # shadow-parsed
238
274
  def self.shadow_parsing? = @shadow_parsing
239
275
 
276
+ # Wraps `block` with `shadow_parsing?` true, restoring it afterward.
277
+ #
278
+ # @yield the caller's own shadow-parse of one piece of frozen era text
279
+ # @return [Object] the block's own return value
240
280
  def self.while_shadow_parsing
241
281
  previous = @shadow_parsing
242
282
  @shadow_parsing = true
@@ -247,11 +287,15 @@ module Hecks
247
287
 
248
288
  # The same stack-restore shape `while_shadow_parsing` uses, for the
249
289
  # same reason: whatever this wraps must never see `disabled?` answer
250
- # true, however a test elsewhere has the env toggle set at that
251
- # exact moment. Only `grammar_registry`'s own one-time build (below)
252
- # wraps itself in this — nothing else needs it, and nothing else
253
- # should reach for it just to dodge `disabled?` for a domain
290
+ # true, however a test elsewhere has a `while_disabled` window open at
291
+ # that exact moment. Only `grammar_registry`'s own one-time build
292
+ # (below) wraps itself in this — nothing else needs it, and nothing
293
+ # else should reach for it just to dodge `disabled?` for a domain
254
294
  # bluebook, which is precisely the toggle's real, intended use.
295
+ #
296
+ # @yield the one-time fixpoint build, with `disabled?` forced false
297
+ # throughout
298
+ # @return [Object] the block's own return value
255
299
  def self.while_forcing_fixpoint
256
300
  previous = @forcing_fixpoint
257
301
  @forcing_fixpoint = true
@@ -263,10 +307,20 @@ module Hecks
263
307
  # The same bluebook judged twice gets the same verdict, and a suite reloads
264
308
  # its fixtures constantly — banking alone is ~200 dispatches per build.
265
309
  # Keyed on the IR itself, so a changed bluebook is always re-judged.
310
+ #
311
+ # @return [Hash{String => Array<String>}] the process-wide judging
312
+ # cache, keyed by a SHA-256 digest of the judged artifact; each
313
+ # value is that artifact's own list of refusal messages (`[]` when
314
+ # well formed)
266
315
  def self.verdicts = @verdicts ||= {}
267
316
 
268
317
  # A world is not a bluebook, so it gets its own door. Same judge, same
269
318
  # meta-domain registry — a different artifact and a different language file.
319
+ #
320
+ # @param world [Bluebook::World] the world to judge
321
+ # @return [Bluebook::World] `world` unchanged, if well formed or
322
+ # while disabled/bootstrapping/shadow-parsing
323
+ # @raise [DSL::Malformed] if `WorldJudge` finds `world` malformed
270
324
  def self.call_world(world)
271
325
  return world if disabled? || bootstrapping? || shadow_parsing?
272
326
 
@@ -281,6 +335,11 @@ module Hecks
281
335
  # A port is not a bluebook either — same door shape as call_world,
282
336
  # one artifact over. Whole-project table-unification survey, item
283
337
  # #13's remaining builders.
338
+ #
339
+ # @param port [Bluebook::Port] the port to judge
340
+ # @return [Bluebook::Port] `port` unchanged, if well formed or while
341
+ # disabled/bootstrapping/shadow-parsing
342
+ # @raise [DSL::Malformed] if `PortJudge` finds `port` malformed
284
343
  def self.call_port(port)
285
344
  return port if disabled? || bootstrapping? || shadow_parsing?
286
345
 
@@ -295,6 +354,11 @@ module Hecks
295
354
  # An adapter is not a bluebook either — same door shape, one more
296
355
  # artifact over. Whole-project table-unification survey, item
297
356
  # #13's remaining builders.
357
+ #
358
+ # @param adapter [Bluebook::Adapter] the adapter to judge
359
+ # @return [Bluebook::Adapter] `adapter` unchanged, if well formed or
360
+ # while disabled/bootstrapping/shadow-parsing
361
+ # @raise [DSL::Malformed] if `AdapterJudge` finds `adapter` malformed
298
362
  def self.call_adapter(adapter)
299
363
  return adapter if disabled? || bootstrapping? || shadow_parsing?
300
364
 
@@ -317,6 +381,12 @@ module Hecks
317
381
  # in one pass over `World::World.Declare`'s own caller, not from a
318
382
  # separate door per binding. Whole-project table-unification survey,
319
383
  # item #13's remaining builders.
384
+ #
385
+ # @param translation [Bluebook::Translation] the translation to judge
386
+ # @return [Bluebook::Translation] `translation` unchanged, if well
387
+ # formed or while disabled/bootstrapping/shadow-parsing
388
+ # @raise [DSL::Malformed] if `TranslationJudge` finds `translation`
389
+ # malformed
320
390
  def self.call_translation(translation)
321
391
  return translation if disabled? || bootstrapping? || shadow_parsing?
322
392
 
@@ -339,53 +409,52 @@ module Hecks
339
409
 
340
410
  # The language hands the graph back.
341
411
  #
342
- # This used to return the bluebook it was given — dispatch every declaration
343
- # in, collect refusals, throw the records away — which is all judging needs
344
- # and exactly why the language could only validate. It returns what the
345
- # meta-domain holds instead, assembled into the graph the runtime runs. The
346
- # builder's own object graph now exists only to be dispatched; nothing keeps
347
- # it.
348
- #
349
- # `Hecks.bluebook` registers whatever comes back from here, so this one line
350
- # is the difference between a language that checks a domain and a language
351
- # that is the source of one.
352
- #
353
- # What is cached is the declarations, not the graph. A hash carries no Ruby
354
- # classes, so a second load of the same chapter re-assembles fresh ones —
355
- # which is the behaviour `Namespace.install` and `spec/construct_spec` both
356
- # expect. Caching the graph would hand two boots the same classes.
357
- # The language is the source. This is the line that makes it one.
358
- #
359
- # `Hecks.bluebook` registers whatever comes back from here, so returning the
360
- # assembled graph rather than the bluebook it was handed is the whole swap: the
361
- # runtime runs what the meta-domain holds. The builder's own graph exists only
362
- # to be dispatched in ; nothing keeps it.
363
- #
364
- # It stayed unlanded for one wrong belief, worth naming because it looked so
365
- # much like a wall: that the language may only hold what `to_h` carries.
366
- # `ReadModel#to_h` omitted a read model's filters until 2026-08-11, so
367
- # read-model filtering seemed impossible to read back —
368
- # and hoisted policies lost which head declared them for the same reason.
369
- # But `to_h` is a projection and the language is the
370
- # source. They must agree about everything to_h spells ; they need not be the
371
- # same size. Both were held even before the wire format carried them, as
372
- # declarations the wire format didn't yet see.
373
- #
374
- # Update, 2026-08-11: the wire format did move, on purpose, for a reason
375
- # unrelated to this file — a Rust-codegen task needed `wheres`/
376
- # `order_by`/`limit` on the wire to compile a read model's real declared
377
- # filtering, and the boundary described above was never load-bearing for
378
- # this mechanism (`option_rows`/`filter_options` in meta_validator/
379
- # readings.rb read `node.wheres`/`node.order_by`/`node.limit` off the
380
- # live object directly, never off `to_h`), so extending `to_h` changed
381
- # nothing here. `ReadModel#to_h` now spells all three explicitly, the
382
- # same mechanism `Query#to_h` already used — purely additive, still
412
+ # A bluebook judged elsewhere only checks: dispatch every declaration
413
+ # in, collect refusals, throw the records away — which is all a
414
+ # boundary check needs. This is the one call that returns what the
415
+ # meta-domain holds instead, assembled into the graph the runtime
416
+ # runs, so the builder's own object graph exists only to be
417
+ # dispatched — nothing keeps it. `Hecks.bluebook` registers whatever
418
+ # comes back from here, so this one line is the difference between a
419
+ # language that checks a domain and a language that is the source of
420
+ # one: the runtime runs what the meta-domain holds, not the builder's
421
+ # own graph.
422
+ #
423
+ # What is cached is the declarations, not the graph. A hash carries no
424
+ # Ruby classes, so a second load of the same chapter re-assembles
425
+ # fresh ones — the behaviour `Namespace.install` and
426
+ # `spec/construct_spec` both expect. Caching the graph would hand two
427
+ # boots the same classes.
428
+ #
429
+ # One belief stayed unlanded for a while, worth naming because it
430
+ # looked so much like a wall: that the language may only hold what
431
+ # `to_h` carries. `ReadModel#to_h` omitted a read model's filters
432
+ # until 2026-08-11, so read-model filtering seemed impossible to read
433
+ # back — and hoisted policies lost which head declared them for the
434
+ # same reason. But `to_h` is a projection and the language is the
435
+ # source. They must agree about everything `to_h` spells ; they need
436
+ # not be the same size. Both were held even before the wire format
437
+ # carried them, as declarations the wire format didn't yet see.
438
+ #
439
+ # The wire format did later move, for a reason unrelated to this
440
+ # file — a Rust-codegen task needed `wheres`/`order_by`/`limit` on
441
+ # the wire to compile a read model's real declared filtering, and the
442
+ # boundary described above was never load-bearing for this mechanism
443
+ # (`option_rows`/`filter_options` in meta_validator/readings.rb read
444
+ # `node.wheres`/`node.order_by`/`node.limit` off the live object
445
+ # directly, never off `to_h`), so extending `to_h` changed nothing
446
+ # here. `ReadModel#to_h` now spells all three explicitly, the same
447
+ # mechanism `Query#to_h` already used — purely additive, still
383
448
  # agreeing with the language about everything it spells.
384
449
  #
385
- # What is cached is the declarations, not the graph. A hash carries no Ruby
386
- # classes, so a second load of the same chapter assembles fresh ones — which is
387
- # what `Namespace.install` and `spec/construct_spec` both expect. Caching the
388
- # graph would hand two boots the same classes.
450
+ # @param bluebook [Object] a built bluebook chapter graph (an
451
+ # `Aggregate`/`Entity`/`ValueObject`/... instance from
452
+ # `lib/hecks/bluebook/`), answering `to_h` and `hecks_name`
453
+ # @return [Object] `bluebook` unchanged while disabled, bootstrapping,
454
+ # shadow-parsing, or deferring; otherwise the graph the meta-domain
455
+ # assembles from its own judged declarations
456
+ # @raise [DSL::Malformed] if the meta-domain refuses any of
457
+ # `bluebook`'s declarations
389
458
  def self.call(bluebook)
390
459
  return bluebook if disabled? || bootstrapping? || shadow_parsing?
391
460
 
@@ -408,6 +477,13 @@ module Hecks
408
477
  # Dispatch it in and read it back. A refused chapter has no declarations to
409
478
  # read — the records are half-written by definition — so it carries refusals
410
479
  # and nothing else.
480
+ #
481
+ # @param bluebook [Object] a built bluebook chapter graph, as `call`
482
+ # receives it
483
+ # @return [Hash{Symbol => Object}] `{refusals: [...]}` when `Judge`
484
+ # refuses any declaration; otherwise `{refusals: [],
485
+ # declaration: Hash}`, the assembled graph `Reconstruction.of` reads
486
+ # back from the judged records
411
487
  def self.hold(bluebook)
412
488
  judge = Judge.new(bluebook)
413
489
  return { refusals: judge.refusals } unless judge.refusals.empty?
@@ -415,6 +491,11 @@ module Hecks
415
491
  { refusals: [], declaration: Reconstruction.of(judge.runtime, bluebook.hecks_name) }
416
492
  end
417
493
 
494
+ # The booted, self-judged language registry every ordinary bluebook is
495
+ # judged against — built once per process and memoized.
496
+ #
497
+ # @return [Runtime::Registry] the booted, fixpoint-judged language
498
+ # registry
418
499
  def self.grammar_registry
419
500
  @grammar_registry ||= begin
420
501
  registry = load_grammar_into(Runtime::Registry.new)
@@ -470,6 +551,9 @@ module Hecks
470
551
  # the snapshot is a function of. Kept here for any other derived
471
552
  # cache that genuinely needs "is the build finished" rather than
472
553
  # "have my inputs changed".
554
+ #
555
+ # @return [Boolean] whether `grammar_registry`'s memoized singleton
556
+ # has finished its fixpoint judge and attached-chapter load
473
557
  def self.grammar_registry_ready?
474
558
  @grammar_registry && @grammar_ready_for == @grammar_registry.object_id
475
559
  end
@@ -481,6 +565,10 @@ module Hecks
481
565
  # `MetaValidator.call`, `bootstrapping?` already false). A directory
482
566
  # with nothing in it loads nothing ; this is a no-op until a chapter
483
567
  # is added there.
568
+ #
569
+ # @param registry [Runtime::Registry] the registry to load every
570
+ # `ATTACHED_GRAMMAR_DIR` chapter file into
571
+ # @return [void]
484
572
  def self.load_attached_grammar_into(registry)
485
573
  Hecks.with_registry(registry) do
486
574
  Dir.glob(File.join(ATTACHED_GRAMMAR_DIR, "*.bluebook")).each { |file| Kernel.load(file) }
@@ -504,6 +592,11 @@ module Hecks
504
592
  # refuses immediately, since `Aggregate.Attribute` references `ValueObject`
505
593
  # and `Aggregate.Holds` references `Entity`, both declared in later files.
506
594
  # Every caller of the grammar must go through here for exactly that reason.
595
+ #
596
+ # @param registry [Runtime::Registry] the registry to load the whole
597
+ # grammar (ports, adapters, and every language chapter) into, raw
598
+ # and unjudged
599
+ # @return [Runtime::Registry] `registry`, unchanged in identity
507
600
  def self.load_grammar_into(registry)
508
601
  @bootstrapping = true
509
602
  Hecks.with_registry(registry) do
@@ -532,6 +625,9 @@ module Hecks
532
625
  # No `bind_runtime` here : judging dispatches by FQN and never opens the
533
626
  # door, and binding would re-install the language's own facade constants
534
627
  # once per judged chapter.
628
+ #
629
+ # @return [Runtime::Dispatcher] a dispatcher over the shared grammar
630
+ # registry, with its records cleared
535
631
  def self.fresh_runtime
536
632
  registry = grammar_registry
537
633
  registry.instance_variable_set(:@repositories, {})