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
@@ -11,8 +11,39 @@ module Rigor
11
11
  # require no reply). Tool implementations delegate to `CLI.new(argv, out:, err:).run` with StringIO capture — every
12
12
  # tool stays in sync with its CLI counterpart automatically (ADR-33 WD4).
13
13
  class Server # rubocop:disable Metrics/ClassLength
14
+ # The revision a legacy client (one that opens with `initialize`) is answered with. Kept at the revision this
15
+ # server was first written to: nothing it serves needs a later legacy revision (ADR-33 WD9).
14
16
  PROTOCOL_VERSION = "2024-11-05"
15
17
 
18
+ # The stateless revisions (ADR-33 WD9): a request carrying `params._meta[PROTOCOL_VERSION_KEY]` is handled by
19
+ # these rules, one request at a time, with no handshake before it.
20
+ SUPPORTED_VERSIONS = ["2026-07-28"].freeze
21
+ PROTOCOL_VERSION_KEY = "io.modelcontextprotocol/protocolVersion"
22
+ CLIENT_CAPABILITIES_KEY = "io.modelcontextprotocol/clientCapabilities"
23
+ SERVER_INFO_KEY = "io.modelcontextprotocol/serverInfo"
24
+
25
+ # `server/discover`'s `capabilities.extensions` while skills are served (ADR-33 WD10). The Skills extension takes
26
+ # no optional setting here: every skill carries a complete manifest, so `directoryRead` is not offered.
27
+ SKILLS_EXTENSION = "io.modelcontextprotocol/skills"
28
+ EXTENSIONS = { SKILLS_EXTENSION => {}.freeze }.freeze
29
+
30
+ # The methods only a server that serves skills answers; with `--no-skills` they are `-32601`.
31
+ SKILLS_METHODS = %w[skills/list skills/get resources/list resources/read].freeze
32
+
33
+ # How long a client may cache `server/discover` and `tools/list`. Neither changes while the process runs, so the
34
+ # number only bounds how stale a cache that outlives a `rigor` upgrade can be. Nothing in either is per-user.
35
+ CACHE_TTL_MS = 3_600_000
36
+ CACHE_SCOPE = "public"
37
+
38
+ # JSON-RPC error codes the 2026-07-28 revision defines (-32020..-32099 are MCP's).
39
+ UNSUPPORTED_PROTOCOL_VERSION = -32_022
40
+ INVALID_PARAMS = -32_602
41
+ METHOD_NOT_FOUND = -32_601
42
+ # JSON-RPC 2.0's own: a message that parses but is not a request object (#3411).
43
+ INVALID_REQUEST = -32_600
44
+ # JSON-RPC 2.0 § 5.1: the server failed while handling a request it could read (#3435).
45
+ INTERNAL_ERROR = -32_603
46
+
16
47
  TOOLS = [
17
48
  {
18
49
  name: "rigor_check",
@@ -24,11 +55,10 @@ module Rigor
24
55
  paths: {
25
56
  type: "array",
26
57
  items: { type: "string" },
27
- description: "Files or directories to analyze (required)"
58
+ description: "Files or directories to analyze (defaults to configured paths)"
28
59
  },
29
60
  config: { type: "string", description: "Path to .rigor.yml (optional)" }
30
- },
31
- required: ["paths"]
61
+ }
32
62
  }
33
63
  },
34
64
  {
@@ -145,43 +175,69 @@ module Rigor
145
175
  paths: {
146
176
  type: "array",
147
177
  items: { type: "string" },
148
- description: "Files or directories to scan (required)"
178
+ description: "Files or directories to scan (defaults to configured paths)"
149
179
  },
150
180
  config: { type: "string", description: "Path to .rigor.yml (optional)" }
151
- },
152
- required: ["paths"]
181
+ }
153
182
  }
154
183
  }
155
184
  ].freeze
156
185
  Ractor.make_shareable(TOOLS)
157
186
 
187
+ # Each tool's `inputSchema.required`, by name. `build_argv` refuses a call missing any of them, and nothing else
188
+ # (#3412): the schema a client reads is the check the server makes.
189
+ REQUIRED_ARGUMENTS = TOOLS.to_h { |tool| [tool[:name], tool.dig(:inputSchema, :required) || []] }.freeze
190
+ Ractor.make_shareable(REQUIRED_ARGUMENTS)
191
+
158
192
  # The tools that read a configuration — the ones taking a `config` argument — and so report its warnings.
