rigortype 0.4.8 → 0.4.9

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 (349) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/docs/handbook/01-getting-started.md +1 -1
  4. data/docs/handbook/04-tuples-and-shapes.md +6 -1
  5. data/docs/handbook/12-lightweight-hkt.md +1 -1
  6. data/docs/handbook/appendix-typescript.md +28 -17
  7. data/docs/manual/02-cli-reference.md +10 -0
  8. data/docs/manual/03-configuration.md +1 -1
  9. data/docs/manual/04-diagnostics.md +1 -1
  10. data/docs/manual/10-mcp-server.md +122 -10
  11. data/docs/manual/plugins/rigor-activerecord.md +7 -0
  12. data/lib/rigor/analysis/check_rules/always_raises.rb +95 -0
  13. data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +32 -2
  14. data/lib/rigor/analysis/check_rules/argument_type.rb +802 -0
  15. data/lib/rigor/analysis/check_rules/call_facts.rb +2 -2
  16. data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +30 -1
  17. data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -5
  18. data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +34 -0
  19. data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +131 -4
  20. data/lib/rigor/analysis/check_rules/nil_receiver.rb +195 -0
  21. data/lib/rigor/analysis/check_rules/override_param_narrowed.rb +111 -0
  22. data/lib/rigor/analysis/check_rules/override_return_widened.rb +88 -0
  23. data/lib/rigor/analysis/check_rules/override_support.rb +246 -0
  24. data/lib/rigor/analysis/check_rules/override_visibility.rb +135 -0
  25. data/lib/rigor/analysis/check_rules/published_constant_guard.rb +75 -31
  26. data/lib/rigor/analysis/check_rules/raise_non_exception.rb +198 -0
  27. data/lib/rigor/analysis/check_rules/receiver_predicates.rb +576 -0
  28. data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +52 -4
  29. data/lib/rigor/analysis/check_rules/return_type.rb +225 -0
  30. data/lib/rigor/analysis/check_rules/rigor_testing.rb +119 -0
  31. data/lib/rigor/analysis/check_rules/rule_ids.rb +7 -7
  32. data/lib/rigor/analysis/check_rules/rule_walk.rb +4 -3
  33. data/lib/rigor/analysis/check_rules/self_closedness_scanner.rb +2 -0
  34. data/lib/rigor/analysis/check_rules/self_undefined_method.rb +165 -0
  35. data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +34 -0
  36. data/lib/rigor/analysis/check_rules/source_arity.rb +2 -2
  37. data/lib/rigor/analysis/check_rules/special_global_write.rb +256 -0
  38. data/lib/rigor/analysis/check_rules/suppression.rb +275 -0
  39. data/lib/rigor/analysis/check_rules/undefined_method.rb +882 -0
  40. data/lib/rigor/analysis/check_rules/unreachable_branch.rb +97 -0
  41. data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +42 -0
  42. data/lib/rigor/analysis/check_rules/unresolved_toplevel.rb +140 -0
  43. data/lib/rigor/analysis/check_rules/visibility_mismatch.rb +252 -0
  44. data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +27 -0
  45. data/lib/rigor/analysis/check_rules/wrong_arity.rb +303 -0
  46. data/lib/rigor/analysis/check_rules.rb +66 -4931
  47. data/lib/rigor/analysis/dependency_recorder.rb +1 -1
  48. data/lib/rigor/analysis/dependency_source_inference/builder.rb +2 -4
  49. data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -2
  50. data/lib/rigor/analysis/dependency_source_inference/walker.rb +15 -15
  51. data/lib/rigor/analysis/incremental_session.rb +4 -4
  52. data/lib/rigor/analysis/path_expansion.rb +1 -1
  53. data/lib/rigor/analysis/plugin_fact_fingerprint.rb +5 -5
  54. data/lib/rigor/analysis/reachability/graph.rb +2 -3
  55. data/lib/rigor/analysis/reachability/plugin_roots.rb +2 -2
  56. data/lib/rigor/analysis/reachability/scan.rb +2 -2
  57. data/lib/rigor/analysis/rule_catalog.rb +2 -1
  58. data/lib/rigor/analysis/run_cache_key.rb +9 -8
  59. data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
  60. data/lib/rigor/analysis/runner/dependency_rows.rb +206 -0
  61. data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +24 -22
  62. data/lib/rigor/analysis/runner/effect_cache_entries.rb +69 -0
  63. data/lib/rigor/analysis/runner/pool_coordinator.rb +6 -8
  64. data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -5
  65. data/lib/rigor/analysis/runner/scope_seed.rb +144 -0
  66. data/lib/rigor/analysis/runner.rb +49 -296
  67. data/lib/rigor/analysis/template_unit_collector.rb +1 -1
  68. data/lib/rigor/analysis/template_units.rb +10 -10
  69. data/lib/rigor/analysis/worker_session.rb +7 -7
  70. data/lib/rigor/bleeding_edge.rb +3 -2
  71. data/lib/rigor/builtins/hkt_builtins.rb +17 -17
  72. data/lib/rigor/builtins/imported_refinements.rb +8 -16
  73. data/lib/rigor/builtins/regex_refinement.rb +3 -3
  74. data/lib/rigor/builtins/static_return_refinements.rb +143 -19
  75. data/lib/rigor/cache/incremental_snapshot.rb +21 -8
  76. data/lib/rigor/cache/rbs_descriptor.rb +18 -1
  77. data/lib/rigor/cli/coverage_renderer.rb +15 -1
  78. data/lib/rigor/cli/coverage_report.rb +19 -1
  79. data/lib/rigor/cli/diagnostic_formats.rb +3 -2
  80. data/lib/rigor/cli/docs_command.rb +5 -5
  81. data/lib/rigor/cli/effects_command.rb +7 -6
  82. data/lib/rigor/cli/fused_protection_report.rb +7 -7
  83. data/lib/rigor/cli/lsp_command.rb +1 -1
  84. data/lib/rigor/cli/mcp_command.rb +5 -2
  85. data/lib/rigor/cli/options.rb +4 -0
  86. data/lib/rigor/cli/plugins_command.rb +1 -1
  87. data/lib/rigor/cli/sig_gen_command.rb +1 -1
  88. data/lib/rigor/cli/skill_command.rb +5 -4
  89. data/lib/rigor/cli/triage_renderer.rb +3 -2
  90. data/lib/rigor/cli/unused_command.rb +4 -4
  91. data/lib/rigor/cli.rb +14 -0
  92. data/lib/rigor/configuration/coercion.rb +418 -0
  93. data/lib/rigor/configuration/defaults.rb +248 -0
  94. data/lib/rigor/configuration/dependencies.rb +1 -1
  95. data/lib/rigor/configuration/loader.rb +354 -0
  96. data/lib/rigor/configuration/severity_profile.rb +4 -4
  97. data/lib/rigor/configuration.rb +51 -860
  98. data/lib/rigor/effects/attribution.rb +1 -1
  99. data/lib/rigor/effects/effect_table.rb +1 -1
  100. data/lib/rigor/effects/identity.rb +3 -3
  101. data/lib/rigor/effects/local_ownership.rb +2 -2
  102. data/lib/rigor/effects/snapshot.rb +1 -1
  103. data/lib/rigor/effects/summary.rb +5 -4
  104. data/lib/rigor/environment/member_consistency.rb +10 -0
  105. data/lib/rigor/environment/rbs_loader.rb +19 -22
  106. data/lib/rigor/environment/reflection.rb +1 -1
  107. data/lib/rigor/environment/unreadable_signature.rb +21 -0
  108. data/lib/rigor/environment.rb +8 -8
  109. data/lib/rigor/flow_contribution/merger.rb +1 -0
  110. data/lib/rigor/hashing/xxh3.rb +1 -1
  111. data/lib/rigor/inference/acceptance.rb +23 -2
  112. data/lib/rigor/inference/alias_mutation_floor/site_collector.rb +5 -0
  113. data/lib/rigor/inference/alias_mutation_floor.rb +0 -5
  114. data/lib/rigor/inference/anonymous_meta_class.rb +2 -2
  115. data/lib/rigor/inference/block_call_timing.rb +6 -0
  116. data/lib/rigor/inference/budget_trace.rb +3 -2
  117. data/lib/rigor/inference/builtins/date_catalog.rb +3 -3
  118. data/lib/rigor/inference/builtins/method_catalog.rb +3 -3
  119. data/lib/rigor/inference/builtins/time_catalog.rb +3 -3
  120. data/lib/rigor/inference/call_ladder/literal_send.rb +98 -0
  121. data/lib/rigor/inference/call_ladder/overriding_def.rb +98 -0
  122. data/lib/rigor/inference/call_ladder/project_singleton.rb +362 -0
  123. data/lib/rigor/inference/call_ladder/refined.rb +212 -0
  124. data/lib/rigor/inference/call_ladder/top_level_def.rb +222 -0
  125. data/lib/rigor/inference/call_ladder/user_method.rb +247 -0
  126. data/lib/rigor/inference/call_ladder.rb +219 -0
  127. data/lib/rigor/inference/callee_write_census.rb +2 -2
  128. data/lib/rigor/inference/captured_locals.rb +2 -2
  129. data/lib/rigor/inference/clause_widening.rb +63 -1
  130. data/lib/rigor/inference/declaration_walk/context.rb +12 -12
  131. data/lib/rigor/inference/declaration_walk/rules.rb +750 -0
  132. data/lib/rigor/inference/declaration_walk/traversal.rb +9 -8
  133. data/lib/rigor/inference/declaration_walk.rb +4 -3
  134. data/lib/rigor/inference/def_node_resolver.rb +2 -2
  135. data/lib/rigor/inference/def_return_typer.rb +14 -6
  136. data/lib/rigor/inference/deferred_mutation.rb +120 -0
  137. data/lib/rigor/inference/define_method_block_self.rb +1 -1
  138. data/lib/rigor/inference/definer_resolution.rb +4 -4
  139. data/lib/rigor/inference/error_info.rb +8 -8
  140. data/lib/rigor/inference/expression_typer/composites.rb +348 -0
  141. data/lib/rigor/inference/expression_typer/per_element_assemblers.rb +233 -0
  142. data/lib/rigor/inference/expression_typer/writes.rb +218 -0
  143. data/lib/rigor/inference/expression_typer.rb +275 -1825
  144. data/lib/rigor/inference/external_ancestor_resolution.rb +2 -2
  145. data/lib/rigor/inference/fallback.rb +1 -0
  146. data/lib/rigor/inference/for_yield_slots.rb +126 -0
  147. data/lib/rigor/inference/genuine_send.rb +92 -0
  148. data/lib/rigor/inference/global_write_census.rb +2 -2
  149. data/lib/rigor/inference/hkt_body.rb +2 -0
  150. data/lib/rigor/inference/in_effect_refinements/walk.rb +2 -2
  151. data/lib/rigor/inference/index_write_widening.rb +4 -4
  152. data/lib/rigor/inference/indexed_narrowing.rb +1 -1
  153. data/lib/rigor/inference/intervening_ivar_reset.rb +46 -9
  154. data/lib/rigor/inference/ivar_writer_census.rb +1 -1
  155. data/lib/rigor/inference/loop_store_sites.rb +239 -0
  156. data/lib/rigor/inference/macro_block_self_type.rb +4 -3
  157. data/lib/rigor/inference/method_dispatcher/block_folding.rb +3 -2
  158. data/lib/rigor/inference/method_dispatcher/call_context.rb +84 -14
  159. data/lib/rigor/inference/method_dispatcher/composite_receiver.rb +144 -0
  160. data/lib/rigor/inference/method_dispatcher/constant_folding.rb +7 -5
  161. data/lib/rigor/inference/method_dispatcher/declared_constructor.rb +1 -1
  162. data/lib/rigor/inference/method_dispatcher/dependency_source.rb +90 -0
  163. data/lib/rigor/inference/method_dispatcher/discovered_method.rb +78 -0
  164. data/lib/rigor/inference/method_dispatcher/file_folding.rb +2 -2
  165. data/lib/rigor/inference/method_dispatcher/hkt_builtin_return.rb +40 -0
  166. data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -6
  167. data/lib/rigor/inference/method_dispatcher/literal_string_folding.rb +4 -2
  168. data/lib/rigor/inference/method_dispatcher/match_data_folding.rb +1 -1
  169. data/lib/rigor/inference/method_dispatcher/meta_introspection.rb +506 -0
  170. data/lib/rigor/inference/method_dispatcher/overload_selector.rb +2 -0
  171. data/lib/rigor/inference/method_dispatcher/plugin_contribution.rb +134 -0
  172. data/lib/rigor/inference/method_dispatcher/project_patched.rb +134 -0
  173. data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +125 -43
  174. data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +3 -4
  175. data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +1 -1
  176. data/lib/rigor/inference/method_dispatcher/set_folding.rb +1 -1
  177. data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +19 -6
  178. data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +3 -3
  179. data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +7 -4
  180. data/lib/rigor/inference/method_dispatcher/static_refinement.rb +106 -0
  181. data/lib/rigor/inference/method_dispatcher/synthesized_stub.rb +41 -0
  182. data/lib/rigor/inference/method_dispatcher/synthetic_method_dispatch.rb +133 -0
  183. data/lib/rigor/inference/method_dispatcher/universal_object_dispatch.rb +2 -1
  184. data/lib/rigor/inference/method_dispatcher/user_class_fallback.rb +216 -0
  185. data/lib/rigor/inference/method_dispatcher.rb +175 -1361
  186. data/lib/rigor/inference/method_parameter_binder.rb +18 -18
  187. data/lib/rigor/inference/module_function_state.rb +5 -4
  188. data/lib/rigor/inference/mutation_widening.rb +20 -7
  189. data/lib/rigor/inference/narrowing/case_literals.rb +58 -0
  190. data/lib/rigor/inference/narrowing/class_dispatch.rb +302 -0
  191. data/lib/rigor/inference/narrowing/complements.rb +322 -0
  192. data/lib/rigor/inference/narrowing/presence_predicates.rb +205 -0
  193. data/lib/rigor/inference/narrowing/regex_match.rb +499 -0
  194. data/lib/rigor/inference/narrowing.rb +86 -1269
  195. data/lib/rigor/inference/object_mixins.rb +2 -2
  196. data/lib/rigor/inference/opaque_mutation.rb +214 -0
  197. data/lib/rigor/inference/optimistic_origin.rb +52 -14
  198. data/lib/rigor/inference/parameter_inference_collector.rb +1 -1
  199. data/lib/rigor/inference/pre_eval_constants.rb +11 -9
  200. data/lib/rigor/inference/precision_scanner.rb +27 -2
  201. data/lib/rigor/inference/project_patched_methods.rb +3 -3
  202. data/lib/rigor/inference/range_constant.rb +3 -3
  203. data/lib/rigor/inference/rbs_type_translator.rb +2 -2
  204. data/lib/rigor/inference/refine_self.rb +8 -7
  205. data/lib/rigor/inference/refined_dispatch.rb +2 -2
  206. data/lib/rigor/inference/return_barrier.rb +24 -9
  207. data/lib/rigor/inference/scope_indexer/alias_def_nodes.rb +311 -0
  208. data/lib/rigor/inference/scope_indexer/census_scope.rb +47 -0
  209. data/lib/rigor/inference/scope_indexer/certainty.rb +2 -2
  210. data/lib/rigor/inference/scope_indexer/class_cvar_census.rb +282 -0
  211. data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +12 -5
  212. data/lib/rigor/inference/scope_indexer/class_declarations.rb +228 -0
  213. data/lib/rigor/inference/scope_indexer/class_ivar_index.rb +2028 -0
  214. data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +4 -3
  215. data/lib/rigor/inference/scope_indexer/constant_tables.rb +844 -0
  216. data/lib/rigor/inference/scope_indexer/cvar_hierarchy.rb +159 -0
  217. data/lib/rigor/inference/scope_indexer/declaration_artifacts.rb +219 -0
  218. data/lib/rigor/inference/scope_indexer/declaration_signature.rb +212 -0
  219. data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +2 -2
  220. data/lib/rigor/inference/scope_indexer/factory_call_resolver.rb +53 -0
  221. data/lib/rigor/inference/scope_indexer/literal_receiver_mutations.rb +266 -0
  222. data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +8 -7
  223. data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +1 -1
  224. data/lib/rigor/inference/scope_indexer/mixin_effects.rb +470 -0
  225. data/lib/rigor/inference/scope_indexer/mixin_tables.rb +388 -0
  226. data/lib/rigor/inference/scope_indexer/mutated_carrier_widening.rb +163 -0
  227. data/lib/rigor/inference/scope_indexer/mutated_element_census.rb +211 -0
  228. data/lib/rigor/inference/scope_indexer/node_propagation.rb +520 -0
  229. data/lib/rigor/inference/scope_indexer/program_globals.rb +154 -0
  230. data/lib/rigor/inference/scope_indexer/published_constant_cvars.rb +146 -0
  231. data/lib/rigor/inference/scope_indexer/published_constant_ivars.rb +181 -0
  232. data/lib/rigor/inference/scope_indexer/shared_walk_tables.rb +823 -0
  233. data/lib/rigor/inference/scope_indexer/singleton_class_sources.rb +85 -0
  234. data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +5 -5
  235. data/lib/rigor/inference/scope_indexer.rb +2657 -9558
  236. data/lib/rigor/inference/self_call_ivar_writes.rb +22 -3
  237. data/lib/rigor/inference/set_mutation.rb +2 -2
  238. data/lib/rigor/inference/singleton_hook_definers.rb +185 -0
  239. data/lib/rigor/inference/statement_evaluator/def_arguments_and_assertions.rb +365 -0
  240. data/lib/rigor/inference/statement_evaluator/pattern_bindings.rb +581 -0
  241. data/lib/rigor/inference/statement_evaluator.rb +201 -1008
  242. data/lib/rigor/inference/synthetic_method_scanner.rb +0 -3
  243. data/lib/rigor/language_server/completion_provider.rb +8 -8
  244. data/lib/rigor/language_server/diagnostic_publisher.rb +6 -7
  245. data/lib/rigor/language_server/document_symbol_provider.rb +4 -6
  246. data/lib/rigor/language_server/folding_range_provider.rb +3 -3
  247. data/lib/rigor/language_server/hover_provider.rb +2 -2
  248. data/lib/rigor/language_server/loop.rb +2 -2
  249. data/lib/rigor/language_server/server.rb +3 -2
  250. data/lib/rigor/language_server/signature_help_provider.rb +7 -9
  251. data/lib/rigor/lens/document.rb +10 -1
  252. data/lib/rigor/lens/file_reader.rb +2 -1
  253. data/lib/rigor/mcp/loop.rb +48 -6
  254. data/lib/rigor/mcp/server.rb +248 -23
  255. data/lib/rigor/mcp/skill_catalog.rb +157 -0
  256. data/lib/rigor/plugin/base.rb +22 -4
  257. data/lib/rigor/plugin/effect_attribution.rb +1 -1
  258. data/lib/rigor/plugin/inflector.rb +2 -2
  259. data/lib/rigor/plugin/io_boundary.rb +1 -1
  260. data/lib/rigor/plugin/loader.rb +4 -4
  261. data/lib/rigor/plugin/macro/heredoc_template.rb +4 -3
  262. data/lib/rigor/plugin/optimistic_return.rb +20 -0
  263. data/lib/rigor/plugin/registry.rb +2 -2
  264. data/lib/rigor/plugin/template_unit.rb +4 -2
  265. data/lib/rigor/plugin/trust_policy.rb +2 -1
  266. data/lib/rigor/plugin.rb +1 -1
  267. data/lib/rigor/protection/mutator.rb +8 -9
  268. data/lib/rigor/rbs_extended/reporter.rb +2 -2
  269. data/lib/rigor/rbs_extended.rb +2 -2
  270. data/lib/rigor/reflection/constant_ancestors.rb +1 -1
  271. data/lib/rigor/reflection/project_method.rb +2 -2
  272. data/lib/rigor/reflection.rb +4 -4
  273. data/lib/rigor/scope/discovery_index.rb +15 -10
  274. data/lib/rigor/scope/resolution_chain.rb +29 -6
  275. data/lib/rigor/scope.rb +89 -32
  276. data/lib/rigor/sig_gen/generator.rb +5 -4
  277. data/lib/rigor/sig_gen/renderer.rb +3 -3
  278. data/lib/rigor/sig_gen/writer.rb +8 -6
  279. data/lib/rigor/source/parameter_envelope.rb +1 -1
  280. data/lib/rigor/triage/catalogue.rb +4 -4
  281. data/lib/rigor/type/combinator.rb +2 -2
  282. data/lib/rigor/type/data_instance.rb +2 -2
  283. data/lib/rigor/type/struct_instance.rb +3 -3
  284. data/lib/rigor/type_node/generic.rb +2 -1
  285. data/lib/rigor/type_of_memo.rb +2 -1
  286. data/lib/rigor/typing_state.rb +3 -2
  287. data/lib/rigor/version.rb +1 -1
  288. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/analyzer.rb +2 -2
  289. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +1 -1
  290. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +4 -4
  291. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +1 -1
  292. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_discoverer.rb +4 -3
  293. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/effects.rb +7 -5
  294. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +4 -2
  295. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/render_locals.rb +1 -1
  296. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +3 -2
  297. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +7 -7
  298. data/plugins/rigor-activejob/lib/rigor/plugin/activejob/job_discoverer.rb +1 -1
  299. data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +2 -2
  300. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +9 -8
  301. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +3 -2
  302. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +15 -7
  303. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +10 -3
  304. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/structure_sql_parser.rb +12 -1
  305. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +20 -5
  306. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +1 -1
  307. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +3 -2
  308. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext/effects.rb +1 -1
  309. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +8 -7
  310. data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema.rb +1 -1
  311. data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +1 -1
  312. data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +6 -7
  313. data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +3 -2
  314. data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +4 -3
  315. data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +4 -2
  316. data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +1 -1
  317. data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +1 -1
  318. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +5 -3
  319. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +1 -1
  320. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +4 -5
  321. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/doorkeeper_routes.rb +2 -2
  322. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +5 -4
  323. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_table.rb +3 -2
  324. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +30 -31
  325. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +13 -15
  326. data/plugins/rigor-rbnacl/lib/rigor/plugin/rbnacl.rb +1 -1
  327. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +4 -3
  328. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +16 -13
  329. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/scope_walker.rb +3 -2
  330. data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -6
  331. data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq/analyzer.rb +3 -3
  332. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +2 -2
  333. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +3 -2
  334. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog_walker.rb +6 -5
  335. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
  336. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +4 -5
  337. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/type_translator.rb +1 -1
  338. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +3 -4
  339. data/sig/rigor/analysis/check_rules/suppression.rbs +9 -0
  340. data/sig/rigor/analysis/dependency_recorder.rbs +9 -0
  341. data/sig/rigor/inference.rbs +275 -11
  342. data/sig/rigor/plugin/base.rbs +14 -5
  343. data/sig/rigor/plugin/optimistic_return.rbs +16 -0
  344. data/sig/rigor/scope.rbs +7 -1
  345. data/sig/rigor/source.rbs +4 -0
  346. data/skills/rigor-mcp-setup/SKILL.md +20 -6
  347. data/skills/rigor-plugin-review/SKILL.md +3 -3
  348. data/skills/rigor-type-oracle/references/01-oracle-commands.md +1 -1
  349. metadata +90 -3
