lex-agentic-inference 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (328) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE +21 -0
  5. data/README.md +13 -0
  6. data/lex-agentic-inference.gemspec +30 -0
  7. data/lib/legion/extensions/agentic/inference/abductive/client.rb +25 -0
  8. data/lib/legion/extensions/agentic/inference/abductive/helpers/abduction_engine.rb +164 -0
  9. data/lib/legion/extensions/agentic/inference/abductive/helpers/constants.rb +39 -0
  10. data/lib/legion/extensions/agentic/inference/abductive/helpers/hypothesis.rb +106 -0
  11. data/lib/legion/extensions/agentic/inference/abductive/helpers/observation.rb +39 -0
  12. data/lib/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning.rb +129 -0
  13. data/lib/legion/extensions/agentic/inference/abductive/version.rb +13 -0
  14. data/lib/legion/extensions/agentic/inference/abductive.rb +20 -0
  15. data/lib/legion/extensions/agentic/inference/affordance/actors/scan.rb +31 -0
  16. data/lib/legion/extensions/agentic/inference/affordance/client.rb +28 -0
  17. data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb +123 -0
  18. data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb +75 -0
  19. data/lib/legion/extensions/agentic/inference/affordance/helpers/constants.rb +42 -0
  20. data/lib/legion/extensions/agentic/inference/affordance/runners/affordance.rb +90 -0
  21. data/lib/legion/extensions/agentic/inference/affordance/version.rb +13 -0
  22. data/lib/legion/extensions/agentic/inference/affordance.rb +19 -0
  23. data/lib/legion/extensions/agentic/inference/analogical/client.rb +28 -0
  24. data/lib/legion/extensions/agentic/inference/analogical/helpers/analogy_engine.rb +209 -0
  25. data/lib/legion/extensions/agentic/inference/analogical/helpers/constants.rb +38 -0
  26. data/lib/legion/extensions/agentic/inference/analogical/helpers/structure_map.rb +113 -0
  27. data/lib/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning.rb +106 -0
  28. data/lib/legion/extensions/agentic/inference/analogical/version.rb +13 -0
  29. data/lib/legion/extensions/agentic/inference/analogical.rb +19 -0
  30. data/lib/legion/extensions/agentic/inference/argument_mapping/client.rb +19 -0
  31. data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb +102 -0
  32. data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine.rb +131 -0
  33. data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/constants.rb +44 -0
  34. data/lib/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping.rb +78 -0
  35. data/lib/legion/extensions/agentic/inference/argument_mapping/version.rb +13 -0
  36. data/lib/legion/extensions/agentic/inference/argument_mapping.rb +19 -0
  37. data/lib/legion/extensions/agentic/inference/bayesian/client.rb +28 -0
  38. data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief.rb +96 -0
  39. data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief_network.rb +147 -0
  40. data/lib/legion/extensions/agentic/inference/bayesian/helpers/constants.rb +36 -0
  41. data/lib/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief.rb +125 -0
  42. data/lib/legion/extensions/agentic/inference/bayesian/version.rb +13 -0
  43. data/lib/legion/extensions/agentic/inference/bayesian.rb +19 -0
  44. data/lib/legion/extensions/agentic/inference/belief_revision/client.rb +19 -0
  45. data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief.rb +155 -0
  46. data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief_network.rb +193 -0
  47. data/lib/legion/extensions/agentic/inference/belief_revision/helpers/constants.rb +54 -0
  48. data/lib/legion/extensions/agentic/inference/belief_revision/helpers/evidence.rb +49 -0
  49. data/lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb +89 -0
  50. data/lib/legion/extensions/agentic/inference/belief_revision/version.rb +13 -0
  51. data/lib/legion/extensions/agentic/inference/belief_revision.rb +21 -0
  52. data/lib/legion/extensions/agentic/inference/causal_attribution/client.rb +27 -0
  53. data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb +92 -0
  54. data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine.rb +159 -0
  55. data/lib/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution.rb +111 -0
  56. data/lib/legion/extensions/agentic/inference/causal_attribution/version.rb +13 -0
  57. data/lib/legion/extensions/agentic/inference/causal_attribution.rb +18 -0
  58. data/lib/legion/extensions/agentic/inference/causal_reasoning/client.rb +24 -0
  59. data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge.rb +101 -0
  60. data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph.rb +184 -0
  61. data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/constants.rb +40 -0
  62. data/lib/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning.rb +111 -0
  63. data/lib/legion/extensions/agentic/inference/causal_reasoning/version.rb +13 -0
  64. data/lib/legion/extensions/agentic/inference/causal_reasoning.rb +19 -0
  65. data/lib/legion/extensions/agentic/inference/coherence/client.rb +28 -0
  66. data/lib/legion/extensions/agentic/inference/coherence/helpers/coherence_engine.rb +170 -0
  67. data/lib/legion/extensions/agentic/inference/coherence/helpers/constants.rb +35 -0
  68. data/lib/legion/extensions/agentic/inference/coherence/helpers/proposition.rb +100 -0
  69. data/lib/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence.rb +123 -0
  70. data/lib/legion/extensions/agentic/inference/coherence/version.rb +13 -0
  71. data/lib/legion/extensions/agentic/inference/coherence.rb +19 -0
  72. data/lib/legion/extensions/agentic/inference/counterfactual/client.rb +19 -0
  73. data/lib/legion/extensions/agentic/inference/counterfactual/helpers/constants.rb +40 -0
  74. data/lib/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine.rb +157 -0
  75. data/lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb +98 -0
  76. data/lib/legion/extensions/agentic/inference/counterfactual/runners/counterfactual.rb +106 -0
  77. data/lib/legion/extensions/agentic/inference/counterfactual/version.rb +13 -0
  78. data/lib/legion/extensions/agentic/inference/counterfactual.rb +19 -0
  79. data/lib/legion/extensions/agentic/inference/debugging/client.rb +30 -0
  80. data/lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb +51 -0
  81. data/lib/legion/extensions/agentic/inference/debugging/helpers/constants.rb +58 -0
  82. data/lib/legion/extensions/agentic/inference/debugging/helpers/correction.rb +56 -0
  83. data/lib/legion/extensions/agentic/inference/debugging/helpers/debugging_engine.rb +156 -0
  84. data/lib/legion/extensions/agentic/inference/debugging/helpers/reasoning_error.rb +97 -0
  85. data/lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb +178 -0
  86. data/lib/legion/extensions/agentic/inference/debugging/version.rb +13 -0
  87. data/lib/legion/extensions/agentic/inference/debugging.rb +21 -0
  88. data/lib/legion/extensions/agentic/inference/enactive_cognition/client.rb +27 -0
  89. data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb +120 -0
  90. data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop.rb +122 -0
  91. data/lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb +124 -0
  92. data/lib/legion/extensions/agentic/inference/enactive_cognition/version.rb +13 -0
  93. data/lib/legion/extensions/agentic/inference/enactive_cognition.rb +18 -0
  94. data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/client.rb +17 -0
  95. data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/constants.rb +47 -0
  96. data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/expectation.rb +82 -0
  97. data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine.rb +126 -0
  98. data/lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb +76 -0
  99. data/lib/legion/extensions/agentic/inference/expectation_violation/version.rb +13 -0
  100. data/lib/legion/extensions/agentic/inference/expectation_violation.rb +19 -0
  101. data/lib/legion/extensions/agentic/inference/free_energy/client.rb +19 -0
  102. data/lib/legion/extensions/agentic/inference/free_energy/helpers/belief.rb +127 -0
  103. data/lib/legion/extensions/agentic/inference/free_energy/helpers/constants.rb +58 -0
  104. data/lib/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine.rb +156 -0
  105. data/lib/legion/extensions/agentic/inference/free_energy/runners/free_energy.rb +97 -0
  106. data/lib/legion/extensions/agentic/inference/free_energy/version.rb +13 -0
  107. data/lib/legion/extensions/agentic/inference/free_energy.rb +19 -0
  108. data/lib/legion/extensions/agentic/inference/gravity/client.rb +29 -0
  109. data/lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb +77 -0
  110. data/lib/legion/extensions/agentic/inference/gravity/helpers/constants.rb +76 -0
  111. data/lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb +164 -0
  112. data/lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb +64 -0
  113. data/lib/legion/extensions/agentic/inference/gravity/runners/gravity.rb +132 -0
  114. data/lib/legion/extensions/agentic/inference/gravity/version.rb +13 -0
  115. data/lib/legion/extensions/agentic/inference/gravity.rb +20 -0
  116. data/lib/legion/extensions/agentic/inference/horizon/actors/adjust.rb +45 -0
  117. data/lib/legion/extensions/agentic/inference/horizon/client.rb +28 -0
  118. data/lib/legion/extensions/agentic/inference/horizon/helpers/constants.rb +43 -0
  119. data/lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb +110 -0
  120. data/lib/legion/extensions/agentic/inference/horizon/helpers/projection.rb +59 -0
  121. data/lib/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon.rb +107 -0
  122. data/lib/legion/extensions/agentic/inference/horizon/version.rb +13 -0
  123. data/lib/legion/extensions/agentic/inference/horizon.rb +19 -0
  124. data/lib/legion/extensions/agentic/inference/hypothesis_testing/client.rb +28 -0
  125. data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants.rb +37 -0
  126. data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb +83 -0
  127. data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine.rb +97 -0
  128. data/lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb +115 -0
  129. data/lib/legion/extensions/agentic/inference/hypothesis_testing/version.rb +13 -0
  130. data/lib/legion/extensions/agentic/inference/hypothesis_testing.rb +19 -0
  131. data/lib/legion/extensions/agentic/inference/intuition/client.rb +19 -0
  132. data/lib/legion/extensions/agentic/inference/intuition/helpers/constants.rb +60 -0
  133. data/lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb +66 -0
  134. data/lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb +157 -0
  135. data/lib/legion/extensions/agentic/inference/intuition/helpers/pattern.rb +105 -0
  136. data/lib/legion/extensions/agentic/inference/intuition/runners/intuition.rb +87 -0
  137. data/lib/legion/extensions/agentic/inference/intuition/version.rb +13 -0
  138. data/lib/legion/extensions/agentic/inference/intuition.rb +20 -0
  139. data/lib/legion/extensions/agentic/inference/magnet/client.rb +29 -0
  140. data/lib/legion/extensions/agentic/inference/magnet/helpers/constants.rb +57 -0
  141. data/lib/legion/extensions/agentic/inference/magnet/helpers/field.rb +105 -0
  142. data/lib/legion/extensions/agentic/inference/magnet/helpers/magnet_engine.rb +179 -0
  143. data/lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb +80 -0
  144. data/lib/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet.rb +124 -0
  145. data/lib/legion/extensions/agentic/inference/magnet/version.rb +13 -0
  146. data/lib/legion/extensions/agentic/inference/magnet.rb +21 -0
  147. data/lib/legion/extensions/agentic/inference/momentum/helpers/client.rb +17 -0
  148. data/lib/legion/extensions/agentic/inference/momentum/helpers/constants.rb +65 -0
  149. data/lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb +112 -0
  150. data/lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb +127 -0
  151. data/lib/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum.rb +101 -0
  152. data/lib/legion/extensions/agentic/inference/momentum/version.rb +13 -0
  153. data/lib/legion/extensions/agentic/inference/momentum.rb +19 -0
  154. data/lib/legion/extensions/agentic/inference/perceptual_inference/client.rb +28 -0
  155. data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/constants.rb +34 -0
  156. data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field.rb +154 -0
  157. data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb +100 -0
  158. data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb +120 -0
  159. data/lib/legion/extensions/agentic/inference/perceptual_inference/version.rb +13 -0
  160. data/lib/legion/extensions/agentic/inference/perceptual_inference.rb +19 -0
  161. data/lib/legion/extensions/agentic/inference/prediction/actors/expire_predictions.rb +45 -0
  162. data/lib/legion/extensions/agentic/inference/prediction/client.rb +27 -0
  163. data/lib/legion/extensions/agentic/inference/prediction/helpers/modes.rb +28 -0
  164. data/lib/legion/extensions/agentic/inference/prediction/helpers/prediction_store.rb +66 -0
  165. data/lib/legion/extensions/agentic/inference/prediction/runners/prediction.rb +146 -0
  166. data/lib/legion/extensions/agentic/inference/prediction/version.rb +13 -0
  167. data/lib/legion/extensions/agentic/inference/prediction.rb +18 -0
  168. data/lib/legion/extensions/agentic/inference/predictive_coding/actors/decay.rb +45 -0
  169. data/lib/legion/extensions/agentic/inference/predictive_coding/client.rb +28 -0
  170. data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/constants.rb +46 -0
  171. data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model.rb +187 -0
  172. data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb +59 -0
  173. data/lib/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding.rb +171 -0
  174. data/lib/legion/extensions/agentic/inference/predictive_coding/version.rb +13 -0
  175. data/lib/legion/extensions/agentic/inference/predictive_coding.rb +20 -0
  176. data/lib/legion/extensions/agentic/inference/predictive_processing/client.rb +28 -0
  177. data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/constants.rb +35 -0
  178. data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model.rb +142 -0
  179. data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor.rb +129 -0
  180. data/lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb +104 -0
  181. data/lib/legion/extensions/agentic/inference/predictive_processing/version.rb +13 -0
  182. data/lib/legion/extensions/agentic/inference/predictive_processing.rb +19 -0
  183. data/lib/legion/extensions/agentic/inference/reality_testing/client.rb +28 -0
  184. data/lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb +98 -0
  185. data/lib/legion/extensions/agentic/inference/reality_testing/helpers/constants.rb +41 -0
  186. data/lib/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine.rb +104 -0
  187. data/lib/legion/extensions/agentic/inference/reality_testing/runners/reality_testing.rb +94 -0
  188. data/lib/legion/extensions/agentic/inference/reality_testing/version.rb +13 -0
  189. data/lib/legion/extensions/agentic/inference/reality_testing.rb +19 -0
  190. data/lib/legion/extensions/agentic/inference/schema/client.rb +26 -0
  191. data/lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb +70 -0
  192. data/lib/legion/extensions/agentic/inference/schema/helpers/constants.rb +50 -0
  193. data/lib/legion/extensions/agentic/inference/schema/helpers/world_model.rb +173 -0
  194. data/lib/legion/extensions/agentic/inference/schema/runners/schema.rb +101 -0
  195. data/lib/legion/extensions/agentic/inference/schema/version.rb +13 -0
  196. data/lib/legion/extensions/agentic/inference/schema.rb +19 -0
  197. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/client.rb +28 -0
  198. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants.rb +42 -0
  199. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb +66 -0
  200. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine.rb +139 -0
  201. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb +129 -0
  202. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/version.rb +13 -0
  203. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance.rb +19 -0
  204. data/lib/legion/extensions/agentic/inference/version.rb +11 -0
  205. data/lib/legion/extensions/agentic/inference.rb +44 -0
  206. data/spec/legion/extensions/agentic/inference/abductive/client_spec.rb +25 -0
  207. data/spec/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning_spec.rb +349 -0
  208. data/spec/legion/extensions/agentic/inference/affordance/client_spec.rb +26 -0
  209. data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_field_spec.rb +131 -0
  210. data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_item_spec.rb +107 -0
  211. data/spec/legion/extensions/agentic/inference/affordance/runners/affordance_spec.rb +78 -0
  212. data/spec/legion/extensions/agentic/inference/analogical/client_spec.rb +31 -0
  213. data/spec/legion/extensions/agentic/inference/analogical/helpers/analogy_engine_spec.rb +276 -0
  214. data/spec/legion/extensions/agentic/inference/analogical/helpers/structure_map_spec.rb +255 -0
  215. data/spec/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning_spec.rb +213 -0
  216. data/spec/legion/extensions/agentic/inference/argument_mapping/client_spec.rb +18 -0
  217. data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine_spec.rb +218 -0
  218. data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_spec.rb +231 -0
  219. data/spec/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping_spec.rb +171 -0
  220. data/spec/legion/extensions/agentic/inference/bayesian/client_spec.rb +20 -0
  221. data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_network_spec.rb +178 -0
  222. data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_spec.rb +137 -0
  223. data/spec/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief_spec.rb +176 -0
  224. data/spec/legion/extensions/agentic/inference/belief_revision/client_spec.rb +31 -0
  225. data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_network_spec.rb +176 -0
  226. data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_spec.rb +153 -0
  227. data/spec/legion/extensions/agentic/inference/belief_revision/helpers/evidence_spec.rb +51 -0
  228. data/spec/legion/extensions/agentic/inference/belief_revision/runners/belief_revision_spec.rb +106 -0
  229. data/spec/legion/extensions/agentic/inference/causal_attribution/client_spec.rb +24 -0
  230. data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine_spec.rb +181 -0
  231. data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_spec.rb +108 -0
  232. data/spec/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution_spec.rb +142 -0
  233. data/spec/legion/extensions/agentic/inference/causal_reasoning/client_spec.rb +35 -0
  234. data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge_spec.rb +158 -0
  235. data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph_spec.rb +259 -0
  236. data/spec/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning_spec.rb +161 -0
  237. data/spec/legion/extensions/agentic/inference/coherence/client_spec.rb +17 -0
  238. data/spec/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence_spec.rb +267 -0
  239. data/spec/legion/extensions/agentic/inference/counterfactual/client_spec.rb +48 -0
  240. data/spec/legion/extensions/agentic/inference/counterfactual/helpers/constants_spec.rb +55 -0
  241. data/spec/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine_spec.rb +234 -0
  242. data/spec/legion/extensions/agentic/inference/counterfactual/helpers/scenario_spec.rb +193 -0
  243. data/spec/legion/extensions/agentic/inference/counterfactual/runners/counterfactual_spec.rb +179 -0
  244. data/spec/legion/extensions/agentic/inference/debugging/client_spec.rb +46 -0
  245. data/spec/legion/extensions/agentic/inference/debugging/helpers/causal_trace_spec.rb +84 -0
  246. data/spec/legion/extensions/agentic/inference/debugging/helpers/constants_spec.rb +97 -0
  247. data/spec/legion/extensions/agentic/inference/debugging/helpers/correction_spec.rb +98 -0
  248. data/spec/legion/extensions/agentic/inference/debugging/helpers/debugging_engine_spec.rb +290 -0
  249. data/spec/legion/extensions/agentic/inference/debugging/helpers/reasoning_error_spec.rb +164 -0
  250. data/spec/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging_spec.rb +301 -0
  251. data/spec/legion/extensions/agentic/inference/enactive_cognition/client_spec.rb +19 -0
  252. data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine_spec.rb +181 -0
  253. data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop_spec.rb +184 -0
  254. data/spec/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition_spec.rb +214 -0
  255. data/spec/legion/extensions/agentic/inference/expectation_violation/expectation_violation_spec.rb +11 -0
  256. data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/expectation_spec.rb +102 -0
  257. data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine_spec.rb +121 -0
  258. data/spec/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation_spec.rb +59 -0
  259. data/spec/legion/extensions/agentic/inference/free_energy/client_spec.rb +46 -0
  260. data/spec/legion/extensions/agentic/inference/free_energy/helpers/belief_spec.rb +183 -0
  261. data/spec/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine_spec.rb +211 -0
  262. data/spec/legion/extensions/agentic/inference/free_energy/runners/free_energy_spec.rb +118 -0
  263. data/spec/legion/extensions/agentic/inference/gravity/client_spec.rb +24 -0
  264. data/spec/legion/extensions/agentic/inference/gravity/helpers/attractor_spec.rb +143 -0
  265. data/spec/legion/extensions/agentic/inference/gravity/helpers/constants_spec.rb +107 -0
  266. data/spec/legion/extensions/agentic/inference/gravity/helpers/gravity_engine_spec.rb +193 -0
  267. data/spec/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought_spec.rb +103 -0
  268. data/spec/legion/extensions/agentic/inference/gravity/runners/gravity_spec.rb +159 -0
  269. data/spec/legion/extensions/agentic/inference/horizon/client_spec.rb +58 -0
  270. data/spec/legion/extensions/agentic/inference/horizon/helpers/constants_spec.rb +98 -0
  271. data/spec/legion/extensions/agentic/inference/horizon/helpers/horizon_engine_spec.rb +325 -0
  272. data/spec/legion/extensions/agentic/inference/horizon/helpers/projection_spec.rb +155 -0
  273. data/spec/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon_spec.rb +269 -0
  274. data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants_spec.rb +38 -0
  275. data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine_spec.rb +182 -0
  276. data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_spec.rb +172 -0
  277. data/spec/legion/extensions/agentic/inference/hypothesis_testing/hypothesis_testing_spec.rb +16 -0
  278. data/spec/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing_spec.rb +159 -0
  279. data/spec/legion/extensions/agentic/inference/intuition/client_spec.rb +33 -0
  280. data/spec/legion/extensions/agentic/inference/intuition/helpers/heuristic_spec.rb +82 -0
  281. data/spec/legion/extensions/agentic/inference/intuition/helpers/intuition_engine_spec.rb +163 -0
  282. data/spec/legion/extensions/agentic/inference/intuition/helpers/pattern_spec.rb +160 -0
  283. data/spec/legion/extensions/agentic/inference/intuition/runners/intuition_spec.rb +107 -0
  284. data/spec/legion/extensions/agentic/inference/magnet/client_spec.rb +30 -0
  285. data/spec/legion/extensions/agentic/inference/magnet/helpers/constants_spec.rb +120 -0
  286. data/spec/legion/extensions/agentic/inference/magnet/helpers/field_spec.rb +193 -0
  287. data/spec/legion/extensions/agentic/inference/magnet/helpers/magnet_engine_spec.rb +281 -0
  288. data/spec/legion/extensions/agentic/inference/magnet/helpers/pole_spec.rb +211 -0
  289. data/spec/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet_spec.rb +201 -0
  290. data/spec/legion/extensions/agentic/inference/momentum/cognitive_momentum_spec.rb +11 -0
  291. data/spec/legion/extensions/agentic/inference/momentum/helpers/idea_spec.rb +152 -0
  292. data/spec/legion/extensions/agentic/inference/momentum/helpers/momentum_engine_spec.rb +154 -0
  293. data/spec/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum_spec.rb +97 -0
  294. data/spec/legion/extensions/agentic/inference/perceptual_inference/client_spec.rb +39 -0
  295. data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/constants_spec.rb +97 -0
  296. data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field_spec.rb +270 -0
  297. data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis_spec.rb +206 -0
  298. data/spec/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference_spec.rb +305 -0
  299. data/spec/legion/extensions/agentic/inference/prediction/actors/expire_predictions_spec.rb +46 -0
  300. data/spec/legion/extensions/agentic/inference/prediction/client_spec.rb +14 -0
  301. data/spec/legion/extensions/agentic/inference/prediction/helpers/modes_spec.rb +118 -0
  302. data/spec/legion/extensions/agentic/inference/prediction/helpers/prediction_store_spec.rb +262 -0
  303. data/spec/legion/extensions/agentic/inference/prediction/runners/prediction_spec.rb +116 -0
  304. data/spec/legion/extensions/agentic/inference/predictive_coding/client_spec.rb +74 -0
  305. data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model_spec.rb +194 -0
  306. data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error_spec.rb +109 -0
  307. data/spec/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding_spec.rb +210 -0
  308. data/spec/legion/extensions/agentic/inference/predictive_processing/client_spec.rb +82 -0
  309. data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model_spec.rb +220 -0
  310. data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor_spec.rb +206 -0
  311. data/spec/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing_spec.rb +213 -0
  312. data/spec/legion/extensions/agentic/inference/reality_testing/client_spec.rb +29 -0
  313. data/spec/legion/extensions/agentic/inference/reality_testing/helpers/belief_spec.rb +197 -0
  314. data/spec/legion/extensions/agentic/inference/reality_testing/helpers/constants_spec.rb +78 -0
  315. data/spec/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine_spec.rb +191 -0
  316. data/spec/legion/extensions/agentic/inference/reality_testing/runners/reality_testing_spec.rb +154 -0
  317. data/spec/legion/extensions/agentic/inference/schema/client_spec.rb +53 -0
  318. data/spec/legion/extensions/agentic/inference/schema/helpers/causal_relation_spec.rb +108 -0
  319. data/spec/legion/extensions/agentic/inference/schema/helpers/constants_spec.rb +54 -0
  320. data/spec/legion/extensions/agentic/inference/schema/helpers/world_model_spec.rb +179 -0
  321. data/spec/legion/extensions/agentic/inference/schema/runners/schema_spec.rb +146 -0
  322. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/client_spec.rb +18 -0
  323. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants_spec.rb +62 -0
  324. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision_spec.rb +125 -0
  325. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine_spec.rb +184 -0
  326. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance_spec.rb +157 -0
  327. data/spec/spec_helper.rb +46 -0
  328. metadata +412 -0