159
193
  CONFIG_TOOLS = TOOLS.filter_map { |tool| tool[:name] if tool.dig(:inputSchema, :properties, :config) }.freeze
160
194
  Ractor.make_shareable(CONFIG_TOOLS)
161
195
 
162
- def initialize(config_path: nil, err: $stderr)
196
+ def initialize(config_path: nil, err: $stderr, skills: true)
163
197
  @config_path = config_path
164
198
  @err = err
199
+ @skills = skills
200
+ end
201
+
202
+ # Whether a response can echo this id back in JSON: a string that is valid UTF-8, an integer, or a finite number.
203
+ def self.valid_id?(id)
204
+ case id
205
+ when String then id.valid_encoding?
206
+ when Integer then true
207
+ when Float then id.finite?
208
+ else false
209
+ end
165
210
  end
166
211
 
167
212
  # Dispatches a parsed JSON-RPC request hash. Returns nil for notifications (requests without an `id`).
213
+ #
214
+ # The era is read from each request, never from an earlier one (ADR-33 WD9): a request whose `params._meta` names
215
+ # a protocol version, and every `server/discover`, is answered by the 2026-07-28 rules; `initialize`, and
216
+ # anything else without that field, is the legacy protocol, answered exactly as before.
217
+ #
218
+ # A parsed line that is not a request object (a batch array, a number, a string, `true`, `false`, `null`) has no
219
+ # `id` to read, so it is answered `-32600` with a null `id` (JSON-RPC 2.0 § 5.1, #3411). MCP has not used batching
220
+ # since 2025-06-18, so a batch is refused whole.
221
+ #
222
+ # An `id` JSON-RPC 2.0 does not allow (anything but a string, a number or null), or one a response cannot echo
223
+ # back (a non-finite number, a string that is not valid UTF-8), is refused the same way with a null `id` (#3426).
168
224
  def handle(request)
225
+ return error(nil, INVALID_REQUEST, "Invalid Request: not a request object") unless request.is_a?(Hash)
226
+
169
227
  id = request["id"]
170
- method_name = request["method"]
171
228
 
172
229
  # A notification carries no `id` and requires no response.
173
230
  return nil if id.nil?
231
+ unless self.class.valid_id?(id)
232
+ return error(nil, INVALID_REQUEST,
233
+ "Invalid Request: id is not a string or a finite number")
234
+ end
174
235
 
175
- case method_name
176
- when "initialize" then handle_initialize(id)
177
- when "ping" then success(id, {})
178
- when "tools/list" then success(id, { tools: TOOLS })
179
- when "tools/call"
180
- call_tool(id,
181
- request.dig("params", "name"),
182
- request.dig("params", "arguments") || {})
236
+ meta = request_meta(request)
237
+ if modern?(request["method"], meta)
238
+ handle_modern(id, request, meta)
183
239
  else
184
- error(id, -32_601, "Method not found: #{method_name.inspect}")
240
+ handle_legacy(id, request)
185
241
  end
186
242
  end
187
243
 
@@ -193,6 +249,136 @@ module Rigor
193
249
 
194
250
  private
195
251
 