@@ -4,13 +4,6 @@ require_relative "../protection/measurement_integrity"
4
4
 
5
5
  module Rigor
6
6
  class CLI
7
- # ADR-70 — aggregates per-file {Protection::MutationScanner::FusedFileResult} into a project-level **fused**
8
- # protection report: how many type-visible breakages were caught by the type checker, how many of the
9
- # *type-survivors* were caught by the test suite, and which sites neither axis caught — the ranked "add a type OR a
10
- # test here" list.
11
- #
12
- # Framing (ADR-63 / ADR-62 Criterion A, extended): the payload is the **attribution** — which protection axis is
13
- # missing — never raw survival. An unprotected site is "add protection here", never "your code is broken".
14
7
  # `harness_errors` (#264) — see {Rigor::CLI::FileEffectiveness}; defaults to 0 for the same reason.
15
8
  # A `class ... < Data.define(...)` body, not the `Data.define(...) do ... end` shorthand: Steep
16
9
  # resolves a `def` inside the shorthand block against the *lexically enclosing* class (here,
@@ -32,6 +25,13 @@ module Rigor
32
25
  end
33
26
  UnprotectedBreakage = Data.define(:method_name, :count, :examples)
34
27
 
28
+ # ADR-70 — aggregates per-file {Protection::MutationScanner::FusedFileResult} into a project-level **fused**
29
+ # protection report: how many type-visible breakages were caught by the type checker, how many of the
30
+ # *type-survivors* were caught by the test suite, and which sites neither axis caught — the ranked "add a type OR a
31
+ # test here" list.
32
+ #
33
+ # Framing (ADR-63 / ADR-62 Criterion A, extended): the payload is the **attribution** — which protection axis is
34
+ # missing — never raw survival. An unprotected site is "add protection here", never "your code is broken".
35
35
  FusedProtectionReport = Data.define(:files, :unprotected, :parse_errors) do