@@ -0,0 +1,206 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Legion::Extensions::Agentic::Inference::PerceptualInference::Helpers::PerceptualHypothesis do
4
+ subject(:hypothesis) do
5
+ described_class.new(content: 'red cube', modality: :visual, domain: :objects, prior: 0.6)
6
+ end
7
+
8
+ describe '#initialize' do
9
+ it 'assigns a UUID id' do
10
+ expect(hypothesis.id).to match(/\A[0-9a-f-]{36}\z/)
11
+ end
12
+
13
+ it 'stores content' do
14
+ expect(hypothesis.content).to eq('red cube')
15
+ end
16
+
17
+ it 'stores modality' do
18
+ expect(hypothesis.modality).to eq(:visual)
19
+ end
20
+
21
+ it 'stores domain' do
22
+ expect(hypothesis.domain).to eq(:objects)
23
+ end
24
+
25
+ it 'clamps prior to PRIOR_CEILING' do
26
+ h = described_class.new(content: 'x', modality: :visual, prior: 1.5)
27
+ expect(h.prior).to be_within(0.001).of(0.99)
28
+ end
29
+
30
+ it 'clamps prior to PRIOR_FLOOR' do
31
+ h = described_class.new(content: 'x', modality: :visual, prior: -0.5)
32
+ expect(h.prior).to be_within(0.001).of(0.01)
33
+ end
34
+
35
+ it 'initializes state as :active' do
36
+ expect(hypothesis.state).to eq(:active)
37
+ end
38
+
39
+ it 'initializes likelihood at 0.5' do
40
+ expect(hypothesis.likelihood).to be_within(0.001).of(0.5)
41
+ end
42
+
43
+ it 'initializes posterior equal to prior' do
44
+ expect(hypothesis.posterior).to be_within(0.001).of(0.6)
45
+ end
46
+
47
+ it 'sets created_at' do
48
+ expect(hypothesis.created_at).to be_a(Time)
49
+ end
50
+
51
+ it 'uses DEFAULT_PRIOR when no prior given' do
52
+ h = described_class.new(content: 'x', modality: :visual)
53
+ expect(h.prior).to be_within(0.001).of(0.5)
54
+ end
55
+ end
56
+
57
+ describe '#compute_posterior' do
58
+ it 'returns a float between 0 and 1' do
59
+ result = hypothesis.compute_posterior(evidence_weight: 0.8)
60
+ expect(result).to be_between(0.0, 1.0)
61
+ end
62
+
63
+ it 'updates the posterior attribute' do
64
+ hypothesis.compute_posterior(evidence_weight: 0.8)
65
+ expect(hypothesis.posterior).to be_between(0.0, 1.0)
66
+ end
67
+
68
+ it 'uses EVIDENCE_STRENGTH_FLOOR when weight is too low' do
69
+ result = hypothesis.compute_posterior(evidence_weight: 0.001)
70
+ expect(result).to be_between(0.0, 1.0)
71
+ end
72
+ end
73
+
74
+ describe '#select!' do
75
+ it 'transitions state to :selected' do
76
+ hypothesis.select!
77
+ expect(hypothesis.state).to eq(:selected)
78
+ end
79
+ end
80
+
81
+ describe '#suppress!' do
82
+ it 'transitions state to :suppressed' do
83
+ hypothesis.suppress!
84
+ expect(hypothesis.state).to eq(:suppressed)
85
+ end
86
+ end
87
+
88
+ describe '#selected?' do
89
+ it 'returns false when active' do
90
+ expect(hypothesis.selected?).to be false
91
+ end
92
+
93
+ it 'returns true after select!' do
94
+ hypothesis.select!
95
+ expect(hypothesis.selected?).to be true
96
+ end
97
+
98
+ it 'returns false after suppress!' do
99
+ hypothesis.suppress!
100
+ expect(hypothesis.selected?).to be false
101
+ end
102
+ end
103
+
104
+ describe '#rival_with?' do
105
+ it 'returns true when posteriors are within RIVALRY_MARGIN' do
106
+ other = described_class.new(content: 'blue cube', modality: :visual, prior: 0.6)
107
+ other.instance_variable_set(:@posterior, hypothesis.posterior + 0.05)
108
+ expect(hypothesis.rival_with?(other)).to be true
109
+ end
110
+
111
+ it 'returns false when posteriors differ by more than RIVALRY_MARGIN' do
112
+ other = described_class.new(content: 'blue cube', modality: :visual, prior: 0.1)
113
+ other.instance_variable_set(:@posterior, 0.1)
114
+ hypothesis.instance_variable_set(:@posterior, 0.9)
115
+ expect(hypothesis.rival_with?(other)).to be false
116
+ end
117
+
118
+ it 'returns false for non-hypothesis argument' do
119
+ expect(hypothesis.rival_with?('not a hypothesis')).to be false
120
+ end
121
+ end
122
+
123
+ describe '#adapt_prior' do
124
+ it 'increases prior on :correct outcome' do
125
+ old_prior = hypothesis.prior
126
+ hypothesis.adapt_prior(outcome: :correct)
127
+ expect(hypothesis.prior).to be > old_prior
128
+ end
129
+
130
+ it 'decreases prior on :incorrect outcome' do
131
+ old_prior = hypothesis.prior
132
+ hypothesis.adapt_prior(outcome: :incorrect)
133
+ expect(hypothesis.prior).to be < old_prior
134
+ end
135
+
136
+ it 'stays within bounds after many correct outcomes' do
137
+ 20.times { hypothesis.adapt_prior(outcome: :correct) }
138
+ expect(hypothesis.prior).to be <= 0.99
139
+ end
140
+
141
+ it 'stays within bounds after many incorrect outcomes' do
142
+ 20.times { hypothesis.adapt_prior(outcome: :incorrect) }
143
+ expect(hypothesis.prior).to be >= 0.01
144
+ end
145
+ end
146
+
147
+ describe '#decay' do
148
+ it 'moves prior toward DEFAULT_PRIOR' do
149
+ h = described_class.new(content: 'x', modality: :visual, prior: 0.9)
150
+ h.decay
151
+ expect(h.prior).to be < 0.9
152
+ end
153
+
154
+ it 'moves prior up from very low values' do
155
+ h = described_class.new(content: 'x', modality: :visual, prior: 0.05)
156
+ h.decay
157
+ expect(h.prior).to be > 0.04
158
+ end
159
+
160
+ it 'marks state as :decayed when suppressed and prior hits floor' do
161
+ h = described_class.new(content: 'x', modality: :visual, prior: 0.5)
162
+ h.suppress!
163
+ 30.times { h.decay }
164
+ expect(h.state).to eq(:decayed)
165
+ end
166
+ end
167
+
168
+ describe '#percept_label' do
169
+ it 'returns :vivid for posterior >= 0.8' do
170
+ hypothesis.instance_variable_set(:@posterior, 0.85)
171
+ expect(hypothesis.percept_label).to eq(:vivid)
172
+ end
173
+
174
+ it 'returns :clear for posterior in 0.6..0.8' do
175
+ hypothesis.instance_variable_set(:@posterior, 0.7)
176
+ expect(hypothesis.percept_label).to eq(:clear)
177
+ end
178
+
179
+ it 'returns :ambiguous for posterior around 0.5' do
180
+ hypothesis.instance_variable_set(:@posterior, 0.5)
181
+ expect(hypothesis.percept_label).to eq(:ambiguous)
182
+ end
183
+
184
+ it 'returns :faint for posterior in 0.2..0.4' do
185
+ hypothesis.instance_variable_set(:@posterior, 0.3)
186
+ expect(hypothesis.percept_label).to eq(:faint)
187
+ end
188
+
189
+ it 'returns :subliminal for posterior < 0.2' do
190
+ hypothesis.instance_variable_set(:@posterior, 0.1)
191
+ expect(hypothesis.percept_label).to eq(:subliminal)
192
+ end
193
+ end
194
+
195
+ describe '#to_h' do
196
+ it 'returns a hash with required keys' do
197
+ h = hypothesis.to_h
198
+ expect(h.keys).to include(:id, :content, :modality, :domain, :prior, :likelihood, :posterior, :state, :label, :created_at)
199
+ end
200
+
201
+ it 'rounds prior to 4 decimal places' do
202
+ h = hypothesis.to_h
203
+ expect(h[:prior].to_s).to match(/\A\d+\.\d{1,4}\z/)
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,305 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/agentic/inference/perceptual_inference/client'
4
+
5
+ RSpec.describe Legion::Extensions::Agentic::Inference::PerceptualInference::Runners::PerceptualInference do
6
+ let(:client) { Legion::Extensions::Agentic::Inference::PerceptualInference::Client.new }
7
+
8
+ describe '#register_percept_hypothesis' do
9
+ it 'returns success: true for valid modality' do
10
+ result = client.register_percept_hypothesis(content: 'red square', modality: :visual)
11
+ expect(result[:success]).to be true
12
+ end
13
+
14
+ it 'returns a hypothesis_id UUID' do
15
+ result = client.register_percept_hypothesis(content: 'red square', modality: :visual)
16
+ expect(result[:hypothesis_id]).to match(/\A[0-9a-f-]{36}\z/)
17
+ end
18
+
19
+ it 'returns the modality in the result' do
20
+ result = client.register_percept_hypothesis(content: 'red square', modality: :visual)
21
+ expect(result[:modality]).to eq(:visual)
22
+ end
23
+
24
+ it 'returns success: false for unknown modality' do
25
+ result = client.register_percept_hypothesis(content: 'x', modality: :unknown)
26
+ expect(result[:success]).to be false
27
+ expect(result[:error]).to be_a(String)
28
+ end
29
+
30
+ it 'uses DEFAULT_PRIOR when no prior given' do
31
+ result = client.register_percept_hypothesis(content: 'cat', modality: :visual)
32
+ expect(result[:prior]).to be_within(0.001).of(0.5)
33
+ end
34
+
35
+ it 'accepts custom prior' do
36
+ result = client.register_percept_hypothesis(content: 'dog', modality: :visual, prior: 0.8)
37
+ expect(result[:prior]).to be_within(0.001).of(0.8)
38
+ end
39
+
40
+ it 'accepts all valid modalities' do
41
+ Legion::Extensions::Agentic::Inference::PerceptualInference::Helpers::MODALITIES.each do |mod|
42
+ result = client.register_percept_hypothesis(content: 'x', modality: mod)
43
+ expect(result[:success]).to be true
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#present_perceptual_evidence' do
49
+ before { client.register_percept_hypothesis(content: 'cat', modality: :visual) }
50
+
51
+ it 'returns success: true' do
52
+ result = client.present_perceptual_evidence(modality: :visual, content: 'cat', strength: 0.8)
53
+ expect(result[:success]).to be true
54
+ end
55
+
56
+ it 'returns hypotheses_updated count' do
57
+ result = client.present_perceptual_evidence(modality: :visual, content: 'cat', strength: 0.8)
58
+ expect(result[:hypotheses_updated]).to eq(1)
59
+ end
60
+
61
+ it 'includes rivalry status' do
62
+ result = client.present_perceptual_evidence(modality: :visual, content: 'cat', strength: 0.8)
63
+ expect(result).to have_key(:rivalry)
64
+ end
65
+
66
+ it 'returns success: false for unknown modality' do
67
+ result = client.present_perceptual_evidence(modality: :bogus, content: 'cat', strength: 0.5)
68
+ expect(result[:success]).to be false
69
+ end
70
+
71
+ it 'defaults strength to 0.5' do
72
+ result = client.present_perceptual_evidence(modality: :visual, content: 'cat')
73
+ expect(result[:success]).to be true
74
+ end
75
+ end
76
+
77
+ describe '#select_percept' do
78
+ it 'returns success: true' do
79
+ result = client.select_percept(modality: :visual)
80
+ expect(result[:success]).to be true
81
+ end
82
+
83
+ it 'returns selected: false when no hypotheses' do
84
+ result = client.select_percept(modality: :visual)
85
+ expect(result[:selected]).to be false
86
+ end
87
+
88
+ it 'selects a strong hypothesis' do
89
+ client.register_percept_hypothesis(content: 'bright light', modality: :visual, prior: 0.95)
90
+ client.present_perceptual_evidence(modality: :visual, content: 'bright light', strength: 0.99)
91
+ result = client.select_percept(modality: :visual)
92
+ expect(result[:selected]).to be true
93
+ expect(result[:hypothesis]).to be_a(Hash)
94
+ end
95
+
96
+ it 'returns selected: false for weak hypothesis' do
97
+ client.register_percept_hypothesis(content: 'faint', modality: :visual, prior: 0.1)
98
+ result = client.select_percept(modality: :visual)
99
+ expect(result[:selected]).to be false
100
+ end
101
+
102
+ it 'returns success: false for unknown modality' do
103
+ result = client.select_percept(modality: :unknown)
104
+ expect(result[:success]).to be false
105
+ end
106
+
107
+ it 'returns percept label when selected' do
108
+ client.register_percept_hypothesis(content: 'vivid image', modality: :visual, prior: 0.95)
109
+ client.present_perceptual_evidence(modality: :visual, content: 'vivid image', strength: 0.99)
110
+ result = client.select_percept(modality: :visual)
111
+ expect(result[:hypothesis][:label]).to be_a(Symbol)
112
+ end
113
+ end
114
+
115
+ describe '#check_rivalry' do
116
+ it 'returns success: true' do
117
+ result = client.check_rivalry(modality: :visual)
118
+ expect(result[:success]).to be true
119
+ end
120
+
121
+ it 'returns rivalry: false with no hypotheses' do
122
+ result = client.check_rivalry(modality: :visual)
123
+ expect(result[:rivalry]).to be false
124
+ end
125
+
126
+ it 'returns top_hypotheses array' do
127
+ result = client.check_rivalry(modality: :visual)
128
+ expect(result[:top_hypotheses]).to be_an(Array)
129
+ end
130
+
131
+ it 'detects rivalry between two evenly matched hypotheses' do
132
+ client.register_percept_hypothesis(content: 'necker left', modality: :visual, prior: 0.6)
133
+ client.register_percept_hypothesis(content: 'necker right', modality: :visual, prior: 0.6)
134
+ client.present_perceptual_evidence(modality: :visual, content: 'necker', strength: 0.5)
135
+ result = client.check_rivalry(modality: :visual)
136
+ expect(result[:rivalry]).to be(true).or be(false)
137
+ end
138
+
139
+ it 'returns success: false for invalid modality' do
140
+ result = client.check_rivalry(modality: :nonexistent)
141
+ expect(result[:success]).to be false
142
+ end
143
+ end
144
+
145
+ describe '#current_percept' do
146
+ it 'returns success: true' do
147
+ result = client.current_percept(modality: :visual)
148
+ expect(result[:success]).to be true
149
+ end
150
+
151
+ it 'returns found: false when nothing selected' do
152
+ result = client.current_percept(modality: :visual)
153
+ expect(result[:found]).to be false
154
+ end
155
+
156
+ it 'returns found: true after selection' do
157
+ client.register_percept_hypothesis(content: 'clear sky', modality: :visual, prior: 0.95)
158
+ client.present_perceptual_evidence(modality: :visual, content: 'clear sky', strength: 0.99)
159
+ client.select_percept(modality: :visual)
160
+ result = client.current_percept(modality: :visual)
161
+ expect(result[:found]).to be true
162
+ end
163
+
164
+ it 'returns the percept hash when found' do
165
+ client.register_percept_hypothesis(content: 'bright', modality: :visual, prior: 0.95)
166
+ client.present_perceptual_evidence(modality: :visual, content: 'bright', strength: 0.99)
167
+ client.select_percept(modality: :visual)
168
+ result = client.current_percept(modality: :visual)
169
+ expect(result[:percept]).to be_a(Hash)
170
+ end
171
+
172
+ it 'returns success: false for invalid modality' do
173
+ result = client.current_percept(modality: :invalid)
174
+ expect(result[:success]).to be false
175
+ end
176
+ end
177
+
178
+ describe '#adapt_perception' do
179
+ it 'returns success: true for valid modality' do
180
+ h = client.register_percept_hypothesis(content: 'cat', modality: :visual)
181
+ result = client.adapt_perception(modality: :visual, correct_hypothesis_id: h[:hypothesis_id])
182
+ expect(result[:success]).to be true
183
+ end
184
+
185
+ it 'includes modality and correct_hypothesis_id' do
186
+ h = client.register_percept_hypothesis(content: 'cat', modality: :visual)
187
+ result = client.adapt_perception(modality: :visual, correct_hypothesis_id: h[:hypothesis_id])
188
+ expect(result[:modality]).to eq(:visual)
189
+ expect(result[:correct_hypothesis_id]).to eq(h[:hypothesis_id])
190
+ end
191
+
192
+ it 'returns success: false for invalid modality' do
193
+ result = client.adapt_perception(modality: :bogus, correct_hypothesis_id: 'some-id')
194
+ expect(result[:success]).to be false
195
+ end
196
+ end
197
+
198
+ describe '#suppress_percept' do
199
+ it 'returns success: true' do
200
+ h = client.register_percept_hypothesis(content: 'cat', modality: :visual)
201
+ result = client.suppress_percept(hypothesis_id: h[:hypothesis_id])
202
+ expect(result[:success]).to be true
203
+ end
204
+
205
+ it 'returns suppressed: true for existing hypothesis' do
206
+ h = client.register_percept_hypothesis(content: 'cat', modality: :visual)
207
+ result = client.suppress_percept(hypothesis_id: h[:hypothesis_id])
208
+ expect(result[:suppressed]).to be true
209
+ end
210
+
211
+ it 'returns suppressed: false for unknown hypothesis' do
212
+ result = client.suppress_percept(hypothesis_id: 'unknown-uuid')
213
+ expect(result[:suppressed]).to be false
214
+ end
215
+ end
216
+
217
+ describe '#perceptual_ambiguity' do
218
+ it 'returns success: true' do
219
+ result = client.perceptual_ambiguity
220
+ expect(result[:success]).to be true
221
+ end
222
+
223
+ it 'returns ambiguity_level as a float' do
224
+ result = client.perceptual_ambiguity
225
+ expect(result[:ambiguity_level]).to be_a(Float)
226
+ end
227
+
228
+ it 'returns a label' do
229
+ result = client.perceptual_ambiguity
230
+ expect(%i[none low moderate high]).to include(result[:label])
231
+ end
232
+
233
+ it 'returns :none when no hypotheses exist' do
234
+ result = client.perceptual_ambiguity
235
+ expect(result[:label]).to eq(:none)
236
+ end
237
+
238
+ it 'returns ambiguity_level of 0.0 with no hypotheses' do
239
+ result = client.perceptual_ambiguity
240
+ expect(result[:ambiguity_level]).to be_within(0.001).of(0.0)
241
+ end
242
+ end
243
+
244
+ describe '#update_perceptual_inference' do
245
+ it 'returns success: true' do
246
+ result = client.update_perceptual_inference
247
+ expect(result[:success]).to be true
248
+ end
249
+
250
+ it 'returns remaining_hypotheses count' do
251
+ client.register_percept_hypothesis(content: 'cat', modality: :visual)
252
+ result = client.update_perceptual_inference
253
+ expect(result[:remaining_hypotheses]).to be_a(Integer)
254
+ end
255
+
256
+ it 'reduces count of very-low-prior hypotheses over many cycles' do
257
+ h = client.register_percept_hypothesis(content: 'ghost', modality: :visual, prior: 0.011)
258
+ h_id = h[:hypothesis_id]
259
+ 30.times { client.update_perceptual_inference }
260
+ result = client.perceptual_inference_stats
261
+ ids = result[:stats][:by_modality][:visual]&.dig(:percept, :id)
262
+ expect(ids).not_to eq(h_id)
263
+ end
264
+ end
265
+
266
+ describe '#perceptual_inference_stats' do
267
+ it 'returns success: true' do
268
+ result = client.perceptual_inference_stats
269
+ expect(result[:success]).to be true
270
+ end
271
+
272
+ it 'returns stats hash' do
273
+ result = client.perceptual_inference_stats
274
+ expect(result[:stats]).to be_a(Hash)
275
+ end
276
+
277
+ it 'includes hypotheses_total in stats' do
278
+ client.register_percept_hypothesis(content: 'cat', modality: :visual)
279
+ result = client.perceptual_inference_stats
280
+ expect(result[:stats][:hypotheses_total]).to eq(1)
281
+ end
282
+
283
+ it 'includes ambiguity_level in stats' do
284
+ result = client.perceptual_inference_stats
285
+ expect(result[:stats]).to have_key(:ambiguity_level)
286
+ end
287
+ end
288
+
289
+ describe 'integration: hypothesis lifecycle' do
290
+ it 'registers, presents evidence, selects, and adapts priors' do
291
+ reg_one = client.register_percept_hypothesis(content: 'bright cube', modality: :visual, prior: 0.95)
292
+ reg_two = client.register_percept_hypothesis(content: 'dark sphere', modality: :visual, prior: 0.1)
293
+
294
+ client.present_perceptual_evidence(modality: :visual, content: 'bright cube', strength: 0.99)
295
+ selection = client.select_percept(modality: :visual)
296
+ expect(selection[:selected]).to be true
297
+
298
+ client.adapt_perception(modality: :visual, correct_hypothesis_id: reg_one[:hypothesis_id])
299
+
300
+ stats = client.perceptual_inference_stats
301
+ expect(stats[:stats][:hypotheses_total]).to eq(2)
302
+ _ = reg_two
303
+ end
304
+ end
305
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Stub the base class before loading the actor
4
+ module Legion
5
+ module Extensions
6
+ module Actors
7
+ class Every; end # rubocop:disable Lint/EmptyClass
8
+ end
9
+ end
10
+ end
11
+
12
+ $LOADED_FEATURES << 'legion/extensions/actors/every'
13
+
14
+ require_relative '../../../../../../../lib/legion/extensions/agentic/inference/prediction/actors/expire_predictions'
15
+
16
+ RSpec.describe Legion::Extensions::Agentic::Inference::Prediction::Actor::ExpirePredictions do
17
+ subject(:actor) { described_class.new }
18
+
19
+ describe '#runner_class' do
20
+ it { expect(actor.runner_class).to eq Legion::Extensions::Agentic::Inference::Prediction::Runners::Prediction }
21
+ end
22
+
23
+ describe '#runner_function' do
24
+ it { expect(actor.runner_function).to eq 'expire_stale_predictions' }
25
+ end
26
+
27
+ describe '#time' do
28
+ it { expect(actor.time).to eq 300 }
29
+ end
30
+
31
+ describe '#run_now?' do
32
+ it { expect(actor.run_now?).to be false }
33
+ end
34
+
35
+ describe '#use_runner?' do
36
+ it { expect(actor.use_runner?).to be false }
37
+ end
38
+
39
+ describe '#check_subtask?' do
40
+ it { expect(actor.check_subtask?).to be false }
41
+ end
42
+
43
+ describe '#generate_task?' do
44
+ it { expect(actor.generate_task?).to be false }
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/agentic/inference/prediction/client'
4
+
5
+ RSpec.describe Legion::Extensions::Agentic::Inference::Prediction::Client do
6
+ it 'responds to prediction runner methods' do
7
+ client = described_class.new
8
+ expect(client).to respond_to(:predict)
9
+ expect(client).to respond_to(:resolve_prediction)
10
+ expect(client).to respond_to(:pending_predictions)
11
+ expect(client).to respond_to(:prediction_accuracy)
12
+ expect(client).to respond_to(:get_prediction)
13
+ end
14
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Legion::Extensions::Agentic::Inference::Prediction::Helpers::Modes do
6
+ describe 'REASONING_MODES' do
7
+ it 'is a frozen array of symbols' do
8
+ expect(described_class::REASONING_MODES).to be_a(Array)
9
+ expect(described_class::REASONING_MODES).to be_frozen
10
+ end
11
+
12
+ it 'contains exactly four modes' do
13
+ expect(described_class::REASONING_MODES.size).to eq(4)
14
+ end
15
+
16
+ it 'includes fault_localization' do
17
+ expect(described_class::REASONING_MODES).to include(:fault_localization)
18
+ end
19
+
20
+ it 'includes functional_mapping' do
21
+ expect(described_class::REASONING_MODES).to include(:functional_mapping)
22
+ end
23
+
24
+ it 'includes boundary_testing' do
25
+ expect(described_class::REASONING_MODES).to include(:boundary_testing)
26
+ end
27
+
28
+ it 'includes counterfactual' do
29
+ expect(described_class::REASONING_MODES).to include(:counterfactual)
30
+ end
31
+
32
+ it 'contains only symbols' do
33
+ expect(described_class::REASONING_MODES).to all(be_a(Symbol))
34
+ end
35
+ end
36
+
37
+ describe 'PREDICTION_CONFIDENCE_MIN' do
38
+ it 'is 0.65' do
39
+ expect(described_class::PREDICTION_CONFIDENCE_MIN).to eq(0.65)
40
+ end
41
+
42
+ it 'is a float' do
43
+ expect(described_class::PREDICTION_CONFIDENCE_MIN).to be_a(Float)
44
+ end
45
+
46
+ it 'is in the valid 0.0-1.0 range' do
47
+ expect(described_class::PREDICTION_CONFIDENCE_MIN).to be_between(0.0, 1.0)
48
+ end
49
+ end
50
+
51
+ describe 'MAX_PREDICTIONS_PER_TICK' do
52
+ it 'is 5' do
53
+ expect(described_class::MAX_PREDICTIONS_PER_TICK).to eq(5)
54
+ end
55
+
56
+ it 'is an integer' do
57
+ expect(described_class::MAX_PREDICTIONS_PER_TICK).to be_an(Integer)
58
+ end
59
+
60
+ it 'is positive' do
61
+ expect(described_class::MAX_PREDICTIONS_PER_TICK).to be > 0
62
+ end
63
+ end
64
+
65
+ describe 'PREDICTION_HORIZON' do
66
+ it 'is 3600' do
67
+ expect(described_class::PREDICTION_HORIZON).to eq(3600)
68
+ end
69
+
70
+ it 'is an integer' do
71
+ expect(described_class::PREDICTION_HORIZON).to be_an(Integer)
72
+ end
73
+
74
+ it 'represents one hour in seconds' do
75
+ expect(described_class::PREDICTION_HORIZON).to eq(60 * 60)
76
+ end
77
+ end
78
+
79
+ describe '.valid_mode?' do
80
+ it 'returns true for fault_localization' do
81
+ expect(described_class.valid_mode?(:fault_localization)).to be true
82
+ end
83
+
84
+ it 'returns true for functional_mapping' do
85
+ expect(described_class.valid_mode?(:functional_mapping)).to be true
86
+ end
87
+
88
+ it 'returns true for boundary_testing' do
89
+ expect(described_class.valid_mode?(:boundary_testing)).to be true
90
+ end
91
+
92
+ it 'returns true for counterfactual' do
93
+ expect(described_class.valid_mode?(:counterfactual)).to be true
94
+ end
95
+
96
+ it 'returns false for an unknown mode symbol' do
97
+ expect(described_class.valid_mode?(:neural_network)).to be false
98
+ end
99
+
100
+ it 'returns false for a string form of a valid mode' do
101
+ expect(described_class.valid_mode?('fault_localization')).to be false
102
+ end
103
+
104
+ it 'returns false for nil' do
105
+ expect(described_class.valid_mode?(nil)).to be false
106
+ end
107
+
108
+ it 'returns false for an integer' do
109
+ expect(described_class.valid_mode?(42)).to be false
110
+ end
111
+
112
+ it 'returns true for all REASONING_MODES members' do
113
+ described_class::REASONING_MODES.each do |mode|
114
+ expect(described_class.valid_mode?(mode)).to be true
115
+ end
116
+ end
117
+ end
118
+ end