252
+ def handle_legacy(id, request)
253
+ method_name = request["method"]
254
+ case method_name
255
+ when "initialize" then handle_initialize(id)
256
+ when "ping" then success(id, {})
257
+ when "tools/list" then success(id, { tools: TOOLS })
258
+ when "tools/call" then tools_call(id, request["params"])
259
+ else method_not_found(id, method_name)
260
+ end
261
+ end
262
+
263
+ def handle_modern(id, request, meta)
264
+ refusal = modern_refusal(id, meta)
265
+ return refusal if refusal
266
+
267
+ method_name = request["method"]
268
+ case method_name
269
+ when "server/discover" then success(id, complete(discover_result))
270
+ # The revision drops `ping`; answering it costs nothing and keeps a client that still sends one connected.
271
+ when "ping" then success(id, complete({}))
272
+ when "tools/list" then success(id, complete(cacheable({ tools: TOOLS })))
273
+ when "tools/call"
274
+ response = tools_call(id, request["params"])
275
+ response.key?("result") ? success(id, complete(response["result"])) : response
276
+ else
277
+ return handle_skills(id, method_name, request["params"]) if @skills && SKILLS_METHODS.include?(method_name)
278
+
279
+ method_not_found(id, method_name)
280
+ end
281
+ end
282
+
283
+ # The Skills extension's methods and the `resources` methods it serves files through (ADR-33 WD10). The catalog is
284
+ # read at the first of these, never at discover or a tool call, and then frozen for the process. `params` is an
285
+ # object here: a 2026-07-28 request carries its `_meta` in it.
286
+ def handle_skills(id, method_name, params)
287
+ case method_name
288
+ when "skills/list" then listing(id, params) { { skills: skill_catalog.entries } }
289
+ when "resources/list" then listing(id, params) { { resources: skill_catalog.resource_list } }
290
+ when "skills/get" then skills_get(id, params["uri"])
291
+ else resources_read(id, params["uri"])
292
+ end
293
+ end
294
+
295
+ # Both lists fit one page, so no `nextCursor` is ever sent, and any cursor is one this server never issued.
296
+ def listing(id, params)
297
+ unless params["cursor"].nil?
298
+ return error(id, INVALID_PARAMS, "Invalid cursor",
299
+ data: { cursor: params["cursor"] })
300
+ end
301
+
302
+ success(id, complete(cacheable(yield)))
303
+ end
304
+
305
+ def skills_get(id, uri)
306
+ skill = skill_catalog.skill(uri) if uri.is_a?(String)
307
+ return error(id, INVALID_PARAMS, "Skill not found", data: { uri: uri }) unless skill
308
+
309
+ success(id, complete(cacheable({ skill: skill.entry })))
310
+ end
311
+
312
+ def resources_read(id, uri)
313
+ contents = skill_catalog.contents(uri) if uri.is_a?(String)
314
+ return error(id, INVALID_PARAMS, "Resource not found", data: { uri: uri }) unless contents
315
+
316
+ success(id, complete(cacheable({ contents: contents })))
317
+ end
318
+
319
+ def skill_catalog
320
+ @skill_catalog ||= begin
321
+ require_relative "skill_catalog"
322
+ SkillCatalog.load(err: @err)
323
+ end
324
+ end
325
+
326
+ # The two `_meta` fields every 2026-07-28 request carries. A version this server does not speak is refused with
327
+ # the versions it does, so the client can retry with one of them.
328
+ def modern_refusal(id, meta)
329
+ version = meta[PROTOCOL_VERSION_KEY]
330
+ unless version.is_a?(String)
331
+ return error(id, INVALID_PARAMS, "Missing required params._meta[#{PROTOCOL_VERSION_KEY.inspect}]")
332
+ end
333
+ unless SUPPORTED_VERSIONS.include?(version)
334
+ return error(id, UNSUPPORTED_PROTOCOL_VERSION, "Unsupported protocol version",
335
+ data: { supported: SUPPORTED_VERSIONS, requested: version })
336
+ end
337
+ return nil if meta[CLIENT_CAPABILITIES_KEY].is_a?(Hash)
338
+
339
+ error(id, INVALID_PARAMS, "Missing required params._meta[#{CLIENT_CAPABILITIES_KEY.inspect}]")
340
+ end
341
+
342
+ def discover_result
343
+ capabilities = { tools: { listChanged: false } }
344
+ capabilities.merge!(resources: {}, extensions: EXTENSIONS) if @skills
345
+ {
346
+ supportedVersions: SUPPORTED_VERSIONS,
347
+ capabilities: capabilities
348
+ }.then { cacheable(it) }
349
+ end
350
+
351
+ def cacheable(result)
352
+ result.merge(ttlMs: CACHE_TTL_MS, cacheScope: CACHE_SCOPE)
353
+ end
354
+
355
+ def modern?(method_name, meta)
356
+ return false if method_name == "initialize"
357
+
358
+ method_name == "server/discover" || meta.key?(PROTOCOL_VERSION_KEY)
359
+ end
360
+
361
+ # Every 2026-07-28 result is complete, and carries the server info the revision asks each result for, beside any
362
+ # `_meta` the result already has (results here use symbol keys).
363
+ def complete(result)
364
+ { resultType: "complete" }.merge(result, _meta: server_info_meta.merge(result.fetch(:_meta, {})))
365
+ end
366
+
367
+ def server_info_meta
368
+ require_relative "../version"
369
+ { SERVER_INFO_KEY => { name: "rigor", version: Rigor::VERSION } }
370
+ end
371
+
372
+ def request_meta(request)
373
+ params = request["params"]
374
+ meta = params["_meta"] if params.is_a?(Hash)
375
+ meta.is_a?(Hash) ? meta : {}
376
+ end
377
+
378
+ def method_not_found(id, method_name)
379
+ error(id, METHOD_NOT_FOUND, "Method not found: #{method_name.inspect}")
380
+ end
381
+
196
382
  def finish_tool_result(name, args, out, err, exit_code)