36
36
  def total_type_killed = files.sum(&:type_killed)
37
37
  def total_test_killed = files.sum(&:test_killed)
@@ -295,7 +295,7 @@ module Rigor
295
295
  project_context = LanguageServer::ProjectContext.new(
296
296
  configuration: configuration, configuration_loader: -> { Configuration.load(config_path) }
297
297
  )
298
- # Single source of truth for buffer state — threaded to Server + all three providers.
298
+ # Single source of truth for buffer state — threaded to Server + every provider.
299
299
  buffer_table = LanguageServer::BufferTable.new
300
300
  debouncer = LanguageServer::Debouncer.new
301
301
  publisher = LanguageServer::DiagnosticPublisher.new(
@@ -36,7 +36,7 @@ module Rigor
36
36
  require_relative "../mcp"
37
37
  require_relative "../version"
38
38
 
39
- server = MCP::Server.new(config_path: options.fetch(:config), err: $stderr)
39
+ server = MCP::Server.new(config_path: options.fetch(:config), err: $stderr, skills: options.fetch(:skills))
40
40
  loop_runner = MCP::Loop.new(input: $stdin, output: $stdout, server: server)
41
41
  loop_runner.run
42
42
  0
@@ -55,13 +55,16 @@ module Rigor
55
55
  "Session-level default config path (individual tool calls may override)") do |value|