197
383
  result = with_config_warnings(tool_result(out, err, exit_code), name, args, out)
198
384
  result = with_shape_notice(result, name, out, err)
@@ -226,16 +412,34 @@ module Rigor
226
412
  })
227
413
  end
228
414
 
415
+ # `tools/call` reads its tool from `params`, so `params` that is present and not an object is `-32602` (#3411).
416
+ # Other methods read no `params` beyond `_meta`, and keep ignoring them.
417
+ def tools_call(id, params)
418
+ params = {} if params.nil?
419
+ return error(id, INVALID_PARAMS, "Invalid params: tools/call params is not an object") unless params.is_a?(Hash)
420
+
421
+ arguments = params["arguments"]
422
+ call_tool(id, params["name"], arguments.nil? ? {} : arguments)
423
+ end
424
+
229
425
  def call_tool(id, name, args)
426
+ refusal = call_refusal(name, args)
427
+ return error(id, INVALID_PARAMS, refusal) if refusal
428
+
230
429
  argv = build_argv(name, args)
231
- return error(id, -32_602, "Unknown tool: #{name.inspect}") unless argv
232
430
 
233
431
  out_io = StringIO.new
234
432
  err_io = StringIO.new
235
433
  require_relative "../cli"
236
- exit_code = with_captured_streams(out_io, err_io) { CLI.new(argv, out: out_io, err: err_io).run }
434
+ require_relative "../configuration"
435
+ # #3432 — stdin is this server's JSON-RPC channel: every configuration file the call reads must be a regular
436
+ # file, so a `config` of `/dev/stdin` or a FIFO is the command's usage error rather than a read of the protocol.
437
+ result = Configuration::Loader.regular_files_only do
438
+ exit_code = with_captured_streams(out_io, err_io) { CLI.new(argv, out: out_io, err: err_io).run }
439
+ finish_tool_result(name, args, out_io.string, err_io.string, exit_code)
440
+ end
237
441
 
238
- success(id, finish_tool_result(name, args, out_io.string, err_io.string, exit_code))
442
+ success(id, result)
239
443
  rescue SystemExit => e
240
444
  # Defence against any command that exits: it must not take the server down with it.
241
445
  success(id, { content: [{ type: "text", text: "Command exited (status #{e.status})" }], isError: true })
@@ -248,6 +452,19 @@ module Rigor
248
452
  })
249
453
  end
250
454
 
455
+ # Why a `tools/call` is `-32602`, or nil when it runs. A missing argument names the argument rather than reading
456
+ # as an unknown tool, and `arguments` other than an object is refused before anything reads it (#3412).
457
+ def call_refusal(name, args)
458
+ return "Unknown tool: #{name.inspect}" unless REQUIRED_ARGUMENTS.key?(name)
459
+ return "Invalid params: arguments is not an object" unless args.is_a?(Hash)
460
+ return nil if build_argv(name, args)
461
+
462
+ missing = REQUIRED_ARGUMENTS.fetch(name).reject { |key| args[key] }
463
+ return "Missing required argument for #{name}: #{missing.join(', ')}" unless missing.empty?
464
+
465
+ "Invalid argument for #{name}: #{REQUIRED_ARGUMENTS.fetch(name).join(', ')}"
466
+ end
467
+
251
468
  # A non-zero exit with nothing on stdout printed only an error; exit 1 with a document (check, lens) is a
252
469
  # result, not an error.
253
470
  def tool_result(out, err, exit_code)
@@ -274,11 +491,17 @@ module Rigor
274
491
 
275
492
  # Only a configuration that does not load is "no warnings to show": the CLI has already reported that error.
276
493
  # A failure in ConfigAudit itself is a bug and surfaces as an internal error rather than reading as clean.
494
+ #
495
+ # The path is the one the command read: `build_argv` wrote it into `--config=` as a string, and the command
496
+ # refused it by `CLI::Options.config_path` before loading anything. The same check runs here first, so a
497
+ # directory, an unreadable file or a non-string value is the command's usage error rather than an `Errno` or a
498
+ # `TypeError` out of `Configuration.load` (#3413).
277
499
  def config_warnings(config_path)
278
500
  require_relative "../configuration"
279
501
  require_relative "../config_audit"
502
+ require_relative "../cli/options"
280
503
  begin
281
- configuration = Configuration.load(config_path)
504
+ configuration = Configuration.load(config_path && CLI::Options.config_path(config_path.to_s))
282
505
  rescue ConfigurationError
283
506
  return []
284
507
  end
@@ -373,8 +596,10 @@ module Rigor
373
596
  { "jsonrpc" => "2.0", "id" => id, "result" => result }
374
597
  end
375
598
 
376
- def error(id, code, message)
377
- { "jsonrpc" => "2.0", "id" => id, "error" => { "code" => code, "message" => message } }
599
+ def error(id, code, message, data: nil)
600
+ body = { "code" => code, "message" => message }
601
+ body["data"] = data if data
602
+ { "jsonrpc" => "2.0", "id" => id, "error" => body }
378
603
  end
379
604
  end
380
605
  end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "yaml"
5
+
6
+ module Rigor
7
+ module MCP
8
+ # The gem-bundled `skills/` tree as the MCP Skills extension serves it (ADR-33 WD10).
9
+ #
10
+ # A catalog reads the served set once and freezes it: every manifest digest and size is computed from the bytes the
11
+ # catalog then serves, so a client that verifies a file against its manifest entry always sees them agree, even if
12
+ # the file changes on disk while the process runs. Only the standard library is loaded here: the server answers the
13
+ # skills methods without loading `rigor/cli` or the engine.
14
+ class SkillCatalog
15
+ # The bundled skills live at `<gem_root>/skills/`; from `lib/rigor/mcp/` that is three directories up.
16
+ # `rigor skill` reads the same constant.
17
+ ROOT = File.expand_path("../../../skills", __dir__).freeze
18
+
19
+ # What a skill directory contributes to the served set: exactly the gemspec's two `skills/` globs, so a source
20
+ # checkout serves what the gem ships. `evals/` and `scripts/` stay out.
21
+ SKILL_FILE = "SKILL.md"
22
+ REFERENCE_GLOB = "references/*.md"
23
+
24
+ FRONTMATTER = /\A---\r?\n(.*?)^---\r?$/m
25
+
26
+ URI_SCHEME = "skill://"
27
+ MIME_TYPE = "text/markdown"
28
+
29
+ # One served file: its URI, its text, and the manifest fields computed from those bytes.
30
+ Resource = Data.define(:uri, :path, :text, :digest, :size) do
31
+ def manifest_entry
32
+ { uri: uri, digest: digest, size: size }
33
+ end
34
+ end
35
+
36
+ # One served skill. `frontmatter` is the SKILL.md front matter, parsed and otherwise unchanged.
37
+ Skill = Data.define(:name, :uri, :frontmatter, :resources) do
38
+ def entry
39
+ { uri: uri, frontmatter: frontmatter, resources: resources.map(&:manifest_entry) }
40
+ end
41
+ end
42
+
43
+ # Reads the served set under `root`. A skill whose SKILL.md is missing, has no front matter, or whose front matter
44
+ # `name` is not its directory name is left out and reported on `err` (ADR-5): one bad skill does not stop the
45
+ # others from being served. `spec/rigor/mcp/skill_catalog_spec.rb` keeps the bundled tree free of such skills.
46
+ def self.load(root: ROOT, err: nil)
47
+ skills = []
48
+ if File.directory?(root)
49
+ Dir.children(root).sort.each do |name|
50
+ dir = File.join(root, name)
51
+ next unless File.file?(File.join(dir, SKILL_FILE))
52
+
53
+ skill = read_skill(dir, name, err)
54
+ skills << skill if skill
55
+ end
56
+ end
57
+ new(skills)
58
+ end
59
+
60
+ def self.read_skill(dir, name, err)
61
+ paths = [File.join(dir, SKILL_FILE)] + Dir.glob(REFERENCE_GLOB, base: dir).sort.map { File.join(dir, it) }
62
+ resources = paths.map { read_resource(dir, name, it) }
63
+ frontmatter = parse_frontmatter(resources.first.text)
64
+ problem = encoding_problem(resources) || skill_problem(name, resources.first.text, frontmatter)
65
+ if problem
66
+ err&.puts("rigor mcp: not serving skill #{name.inspect}: #{problem}")
67
+ return nil
68
+ end
69
+
70
+ Skill.new(name: name, uri: resources.first.uri, frontmatter: frontmatter.freeze, resources: resources.freeze)
71
+ end
72
+
73
+ def self.read_resource(dir, name, path)
74
+ bytes = File.binread(path)
75
+ relative = path.delete_prefix("#{dir}/")
76
+ Resource.new(uri: "#{URI_SCHEME}#{name}/#{relative}", path: path,
77
+ text: bytes.dup.force_encoding(Encoding::UTF_8).freeze,
78
+ digest: "sha256:#{Digest::SHA256.hexdigest(bytes)}", size: bytes.bytesize)
79
+ end
80
+
81
+ # The YAML between a leading `---` line and the next `---` line, or nil when SKILL.md does not open with one.
82
+ def self.parse_frontmatter(text)
83
+ match = text.valid_encoding? && text.match(FRONTMATTER)
84
+ return nil unless match
85
+
86
+ parsed = YAML.safe_load(match[1])
87
+ parsed.is_a?(Hash) ? parsed : nil
88
+ rescue Psych::Exception
89
+ nil
90
+ end
91
+
92
+ # A file that is not valid UTF-8 cannot be sent as JSON text, so its skill is not served at all.
93
+ def self.encoding_problem(resources)
94
+ bad = resources.find { !it.text.valid_encoding? }
95
+ bad && "#{bad.uri} is not valid UTF-8"
96
+ end
97
+
98
+ def self.skill_problem(name, text, frontmatter)
99
+ unless frontmatter
100
+ return "SKILL.md has no YAML front matter" unless text.valid_encoding? && text.match?(FRONTMATTER)
101
+
102
+ return "SKILL.md front matter is not a YAML mapping the safe loader accepts"
103
+ end
104
+ return "front matter has no string `description`" unless frontmatter["description"].is_a?(String)
105
+ return nil if frontmatter["name"] == name
106
+
107
+ "front matter name #{frontmatter['name'].inspect} is not the directory name"
108
+ end
109
+
110
+ private_class_method :read_skill, :read_resource, :encoding_problem, :skill_problem
111
+
112
+ attr_reader :skills
113
+
114
+ def initialize(skills)
115
+ @skills = skills.freeze
116
+ @skills_by_uri = skills.to_h { [it.uri, it] }.freeze
117
+ @resources_by_uri = skills.flat_map(&:resources).to_h { [it.uri, it] }.freeze
118
+ freeze
119
+ end
120
+
121
+ # The `skills/list` and `skills/get` entry of each skill.
122
+ def entries
123
+ skills.map(&:entry)
124
+ end
125
+
126
+ # The skill whose SKILL.md URI is `uri`, or nil.
127
+ def skill(uri)
128
+ @skills_by_uri[uri]
129
+ end
130
+
131
+ # The served file at `uri`, or nil.
132
+ def resource(uri)
133
+ @resources_by_uri[uri]
134
+ end
135
+
136
+ # The `resources/read` contents of the file at `uri`, or nil.
137
+ def contents(uri)
138
+ resource = resource(uri)
139
+ resource && [{ uri: resource.uri, mimeType: MIME_TYPE, text: resource.text }]
140
+ end
141
+
142
+ # The `resources/list` entries: every served file. A SKILL.md takes its name and description from its front
143
+ # matter, as the Skills extension recommends; a reference file is named by its path under `skills/`.
144
+ def resource_list
145
+ skills.flat_map do |skill|
146
+ skill.resources.map do |resource|
147
+ listed = { uri: resource.uri, name: resource.uri.delete_prefix(URI_SCHEME), mimeType: MIME_TYPE,
148
+ size: resource.size }
149
+ next listed unless resource.uri == skill.uri
150
+
151
+ listed.merge(name: skill.name, description: skill.frontmatter["description"])
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -7,6 +7,7 @@ require "prism"
7
7
 