56
56
  options[:config] = Options.config_path(value)
57
57
  end
58
+ opts.on("--no-skills", "Do not serve the bundled skills over the MCP Skills extension") do
59
+ options[:skills] = false
60
+ end
58
61
  end
59
62
  end
60
63
 
61
64
  private
62
65
 
63
66
  def parse_options
64
- options = { transport: "stdio", config: nil }
67
+ options = { transport: "stdio", config: nil, skills: true }
65
68
 
66
69
  option_parser(options).parse!(@argv)
67
70
  options
@@ -51,7 +51,11 @@ module Rigor
51
51
  # and an MCP caller would get a result for it with no sign anything was missing. Auto-discovery, with no
52
52
  # `--config` given, is not affected.
53
53
  def config_path(value)
54
+ # A shell can pass bytes that are not UTF-8 (`--config=$'\xffx'`), which `strip` raises on (#3432).
55
+ raise ConfigurationError, "config file not found: #{value.inspect}" unless value.valid_encoding?
54
56
  raise ConfigurationError, "empty config path" if value.strip.empty?
57
+ # Only an MCP `config` argument can carry a NUL, which `File.directory?` raises on (#3413).
58
+ raise ConfigurationError, "config file not found: #{value.inspect}" if value.include?("\0")
55
59
  raise ConfigurationError, "config path is a directory: #{value}" if File.directory?(value)
56
60
  raise ConfigurationError, "config file not found: #{value}" unless File.exist?(value)
57
61
  raise ConfigurationError, "config file not readable: #{value}" unless File.readable?(value)
@@ -46,7 +46,7 @@ module Rigor
46
46
  # integrations).
47
47
  #
48
48
  # Exit codes:
49
- # - `0` — every configured plugin loaded.
49
+ # - `0` — every configured plugin loaded, or `--strict` was not passed.
50
50
  # - `1` — at least one plugin failed to load AND `--strict`
51
51
  # was passed. Without `--strict` the command always exits 0;
52
52
  # load errors are reported but not treated as a gate failure