8
8
  require_relative "manifest"
9
9
  require_relative "node_context"
10
+ require_relative "optimistic_return"
10
11
  require_relative "../analysis/diagnostic"
11
12
  require_relative "../analysis/run_disclosure_credit"
12
13
  require_relative "../cache/engine_source"
@@ -619,10 +620,26 @@ module Rigor
619
620
  end
620
621
 
621
622
  # ADR-37 slice 2 — the return type contributed by this plugin's {.dynamic_return} rules for a call, or
622
- # nil. The engine calls this from `MethodDispatcher`; a rule fires only when `receiver_type`'s class
623
- # equals or inherits from one of its declared `receivers:` AND is of that entry's kind (#701). First
624
- # non-nil wins (declaration order). Failures isolate to nil.
623
+ # nil. A rule fires only when `receiver_type`'s class equals or inherits from one of its declared
624
+ # `receivers:` AND is of that entry's kind (#701). First non-nil wins (declaration order). Failures
625
+ # isolate to nil. An {OptimisticReturn} answer is unwrapped to its type here; the engine reads the
626
+ # answer itself through {#dynamic_return_answer}.
625
627
  def dynamic_return_type(call_node:, scope:, receiver_type:)
628
+ OptimisticReturn.unwrap(
629
+ dynamic_return_answer(call_node: call_node, scope: scope, receiver_type: receiver_type)
630
+ )
631
+ end
632
+
633
+ # Issue #3322 — a rule body's answer to pass back when the type omits a `nil` the value can hold: the
634
+ # engine types the call as `type` but does not let a condition over it fold to a constant
635
+ # ({OptimisticReturn}). `type` nil passes through, so a declining body can wrap unconditionally.
636
+ def optimistic_nil_free(type)
637
+ type.nil? ? nil : OptimisticReturn.new(type: type)
638
+ end
639
+
640
+ # {#dynamic_return_type} without the unwrap: the rule body's answer — a type, an {OptimisticReturn}, or
641
+ # nil. `MethodDispatcher::PluginContribution` calls this so the optimistic flag reaches the engine.
642
+ def dynamic_return_answer(call_node:, scope:, receiver_type:)
626
643
  rules = self.class.dynamic_returns
627
644
  return nil if rules.empty? || receiver_type.nil?
628
645
 
@@ -631,7 +648,8 @@ module Rigor
631
648
  next unless dynamic_return_rule_applies?(rule, call_node, receiver_type, environment, scope)
632
649
 
633
650
  result = instance_exec(call_node, scope, &rule[:block])
634
- return result if result
651
+ # A directly built `OptimisticReturn.new(type: nil)` is a decline, like `nil`, so the walk goes on.
652
+ return result if OptimisticReturn.unwrap(result)
635
653
  end
636
654
  nil
637
655
  rescue StandardError
@@ -18,7 +18,7 @@ module Rigor
18
18
  #
19
19
  # ## The receiver
20
20
  #
21
- # `receiver` is spelled one of two ways, and the spelling picks the matching rule:
21
+ # `receiver` is spelled one of three ways, and the spelling picks the matching rule:
22
22
  #
23
23
  # - a **class name** (`"ActiveRecord::Base"`, `"I18n"`) matches the class the call's receiver
24
24
  # projects to, **through the project's inheritance chain**: an `ActiveRecord::Base` row applies to
@@ -15,8 +15,8 @@ module Rigor
15
15
  # Per ADR-39 this is a permitted *target-library* invocation: the methods called are a fixed, pure,
16
16
  # allow-listed set ({ALLOWED_METHODS}) on a trusted gem the consuming plugins declare as a dependency.
17
17
  # (`ActiveSupport::Inflector` is loaded, not the analyzed application's code; project-specific inflection
18
- # rules are ingested by *statically parsing* `config/initializers/inflections.rb` in a later slice, never
19
- # by executing it.)
18
+ # rules are ingested by *statically parsing* `config/initializers/inflections.rb` — `rigor-rails-routes`
19
+ # reads the acronyms that way — never by executing it.)
20
20
  #
21
21
  # **Absence is silence, never a guess.** ActiveSupport is resolved from Rigor's host gem environment
22
22
  # first, then from the analyzed project's own bundler install tree ({Isolation.target_bundle_root},
@@ -44,7 +44,7 @@ module Rigor
44
44
  # `plugins_io.allowed_url_hosts: [...]`. The HTTP fetch is GET-only over HTTPS, capped at
45
45
  # {URL_TIMEOUT_SECONDS} wall time and {URL_MAX_BYTES} body size; non-2xx responses raise
46
46
  # {AccessDeniedError} so plugin code doesn't have to rescue mid-build.
47
- # - `#cache_descriptor` — flushes the accumulated entries into a fresh {Cache::Descriptor} for the
47
+ # - `#cache_descriptor` — snapshots the accumulated entries into a fresh {Cache::Descriptor} for the
48
48
  # contribution that built it. URL fetches contribute `ConfigEntry` rows keyed `"url:#{url}"` with the
49
49
  # response body's SHA-256 so contributions invalidate when the remote document changes.
50
50
  # - `#replay(descriptor)` — records a {Cache::Descriptor}'s rows as though this boundary had observed