@@ -22,7 +22,7 @@ module Rigor
22
22
  # `--write` follows the established Ruby community convention: `lib/foo/bar.rb` → `sig/foo/bar.rbs`. New methods are
23
23
  # inserted into the matching class declaration just before its closing `end`; new classes are appended to the file;
24
24
  # non-existent target files are created. User-authored declarations are NEVER replaced unless `--overwrite` is set
25
- # AND the candidate is a `tighter-return`.
25
+ # AND the candidate is a `tighter-return` or an inline declaration that disagrees with the `sig/` copy.
26
26
  #
27
27
  # Parameter policy defaults to `untyped`. `--params=observed` (slice 3) opts in to caller-side observation
28
28
  # harvesting: the `ObservationCollector` walks `--observe=PATH...` (default: the project's test roots,
@@ -4,12 +4,13 @@ require "optparse"
4
4
 
5
5
  require_relative "command"
6
6
  require_relative "../rooted_glob"
7
+ require_relative "../mcp/skill_catalog"
7
8
 
8
9
  module Rigor
9
10
  class CLI
10
11
  # `rigor skill` — discover and print the SKILL.md files bundled with the `rigortype` gem.
11
12
  #
12
- # Rigor ships a small set of Agent Skills under `skills/` that walk an AI coding agent through onboarding
13
+ # Rigor ships Agent Skills under `skills/` that walk an AI coding agent through workflows such as onboarding
13
14
  # (`rigor-project-init`), baseline reduction (`rigor-baseline-reduce`), and authoring a plugin
14
15
  # (`rigor-plugin-author`). When Rigor is installed via `mise` / `gem install` / etc. the SKILL files live inside the
15
16
  # gem checkout — the project being analysed has no copy, so an AI agent has no a priori way to find them.
@@ -75,9 +76,9 @@ module Rigor
75
76
  rigor skill describe --deep (also: rigor describe --deep)
76
77
  USAGE
77
78
 
78
- # The bundled skills live at `<gem_root>/skills/`. From `lib/rigor/cli/skill_command.rb` that is three directories
79
- # up.
80
- SKILLS_ROOT = File.expand_path("../../../skills", __dir__).freeze
79
+ # The bundled skills live at `<gem_root>/skills/`. `rigor mcp` serves the same tree (ADR-33 WD10), so both read
80
+ # one constant.
81
+ SKILLS_ROOT = MCP::SkillCatalog::ROOT
81
82
 
82
83
  # The parser of `rigor skill`, built without parsing anything: the catalogue reads its flags from it (ADR-126
83
84
  # WD3). The positional grammar is read by hand in {#run}, so this describes the switches and parses nothing.
@@ -66,8 +66,9 @@ module Rigor
66
66
  lines = ["Hotspot files"]
67
67
  @report.hotspots.each do |spot|
68
68
  by_rule = spot.by_rule.map { |rule, count| "#{rule}×#{count}" }.join(" ")
69
- lines << format(" %<file>-40s %<count>4d %<rules>s",
70
- file: spot.file, count: spot.count, rules: by_rule)
69
+ # A path from a `\xFF`-bearing argument is binary; show it as UTF-8, with `?` for bytes it cannot display.
70
+ file = spot.file.dup.force_encoding(Encoding::UTF_8).scrub("?")
71
+ lines << format(" %<file>-40s %<count>4d %<rules>s", file: file, count: spot.count, rules: by_rule)
71
72
  end
72
73
  lines.join("\n")
73
74
  end
@@ -286,10 +286,6 @@ module Rigor
286
286
  real
287
287
  end
288
288
 
289
- # A glob is matched against every analysed spelling of the declaration's file, and each of them and its
290
- # realpath relative to the project root (#1760) and to the working directory:
291
- # `configuration.paths` are expanded to absolute, so a user-written `--entry-point=lib/entry.rb` would
292
- # otherwise never match anything and silently produce a root set of zero.
293
289
  # A constant named only from the project's own `sig/` is referenced — the #345 probe reported exactly this
294
290
  # as a false candidate until an RBS-side hook was added, because `Reflection.resolve_constant_type` is
295
291
  # source-side only. A signature also DECLARES, though, and {Analysis::Reachability::SignatureScan} is
@@ -349,6 +345,10 @@ module Rigor
349
345
  text.scan(CONSTANT_BEARING_RUN).uniq.join("\n")
350
346
  end
351
347
 
348
+ # A glob is matched against every analysed spelling of the declaration's file, and each of them and its
349
+ # realpath relative to the project root (#1760) and to the working directory:
350
+ # `configuration.paths` are expanded to absolute, so a user-written `--entry-point=lib/entry.rb` would
351
+ # otherwise never match anything and silently produce a root set of zero.
352
352
  def root_fqns(declarations, globs)
353
353
  return [] if globs.empty?
354
354
 
data/lib/rigor/cli.rb CHANGED
@@ -123,6 +123,10 @@ module Rigor
123
123
  end
124
124
 
125
125
  def run
126
+ # OptionParser raises `ArgumentError` from `Regexp#===` on an argument that is not valid in its encoding
127
+ # (#3470), before any command sees it, so every argument is normalised once, for every command.
128
+ @argv.map! { |arg| argv_text(arg) }
129
+
126
130
  command = @argv.shift
127
131
 
128
132
  case command
@@ -173,6 +177,16 @@ module Rigor
173
177
  FATAL_BACKTRACE_FRAMES = 5
174
178
  private_constant :FATAL_BACKTRACE_FRAMES
175
179
 
180
+ # An argument whose bytes are valid UTF-8 is read as UTF-8, whatever its tag: a `LC_ALL=C` argv is ASCII-8BIT,
181
+ # and a binary string with non-ASCII bytes crashes the JSON, SARIF and cache renderers. Any other invalid
182
+ # argument keeps its bytes as binary. An argument valid in a non-binary encoding is left as it is (#3486).
183
+ def argv_text(arg)
184
+ return arg if arg.valid_encoding? && arg.encoding != Encoding::BINARY
185
+
186
+ text = arg.dup.force_encoding(Encoding::UTF_8)
187
+ text.valid_encoding? ? text : arg.b
188
+ end
189
+
176
190
  def dispatch(command)
177
191
  handler = HANDLERS[command]
178
192
  return arm_jit_deadline { send(handler) } if handler
@@ -0,0 +1,418 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../configuration_error"
4
+ require_relative "../effects/entry_points"
5
+ require_relative "../effects/label"
6
+ require_relative "../effects/method_key"
7
+ require_relative "../rooted_glob"
8
+ require_relative "defaults"
9
+ require_relative "severity_profile"
10
+
11
+ module Rigor
12
+ class Configuration
13
+ # The validators and normalisers `Configuration#initialize` runs over each key of a loaded file. Each is a
14
+ # function of its arguments: it returns the coerced value or raises {ConfigurationError}, and reads no
15
+ # `Configuration` state, so the methods are `module_function` entries called as `Coercion.coerce_x(value)`.
16
+ # The coercions that write instance variables or ask the bleeding-edge selector (`coerce_effects`,
17
+ # `coerce_effects_snapshot`, `coerce_effects_policy`) stay on `Configuration`.
18
+ #
19
+ # Only the methods `Configuration` calls are public; the helpers behind them are `private_class_method`.
20
+ module Coercion # rubocop:disable Metrics/ModuleLength
21
+ module_function
22
+
23
+ # `effects.check:` — true by default under a present block, and never true without one. Only an
24
+ # explicit `false` turns it off; any other value is normalised to true rather than rejected, because a
25
+ # switch whose only two readings are "check" and "do not check" has nothing a tier-2 error would add.
26
+ def coerce_effects_check?(effects)
27
+ return false if effects.nil?
28
+
29
+ effects.fetch("check", true) != false
30
+ end
31
+
32
+ VALID_EFFECTS_GATES = %i[symmetric additions].freeze
33
+ private_constant :VALID_EFFECTS_GATES
34
+
35
+ def coerce_effects_gate(value)
36
+ return :symmetric if value.nil?
37
+
38
+ gate = value.to_s.to_sym
39
+ unless VALID_EFFECTS_GATES.include?(gate)
40
+ raise ConfigurationError,
41
+ "effects.snapshot.gate must be one of #{VALID_EFFECTS_GATES.inspect}, got #{value.inspect}"
42
+ end
43
+
44
+ gate
45
+ end
46
+
47
+ # Entry-point globs and preset names, kept as written.
48
+ #
49
+ # **Shape only.** A preset is *named by a plugin* (#387; ADR-103 WD14) and plugins load from this very
50
+ # configuration, so at this point no preset is registered yet and asking `EntryPoints.known?` would
51
+ # reject `reach: [rails]` for every project that uses one. The existence check therefore lives where
52
+ # the snapshot expands `reach:` ({Effects::Snapshot.expand_reach}), which runs after plugin load and
53
+ # raises there — the same error, at the first moment it can be right.
54
+ def coerce_effects_reach(value)
55
+ entries = Array(value).map(&:to_s)
56
+ entries.each do |entry|
57
+ next if Effects::EntryPoints.glob?(entry) || Effects::EntryPoints.name?(entry)
58
+
59
+ raise ConfigurationError,
60
+ "effects.snapshot.reach entry is neither a file glob nor a well-formed entry-point preset " \
61
+ "name: #{entry.inspect} (a preset name is #{Effects::EntryPoints::NAME_PATTERN.inspect}; " \
62
+ "anything carrying a path or glob character is treated as a file glob instead)"
63
+ end
64
+ entries.uniq.freeze
65
+ end
66
+
67
+ # Shape validation only: the label grammar of `docs/type-specification/effect-labels.md`.
68
+ def coerce_effects_tolerated(value)
69
+ labels = Array(value).map(&:to_s)
70
+ labels.each do |label|
71
+ raise ConfigurationError, "effects.tolerated is not a well-formed effect label: #{label.inspect}" unless
72
+ Effects::Label.valid?(label)
73
+ end
74
+ labels.uniq.sort.freeze
75
+ end
76
+
77
+ NO_ATTRIBUTION = {}.freeze
78
+ private_constant :NO_ATTRIBUTION
79
+
80
+ def coerce_effects_labels(value)
81
+ labels = Array(value).map(&:to_s)
82
+ labels.each do |label|
83
+ raise ConfigurationError, "effects.labels is not a well-formed effect label: #{label.inspect}" unless
84
+ Effects::Label.valid?(label)
85
+ end
86
+ labels.uniq.sort.freeze
87
+ end
88
+
89
+ # `{ "Net::HTTP.get" => ["io.net.http"] }` — a method key exactly as the symbol tables spell one
90
+ # (`Owner#instance`, `Owner.singleton`), mapped to the labels a call to it contributes.
91
+ def coerce_effects_attribution(value)
92
+ return NO_ATTRIBUTION unless value.is_a?(Hash)
93
+
94
+ value.each_with_object({}) do |(key, labels), out|
95
+ name = key.to_s
96
+ unless Effects::MethodKey.valid?(name)
97
+ raise ConfigurationError,
98
+ "effects.attribution key is not a method key (`Owner#method` / `Owner.method`): #{name.inspect}"
99
+ end
100
+
101
+ out[name] = coerce_effect_label_list(Array(labels), "effects.attribution[#{name.inspect}]")
102
+ end.freeze
103
+ end
104
+
105
+ # `[{ match: | namespace:, effect: [...] }]`. Exactly one selector per entry: an entry naming both
106
+ # would need a precedence rule between two selectors of the same entry, and one naming neither selects
107
+ # every class in the project, which is never what an author meant to write.
108
+ def coerce_effects_envelopes(value)
109
+ Array(value).each_with_index.map { |entry, index| coerce_effects_envelope(entry, index) }.freeze
110
+ end
111
+
112
+ def coerce_effects_envelope(entry, index)
113
+ where = "effects.envelopes[#{index}]"
114
+ raise ConfigurationError, "#{where} is not a mapping: #{entry.inspect}" unless entry.is_a?(Hash)
115
+
116
+ match = coerce_effects_envelope_selector(entry["match"], "#{where}.match")
117
+ namespace = coerce_effects_envelope_selector(entry["namespace"], "#{where}.namespace")
118
+ if match.nil? == namespace.nil?
119
+ raise ConfigurationError, "#{where} must name exactly one of `match:` (a path glob) or `namespace:` " \
120
+ "(a constant glob), got #{match.nil? ? 'neither' : 'both'}"
121
+ end
122
+ unless entry.key?("effect")
123
+ raise ConfigurationError, "#{where} has no `effect:` bound (write `effect: []` for the empty envelope)"
124
+ end
125
+
126
+ {
127
+ "match" => match, "namespace" => namespace,
128
+ "effect" => coerce_effect_label_list(Array(entry["effect"]), "#{where}.effect")
129
+ }.freeze
130
+ end
131
+
132
+ def coerce_effects_envelope_selector(value, where)
133
+ return nil if value.nil?
134
+
135
+ selector = value.to_s
136
+ raise ConfigurationError, "#{where} is empty" if selector.strip.empty?
137
+
138
+ selector.freeze
139
+ end
140
+
141
+ def coerce_effect_label_list(labels, where)
142
+ labels.map(&:to_s).each do |label|
143
+ raise ConfigurationError, "#{where} is not a well-formed effect label: #{label.inspect}" unless
144
+ Effects::Label.valid?(label)
145
+ end.uniq.sort.freeze
146
+ end
147
+
148
+ # ADR-17 slice 4 — `pre_eval:` glob expansion. Each entry is accepted as either a literal path (slice 1
149
+ # contract) OR a `File.fnmatch?`-shaped glob pattern (`lib/core_ext/**/*.rb`). Glob meta characters (`*`,
150
+ # `?`, `[`) trigger `Dir.glob` expansion; the resulting file list is folded into the `pre_eval:` set with
151
+ # `uniq`. Literal entries that don't exist on disk continue to surface as `pre-eval.file-not-found`
152
+ # `:error` (slice 1 behaviour); glob entries that match nothing degrade silently to "no contribution from
153
+ # this entry" so a templated `**` pattern in a fresh project doesn't generate an error per match-less
154
+ # pattern.
155
+ def expand_pre_eval_entries(entries)
156
+ entries.flat_map { |entry| expand_pre_eval_entry(entry) }.uniq.freeze
157
+ end
158
+
159
+ # #1956 — a relative entry arrives joined onto the config file's directory, so the metacharacters the
160
+ # check above sees may be that directory's own (`ds [x]/`). The leading run of segments that name existing
161
+ # directories is read literally and only the rest is globbed under it: a literal entry under such a
162
+ # directory stays a literal path, and a pattern matches what it matches under a plain directory.
163
+ def expand_pre_eval_entry(entry)
164
+ return [entry] unless glob_pattern?(entry)
165
+
166
+ base, pattern = literal_directory_prefix(entry)
167
+ return [entry] unless glob_pattern?(pattern)
168
+
169
+ base ? RootedGlob.glob(base, pattern) : Dir.glob(entry, sort: true)
170
+ end
171
+
172
+ def literal_directory_prefix(entry)
173
+ segments = entry.split("/")
174
+ count = (1...segments.size).take_while { |n| File.directory?(join_segments(segments.take(n))) }.size
175
+ return [nil, entry] if count.zero?
176
+
177
+ [join_segments(segments.take(count)), segments.drop(count).join("/")]
178
+ end
179
+
180
+ # `"/a".split("/")` leads with an empty segment, which spells the filesystem root.
181
+ def join_segments(segments)
182
+ path = segments.join("/")
183
+ path.empty? ? "/" : path
184
+ end
185
+
186
+ def glob_pattern?(path)
187
+ path.include?("*") || path.include?("?") || path.include?("[")
188
+ end
189
+
190
+ # Accepts either `"rigor-foo"` (gem-name shorthand) or `{ "gem" => "rigor-foo", "id" => "foo", "config" =>
191
+ # {...} }` (full form). Returns the canonical hash form so the loader works against a single shape.
192
+ def coerce_plugin_entry(entry)
193
+ case entry
194
+ when String
195
+ entry.dup.freeze
196
+ when Hash
197
+ entry.to_h { |k, v| [k.to_s, v] }.freeze
198
+ else
199
+ raise ConfigurationError,
200
+ "plugin configuration entry must be a String or Hash, got #{entry.inspect}"
201
+ end
202
+ end
203
+
204
+ # `target_ruby` is passed as Prism's `version:` option at the analyser's parse sites
205
+ # (`Analysis::Runner`, `CLI::TypeOfCommand`, `CLI::TypeScanCommand`) so projects that target an older
206
+ # Ruby get parse errors for syntax their target doesn't support. Format validation here is loose —
207
+ # accepts any `<major>.<minor>` or `<major>.<minor>.<patch>` form, plus the literal `"latest"`. Prism
208
+ # itself enforces the supported set and raises `ArgumentError` for versions it does not recognise (e.g.
209
+ # `"1.0"`); the parse-time error message names the version, so the user can correct the setting.
210
+ TARGET_RUBY_FORMAT = /\A(?:\d+\.\d+(?:\.\d+)?|latest)\z/
211
+ private_constant :TARGET_RUBY_FORMAT
212
+
213
+ def coerce_target_ruby(value)
214
+ s = value.to_s
215
+ unless s.match?(TARGET_RUBY_FORMAT)
216
+ raise ConfigurationError,
217
+ "target_ruby must be a version (e.g. \"3.4\", \"4.0\", \"3.4.0\") or \"latest\", got #{value.inspect}"
218
+ end
219
+
220
+ s.dup.freeze
221
+ end
222
+
223
+ # YAML scalar may arrive as a String or already as a Symbol; coerce to the canonical Symbol shape so the
224
+ # downstream `TrustPolicy` constructor stays strict.
225
+ #
226
+ # The accepted set is duplicated from {Rigor::Plugin::TrustPolicy::VALID_NETWORK_POLICIES} so
227
+ # `Configuration` does not require the plugin namespace at load time (Configuration is loaded before
228
+ # Plugin in `lib/rigor.rb`); the two stay in lockstep via spec.
229
+ VALID_NETWORK_POLICIES = %i[disabled allowlist].freeze
230
+ private_constant :VALID_NETWORK_POLICIES
231
+
232
+ # ADR-15 Phase 4c — accepts a non-negative Integer (or a string-shaped one from YAML files that miss type
233
+ # annotations). Negative / non-integer values raise so typos / bad YAML fail loudly rather than silently
234
+ # disabling parallelism.
235
+ def coerce_parallel_workers(value)
236
+ integer = Integer(value)
237
+ raise ConfigurationError, "parallel.workers must be >= 0, got #{value.inspect}" if integer.negative?
238
+
239
+ integer
240
+ rescue TypeError, ArgumentError => e
241
+ raise ConfigurationError, "parallel.workers must be a non-negative Integer, got #{value.inspect} (#{e.message})"
242
+ end
243
+
244
+ # Issue #2517 — the directory's existence and contents are checked where the environment is built
245
+ # ({Environment::CoreRoot.validate!}), not here: `rigor init`, `rigor doctor` and the language server's reload
246
+ # load a configuration without building an environment, and must still be able to read one naming a core that
247
+ # is not generated yet.
248
+ def coerce_core_root(value)
249
+ return nil if value.nil?
250
+ raise ConfigurationError, "core_root must be a directory path, got #{value.inspect}" unless value.is_a?(String)
251
+ raise ConfigurationError, "core_root must not be empty" if value.strip.empty?
252
+
253
+ value.dup.freeze
254
+ end
255
+
256
+ # ADR-22 WD2 (b) — `baseline: <path>` activates the file; `baseline: false` is the explicit-disable form
257
+ # (useful in `.rigor.yml` to override an upstream `.rigor.dist.yml` that names a baseline). `nil`
258
+ # (default / absent key) is also "no baseline".
259
+ def coerce_baseline_path(value)
260
+ return nil if value.nil? || value == false
261
+
262
+ value.to_s
263
+ end
264
+
265
+ # ADR-87 WD1 — `cache.validation` is `"auto"` (default), `"stat"`, or `"digest"`. An unrecognised value
266
+ # fails soft to `"auto"` rather than aborting a check over a typo, and the always-available
267
+ # `RIGOR_STRICT_VALIDATION=1` env escape hatch does not depend on this value being valid.
268
+ VALID_CACHE_VALIDATIONS = %w[auto stat digest].freeze
269
+ private_constant :VALID_CACHE_VALIDATIONS
270
+
271
+ # The `sig_gen.inline_declared:` values, as the Symbols {Configuration#sig_gen_inline_declared} answers.
272
+ VALID_SIG_GEN_INLINE_DECLARED = %w[write skip].freeze
273
+ private_constant :VALID_SIG_GEN_INLINE_DECLARED
274
+
275
+ # Rejects rather than fails soft: an unrecognised value read as `write` would put a second declaration of
276
+ # every inline-annotated method into `sig/` for exactly the project that asked for none. A `sig_gen:`
277
+ # block that omits the key, or is written empty, keeps the default.
278
+ def coerce_sig_gen_inline_declared(section)
279
+ section = {} if section.nil?
280
+ raise ConfigurationError, "sig_gen must be a mapping, got #{section.inspect}" unless section.is_a?(Hash)
281
+
282
+ # The schema closes this object (`additionalProperties: false`); a misspelled key here would otherwise
283
+ # load as the default and write exactly what `inline_declare: skip` was meant to prevent.
284
+ unknown = section.keys.map(&:to_s) - Defaults::DEFAULTS.fetch("sig_gen").keys
285
+ unless unknown.empty?
286
+ raise ConfigurationError,
287
+ "sig_gen has unknown key(s) #{unknown.inspect}; known keys: #{Defaults::DEFAULTS.fetch('sig_gen').keys.inspect}"
288
+ end
289
+
290
+ value = section.fetch("inline_declared", Defaults::DEFAULTS.dig("sig_gen", "inline_declared")).to_s
291
+ unless VALID_SIG_GEN_INLINE_DECLARED.include?(value)
292
+ raise ConfigurationError,
293
+ "sig_gen.inline_declared must be one of #{VALID_SIG_GEN_INLINE_DECLARED.inspect}, " \
294
+ "got #{section['inline_declared'].inspect}"
295
+ end
296
+
297
+ value.to_sym
298
+ end
299
+
300
+ def coerce_cache_validation(value)
301
+ str = value.to_s
302
+ VALID_CACHE_VALIDATIONS.include?(str) ? str : "auto"
303
+ end
304
+
305
+ # Rejects rather than fails soft — a strategy that silently resolves to a different one is exactly
306
+ # the failure #911 exists to close, and the run's isolation is not a detail the user can be assumed
307
+ # not to have meant.
308
+ def coerce_plugins_isolation(value)
309
+ return nil if value.nil?
310
+
311
+ str = value.to_s
312
+ return str if Defaults::CONFIGURABLE_PLUGIN_ISOLATIONS.include?(str)
313
+
314
+ if str == "ruby_box"
315
+ raise ConfigurationError,
316
+ "plugins_isolation: ruby_box cannot be selected from the configuration file — `Ruby::Box` " \
317
+ "must be active before Ruby boots. Run rigor with RIGOR_PLUGIN_ISOLATION=ruby_box instead " \
318
+ "(the launcher re-execs itself with RUBY_BOX=1 set)."
319
+ end
320
+
321
+ raise ConfigurationError,
322
+ "plugins_isolation must be one of #{Defaults::CONFIGURABLE_PLUGIN_ISOLATIONS.inspect} " \
323
+ "(`ruby_box` is environment-only), got #{value.inspect}"
324
+ end
325
+
326
+ def coerce_network_policy(value)
327
+ sym = value.to_sym
328
+ unless VALID_NETWORK_POLICIES.include?(sym)
329
+ raise ConfigurationError,
330
+ "plugins_io.network must be one of #{VALID_NETWORK_POLICIES.inspect}, got #{value.inspect}"
331
+ end
332
+
333
+ sym
334
+ end
335
+
336
+ # ADR-8 § "Severity profile" — accepts the canonical Symbol form or its String spelling; rejects unknown
337
+ # profile names so typos fail loudly.
338
+ def coerce_severity_profile(value)
339
+ sym = value.to_sym
340
+ unless SeverityProfile::VALID_PROFILES.include?(sym)
341
+ raise ConfigurationError,
342
+ "severity_profile must be one of " \
343
+ "#{SeverityProfile::VALID_PROFILES.inspect}, got #{value.inspect}"
344
+ end
345
+
346
+ sym
347
+ end
348
+
349
+ # ADR-8 § "Severity profile" — `severity_overrides:` is a `{ rule => severity }` map. Keys are canonical
350
+ # rule ids (`call.undefined-method`) or family wildcards (`call`). Values are
351
+ # {SeverityProfile::VALID_SEVERITIES} symbols (`:error` / `:warning` / `:info` / `:off`). Unknown
352
+ # severities raise; unknown rule ids are silently kept (the override is inert until the rule lands).
353
+ def coerce_severity_overrides(value)
354
+ raise ConfigurationError, "severity_overrides must be a Hash, got #{value.inspect}" unless value.is_a?(Hash)
355
+
356
+ value.to_h do |k, v|
357
+ # YAML 1.1 parses bare `off`/`on`/`no`/`yes`/`true`/`false` as booleans, so a user who wrote `off` (a
358
+ # valid severity) without quotes hands us `false`. Catch the non-Symbol / non-String case before
359
+ # `to_sym` blows up with a backtrace.
360
+ unless v.is_a?(String) || v.is_a?(Symbol)
361
+ hint = v == false ? %( — did you mean the string "off"?) : ""
362
+ raise ConfigurationError,
363
+ "severity_overrides[#{k.inspect}] is #{v.inspect}, a YAML boolean#{hint} " \
364
+ "Bare off/on/no/yes/true/false are parsed as booleans; quote the severity " \
365
+ "(e.g. \"off\")."
366
+ end
367
+
368
+ sym = v.to_sym
369
+ unless SeverityProfile::VALID_SEVERITIES.include?(sym)
370
+ raise ConfigurationError,
371
+ "severity_overrides[#{k.inspect}] must be one of " \
372
+ "#{SeverityProfile::VALID_SEVERITIES.inspect}, got #{v.inspect}"
373
+ end
374
+
375
+ [k.to_s, sym]
376
+ end.freeze
377
+ end
378
+
379
+ # ADR-50 § WD2 — normalizes the `bleeding_edge:` selector to a canonical `{ "mode" => … }` hash
380
+ # (interpreted by {Rigor::BleedingEdge}). Validates *shape* only; membership against the overlay is
381
+ # intentionally NOT checked here (an unknown id stays inert, like an unknown `severity_overrides:` rule).
382
+ # Deep-frozen so the Configuration stays `Ractor.shareable?`.
383
+ def coerce_bleeding_edge(value)
384
+ case value
385
+ when nil, false then { "mode" => "none" }
386
+ when true then { "mode" => "all" }
387
+ when Array then { "mode" => "list", "ids" => freeze_ids(value) }
388
+ when Hash then coerce_bleeding_edge_hash(value)
389
+ else
390
+ raise ConfigurationError,
391
+ "bleeding_edge must be true, false, a list of feature ids, " \
392
+ "or { all: true, except: [...] }, got #{value.inspect}"
393
+ end.freeze
394
+ end
395
+
396
+ def coerce_bleeding_edge_hash(value)
397
+ hash = value.to_h { |k, v| [k.to_s, v] }
398
+ if hash.fetch("all", false) == true
399
+ { "mode" => "all", "except" => freeze_ids(Array(hash["except"])) }
400
+ else
401
+ { "mode" => "none" }
402
+ end
403
+ end
404
+
405
+ # Feature ids reach `coerce_bleeding_edge` from YAML, a `to_h` round-trip, or the CLI's
406
+ # `--bleeding-edge=a,b` (all runtime-created, non-frozen Strings). Each id String is frozen so the
407
+ # normalized selector — and thus the whole Configuration — stays deeply frozen and `Ractor.shareable?`
408
+ # for the worker path (the same invariant `#initialize`'s final `freeze` upholds for every other field).
409
+ def freeze_ids(ids)
410
+ ids.map { |id| id.to_s.dup.freeze }.freeze
411
+ end
412
+
413
+ private_class_method :coerce_effects_envelope, :coerce_effects_envelope_selector, :coerce_effect_label_list,
414
+ :expand_pre_eval_entry, :literal_directory_prefix, :join_segments, :glob_pattern?,
415
+ :coerce_bleeding_edge_hash, :freeze_ids
416
+ end
417
+ end
418
+ end