@@ -19,9 +19,9 @@ module Rigor
19
19
  # 4. Validate the user's config against the manifest's `config_schema`.
20
20
  # 5. Instantiate the plugin and call `init(services)`.
21
21
  #
22
- # Loading is deterministic: configuration order, with plugin id alphabetical as the tie-breaker for
23
- # entries that resolve to the same gem. Failures do not abort the run; the loader collects them on the
24
- # {Registry} so the runner can convert each one into a `:plugin_loader` diagnostic.
22
+ # Loading is deterministic: configuration order, reordered only by the `manifest(consumes:)` topological
23
+ # sort (ADR-9), which itself breaks ties by configuration order. Failures do not abort the run; the loader collects
24
+ # them on the {Registry} so the runner can convert each one into a `:plugin_loader` diagnostic.
25
25
  class Loader # rubocop:disable Metrics/ClassLength
26
26
  attr_reader :services, :requirer, :feature_resolver
27
27
 
@@ -344,7 +344,7 @@ module Rigor
344
344
 
345
345
  # ADR-9 slice 5 — topological sort of plugins by their `manifest(consumes:)` declarations. Returns
346
346
  # `[sorted_plugins, load_errors]`. Determinism: when no dependency relation forces an order, plugins
347
- # are visited alphabetically by manifest id. A non-optional consume of a `(plugin_id, name)` whose
347
+ # keep their configuration order. A non-optional consume of a `(plugin_id, name)` whose
348
348
  # producer is missing emits a `:missing-producer` LoadError and drops the consumer; cycles emit a
349
349
  # `:dependency-cycle` LoadError naming the offending chain.
350
350
  def topo_sort_plugins(plugins)
@@ -50,9 +50,10 @@ module Rigor
50
50
  # method's name (a single `"\#{name}"` placeholder gets interpolated with the literal symbol argument at
51
51
  # `symbol_arg_position`). The synthetic method's return type is the `returns_from_arg:` lookup when it
52
52
  # resolves, else a non-empty `returns:` string (`SyntheticMethodScanner#resolve_emit_return_type`); the
53
- # dispatcher turns it into a nominal type through `MethodDispatcher#promote_via_return_type` when the
54
- # environment knows the class. With neither, an `"untyped"` / `"void"` placeholder, or an unknown class, the
55
- # method answers `Dynamic[Top]`. Resolution through ADR-13's `Plugin::TypeNodeResolver` is not wired.
53
+ # dispatcher turns it into a nominal type through
54
+ # `MethodDispatcher::SyntheticMethodDispatch.promote_via_return_type` when the environment knows the class.
55
+ # With neither, an `"untyped"` / `"void"` placeholder, or an unknown class, the method answers `Dynamic[Top]`.
56
+ # Resolution through ADR-13's `Plugin::TypeNodeResolver` is not wired.
56
57
  #
57
58
  # Engine wiring: `Inference::SyntheticMethodScanner` (slice 2b, `synthetic_method_scanner.rb`) consumes
58
59
  # `manifest.heredoc_templates`. Worked consumers: `plugins/rigor-dry-struct/` and
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rigor
4
+ module Plugin
5
+ # Issue #3322 — a `dynamic_return` answer whose nil-freeness is the plugin's bet rather than a property of the
6
+ # value. A plugin returns one through {Base#optimistic_nil_free} when the honest type is `T | nil` but
7
+ # contributing the `nil` would report `call.possible-nil-receiver` on the idiom every caller writes:
8
+ # rigor-activerecord's reader of a column the schema does not declare `null: false` answers `Time`, not
9
+ # `Time | nil`. The engine types the call as `type` and records an {Inference::OptimisticOrigin} mark on it, so
10
+ # the certainty consumers (`flow.always-truthy-condition`, the `&&` / `||` dead-operand gate, branch elision)
11
+ # decline to conclude from it exactly as they do for `Hash#[]` — `if record.completed_at.present?` stays live.
12
+ #
13
+ # The wrapper never reaches a type position: `Base#dynamic_return_type` unwraps it, and only the engine's own
14
+ # contribution tier reads the flag (`Base#dynamic_return_answer`).
15
+ OptimisticReturn = Data.define(:type) do
16
+ # The bare type of a `dynamic_return` answer, wrapped or not.
17
+ def self.unwrap(answer) = answer.is_a?(OptimisticReturn) ? answer.type : answer
18
+ end
19
+ end
20
+ end