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,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module Debugging
8
+ module Helpers
9
+ class DebuggingEngine
10
+ attr_reader :errors, :traces, :corrections
11
+
12
+ def initialize
13
+ @errors = {}
14
+ @traces = {}
15
+ @corrections = {}
16
+ end
17
+
18
+ def detect_error(error_type:, description:, severity:, source_phase:, confidence_at_detection:)
19
+ return nil unless Constants::ERROR_TYPES.include?(error_type)
20
+ return nil if @errors.size >= Constants::MAX_ERRORS
21
+
22
+ err = ReasoningError.new(
23
+ error_type: error_type,
24
+ description: description,
25
+ severity: severity,
26
+ source_phase: source_phase,
27
+ confidence_at_detection: confidence_at_detection
28
+ )
29
+ @errors[err.id] = err
30
+ err
31
+ end
32
+
33
+ def trace_error(error_id:, steps:, root_cause:, confidence:)
34
+ err = @errors[error_id]
35
+ return nil unless err
36
+ return nil if @traces.size >= Constants::MAX_TRACES
37
+
38
+ trace = CausalTrace.new(error_id: error_id, root_cause: root_cause, confidence: confidence)
39
+ steps.each { |s| trace.add_step!(phase: s.fetch(:phase), description: s.fetch(:description)) }
40
+ @traces[trace.id] = trace
41
+ err.trace!(trace.id)
42
+ trace
43
+ end
44
+
45
+ def propose_correction(error_id:, strategy:, description:)
46
+ err = @errors[error_id]
47
+ return nil unless err
48
+ return nil unless Constants::CORRECTION_STRATEGIES.include?(strategy)
49
+ return nil if @corrections.size >= Constants::MAX_CORRECTIONS
50
+
51
+ correction = Correction.new(error_id: error_id, strategy: strategy, description: description)
52
+ @corrections[correction.id] = correction
53
+ err.correct!(correction.id)
54
+ correction
55
+ end
56
+
57
+ def apply_correction(correction_id:)
58
+ correction = @corrections[correction_id]
59
+ return nil unless correction
60
+
61
+ correction.apply!
62
+ end
63
+
64
+ def measure_correction(correction_id:, effectiveness:)
65
+ correction = @corrections[correction_id]
66
+ return nil unless correction
67
+
68
+ correction.measure_effectiveness!(effectiveness)
69
+ end
70
+
71
+ def resolve_error(error_id:)
72
+ err = @errors[error_id]
73
+ return nil unless err
74
+
75
+ err.resolve!
76
+ end
77
+
78
+ def active_errors
79
+ @errors.values.select(&:active?)
80
+ end
81
+
82
+ def resolved_errors
83
+ @errors.values.select(&:resolved?)
84
+ end
85
+
86
+ def errors_by_type
87
+ @errors.values.group_by(&:error_type).transform_values(&:length)
88
+ end
89
+
90
+ def errors_by_phase
91
+ @errors.values.group_by(&:source_phase).transform_values(&:length)
92
+ end
93
+
94
+ def most_common_error_type
95
+ tally = errors_by_type
96
+ return nil if tally.empty?
97
+
98
+ tally.max_by { |_, count| count }&.first
99
+ end
100
+
101
+ def most_effective_strategy
102
+ applied = @corrections.values.reject { |c| c.effectiveness.nil? }
103
+ return nil if applied.empty?
104
+
105
+ by_strategy = applied.group_by(&:strategy)
106
+ best = by_strategy.max_by do |_, list|
107
+ scores = list.map(&:effectiveness)
108
+ scores.sum.round(10) / scores.size
109
+ end
110
+ best&.first
111
+ end
112
+
113
+ def error_rate_by_phase
114
+ errors_by_phase
115
+ end
116
+
117
+ def correction_success_rate
118
+ applied = @corrections.values.select(&:applied)
119
+ return 0.0 if applied.empty?
120
+
121
+ measured = applied.reject { |c| c.effectiveness.nil? }
122
+ return 0.0 if measured.empty?
123
+
124
+ effective_count = measured.count(&:effective?)
125
+ (effective_count.to_f / measured.size).round(10)
126
+ end
127
+
128
+ def debugging_report
129
+ {
130
+ total_errors: @errors.size,
131
+ active_errors: active_errors.size,
132
+ resolved_errors: resolved_errors.size,
133
+ total_traces: @traces.size,
134
+ total_corrections: @corrections.size,
135
+ correction_success_rate: correction_success_rate,
136
+ most_common_error_type: most_common_error_type,
137
+ most_effective_strategy: most_effective_strategy,
138
+ errors_by_type: errors_by_type,
139
+ error_rate_by_phase: error_rate_by_phase
140
+ }
141
+ end
142
+
143
+ def to_h
144
+ {
145
+ errors: @errors.transform_values(&:to_h),
146
+ traces: @traces.transform_values(&:to_h),
147
+ corrections: @corrections.transform_values(&:to_h)
148
+ }
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Agentic
8
+ module Inference
9
+ module Debugging
10
+ module Helpers
11
+ class ReasoningError
12
+ attr_reader :id, :error_type, :description, :severity, :source_phase,
13
+ :confidence_at_detection, :trace_ids, :correction_ids,
14
+ :created_at, :resolved_at, :status
15
+
16
+ def initialize(error_type:, description:, severity:, source_phase:, confidence_at_detection:)
17
+ @id = SecureRandom.uuid
18
+ @error_type = error_type
19
+ @description = description
20
+ @severity = severity.clamp(0.0, 1.0).round(10)
21
+ @source_phase = source_phase
22
+ @confidence_at_detection = confidence_at_detection.clamp(0.0, 1.0).round(10)
23
+ @status = :detected
24
+ @trace_ids = []
25
+ @correction_ids = []
26
+ @created_at = Time.now.utc
27
+ @resolved_at = nil
28
+ end
29
+
30
+ def detect!
31
+ @status = :detected
32
+ self
33
+ end
34
+
35
+ def trace!(trace_id)
36
+ @trace_ids << trace_id
37
+ @status = :traced
38
+ self
39
+ end
40
+
41
+ def correct!(correction_id)
42
+ @correction_ids << correction_id
43
+ @status = :correcting
44
+ self
45
+ end
46
+
47
+ def resolve!
48
+ @status = :resolved
49
+ @resolved_at = Time.now.utc
50
+ self
51
+ end
52
+
53
+ def mark_unresolvable!
54
+ @status = :unresolvable
55
+ @resolved_at = Time.now.utc
56
+ self
57
+ end
58
+
59
+ def severe?
60
+ @severity >= 0.7
61
+ end
62
+
63
+ def resolved?
64
+ @status == :resolved
65
+ end
66
+
67
+ def active?
68
+ !%i[resolved unresolvable].include?(@status)
69
+ end
70
+
71
+ def severity_label
72
+ Constants.severity_label(@severity)
73
+ end
74
+
75
+ def to_h
76
+ {
77
+ id: @id,
78
+ error_type: @error_type,
79
+ description: @description,
80
+ severity: @severity,
81
+ severity_label: severity_label,
82
+ source_phase: @source_phase,
83
+ confidence_at_detection: @confidence_at_detection,
84
+ status: @status,
85
+ trace_ids: @trace_ids.dup,
86
+ correction_ids: @correction_ids.dup,
87
+ created_at: @created_at,
88
+ resolved_at: @resolved_at
89
+ }
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module Debugging
8
+ module Runners
9
+ module CognitiveDebugging
10
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
11
+ Legion::Extensions::Helpers.const_defined?(:Lex)
12
+
13
+ def detect_error(error_type:, description:, severity:, source_phase:, confidence_at_detection: 0.5, **)
14
+ unless Helpers::Constants::ERROR_TYPES.include?(error_type)
15
+ Legion::Logging.debug "[cognitive_debugging] detect_error: invalid error_type=#{error_type}"
16
+ return { success: false, error: :invalid_error_type, valid: Helpers::Constants::ERROR_TYPES }
17
+ end
18
+
19
+ err = engine.detect_error(
20
+ error_type: error_type,
21
+ description: description,
22
+ severity: severity,
23
+ source_phase: source_phase,
24
+ confidence_at_detection: confidence_at_detection
25
+ )
26
+
27
+ if err
28
+ Legion::Logging.info "[cognitive_debugging] error detected: id=#{err.id[0..7]} type=#{error_type} " \
29
+ "phase=#{source_phase} severity=#{err.severity_label}"
30
+ { success: true, error_id: err.id, error_type: error_type, severity_label: err.severity_label }
31
+ else
32
+ Legion::Logging.warn '[cognitive_debugging] detect_error: engine returned nil (cap reached?)'
33
+ { success: false, error: :cap_reached }
34
+ end
35
+ end
36
+
37
+ def trace_error(error_id:, steps:, root_cause:, confidence: 0.5, **)
38
+ trace = engine.trace_error(
39
+ error_id: error_id,
40
+ steps: steps,
41
+ root_cause: root_cause,
42
+ confidence: confidence
43
+ )
44
+
45
+ if trace
46
+ Legion::Logging.info "[cognitive_debugging] error traced: error_id=#{error_id[0..7]} " \
47
+ "trace_id=#{trace.id[0..7]} depth=#{trace.depth} root_cause=#{root_cause}"
48
+ { success: true, trace_id: trace.id, depth: trace.depth, root_cause: root_cause }
49
+ else
50
+ Legion::Logging.debug "[cognitive_debugging] trace_error: error_id=#{error_id[0..7]} not found or cap"
51
+ { success: false, error: :not_found_or_cap }
52
+ end
53
+ end
54
+
55
+ def propose_correction(error_id:, strategy:, description:, **)
56
+ unless Helpers::Constants::CORRECTION_STRATEGIES.include?(strategy)
57
+ Legion::Logging.debug "[cognitive_debugging] propose_correction: invalid strategy=#{strategy}"
58
+ return { success: false, error: :invalid_strategy, valid: Helpers::Constants::CORRECTION_STRATEGIES }
59
+ end
60
+
61
+ correction = engine.propose_correction(error_id: error_id, strategy: strategy, description: description)
62
+
63
+ if correction
64
+ Legion::Logging.info "[cognitive_debugging] correction proposed: error_id=#{error_id[0..7]} " \
65
+ "correction_id=#{correction.id[0..7]} strategy=#{strategy}"
66
+ { success: true, correction_id: correction.id, strategy: strategy }
67
+ else
68
+ Legion::Logging.debug "[cognitive_debugging] propose_correction: error_id=#{error_id[0..7]} not found"
69
+ { success: false, error: :not_found }
70
+ end
71
+ end
72
+
73
+ def apply_correction(correction_id:, **)
74
+ correction = engine.apply_correction(correction_id: correction_id)
75
+
76
+ if correction
77
+ Legion::Logging.info "[cognitive_debugging] correction applied: id=#{correction_id[0..7]}"
78
+ { success: true, correction_id: correction_id, applied: true }
79
+ else
80
+ Legion::Logging.debug "[cognitive_debugging] apply_correction: id=#{correction_id[0..7]} not found"
81
+ { success: false, error: :not_found }
82
+ end
83
+ end
84
+
85
+ def measure_correction(correction_id:, effectiveness:, **)
86
+ correction = engine.measure_correction(correction_id: correction_id, effectiveness: effectiveness)
87
+
88
+ if correction
89
+ Legion::Logging.info "[cognitive_debugging] correction measured: id=#{correction_id[0..7]} " \
90
+ "effectiveness=#{correction.effectiveness} effective=#{correction.effective?}"
91
+ { success: true, correction_id: correction_id, effectiveness: correction.effectiveness,
92
+ effective: correction.effective? }
93
+ else
94
+ Legion::Logging.debug "[cognitive_debugging] measure_correction: id=#{correction_id[0..7]} not found"
95
+ { success: false, error: :not_found }
96
+ end
97
+ end
98
+
99
+ def resolve_error(error_id:, **)
100
+ err = engine.resolve_error(error_id: error_id)
101
+
102
+ if err
103
+ Legion::Logging.info "[cognitive_debugging] error resolved: id=#{error_id[0..7]}"
104
+ { success: true, error_id: error_id, resolved: true }
105
+ else
106
+ Legion::Logging.debug "[cognitive_debugging] resolve_error: id=#{error_id[0..7]} not found"
107
+ { success: false, error: :not_found }
108
+ end
109
+ end
110
+
111
+ def active_errors(**)
112
+ errors = engine.active_errors
113
+ Legion::Logging.debug "[cognitive_debugging] active_errors: count=#{errors.size}"
114
+ { success: true, errors: errors.map(&:to_h), count: errors.size }
115
+ end
116
+
117
+ def resolved_errors(**)
118
+ errors = engine.resolved_errors
119
+ Legion::Logging.debug "[cognitive_debugging] resolved_errors: count=#{errors.size}"
120
+ { success: true, errors: errors.map(&:to_h), count: errors.size }
121
+ end
122
+
123
+ def errors_by_type(**)
124
+ tally = engine.errors_by_type
125
+ Legion::Logging.debug "[cognitive_debugging] errors_by_type: types=#{tally.keys.join(',')}"
126
+ { success: true, tally: tally }
127
+ end
128
+
129
+ def errors_by_phase(**)
130
+ tally = engine.errors_by_phase
131
+ Legion::Logging.debug "[cognitive_debugging] errors_by_phase: phases=#{tally.keys.join(',')}"
132
+ { success: true, tally: tally }
133
+ end
134
+
135
+ def most_common_error_type(**)
136
+ type = engine.most_common_error_type
137
+ Legion::Logging.debug "[cognitive_debugging] most_common_error_type: type=#{type}"
138
+ { success: true, error_type: type }
139
+ end
140
+
141
+ def most_effective_strategy(**)
142
+ strategy = engine.most_effective_strategy
143
+ Legion::Logging.debug "[cognitive_debugging] most_effective_strategy: strategy=#{strategy}"
144
+ { success: true, strategy: strategy }
145
+ end
146
+
147
+ def correction_success_rate(**)
148
+ rate = engine.correction_success_rate
149
+ Legion::Logging.debug "[cognitive_debugging] correction_success_rate: rate=#{rate}"
150
+ { success: true, rate: rate }
151
+ end
152
+
153
+ def debugging_report(**)
154
+ report = engine.debugging_report
155
+ Legion::Logging.info "[cognitive_debugging] debugging_report: total_errors=#{report[:total_errors]} " \
156
+ "active=#{report[:active_errors]}"
157
+ { success: true, report: report }
158
+ end
159
+
160
+ def snapshot(**)
161
+ data = engine.to_h
162
+ Legion::Logging.debug "[cognitive_debugging] snapshot: errors=#{data[:errors].size} " \
163
+ "traces=#{data[:traces].size} corrections=#{data[:corrections].size}"
164
+ { success: true, snapshot: data }
165
+ end
166
+
167
+ private
168
+
169
+ def engine
170
+ @engine ||= Helpers::DebuggingEngine.new
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module Debugging
8
+ VERSION = '0.1.0'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/agentic/inference/debugging/version'
4
+ require 'legion/extensions/agentic/inference/debugging/helpers/constants'
5
+ require 'legion/extensions/agentic/inference/debugging/helpers/reasoning_error'
6
+ require 'legion/extensions/agentic/inference/debugging/helpers/causal_trace'
7
+ require 'legion/extensions/agentic/inference/debugging/helpers/correction'
8
+ require 'legion/extensions/agentic/inference/debugging/helpers/debugging_engine'
9
+ require 'legion/extensions/agentic/inference/debugging/runners/cognitive_debugging'
10
+ require 'legion/extensions/agentic/inference/debugging/client'
11
+
12
+ module Legion
13
+ module Extensions
14
+ module Agentic
15
+ module Inference
16
+ module Debugging
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop'
4
+ require 'legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine'
5
+ require 'legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition'
6
+
7
+ module Legion
8
+ module Extensions
9
+ module Agentic
10
+ module Inference
11
+ module EnactiveCognition
12
+ class Client
13
+ include Runners::EnactiveCognition
14
+
15
+ def initialize(**)
16
+ @enaction_engine = Helpers::EnactionEngine.new
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :enaction_engine
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module EnactiveCognition
8
+ module Helpers
9
+ class EnactionEngine
10
+ attr_reader :couplings
11
+
12
+ def initialize
13
+ @couplings = {}
14
+ end
15
+
16
+ def create_coupling(action:, perception:, domain:, loop_type: :sensorimotor)
17
+ prune_to_limit
18
+
19
+ loop = SensorimotorLoop.new(
20
+ action: action,
21
+ perception: perception,
22
+ domain: domain,
23
+ loop_type: loop_type
24
+ )
25
+ @couplings[loop.id] = loop
26
+ loop
27
+ end
28
+
29
+ def execute_action(coupling_id:, actual_perception:)
30
+ loop = @couplings[coupling_id]
31
+ return { success: false, reason: :not_found } unless loop
32
+
33
+ result = loop.execute!(actual_perception: actual_perception)
34
+ {
35
+ success: true,
36
+ coupling_id: coupling_id,
37
+ match: result[:match],
38
+ coupling_strength: result[:coupling_strength],
39
+ prediction_accuracy: result[:prediction_accuracy],
40
+ coupling_label: loop.coupling_label
41
+ }
42
+ end
43
+
44
+ def adapt_coupling(coupling_id:, new_perception:)
45
+ loop = @couplings[coupling_id]
46
+ return { success: false, reason: :not_found } unless loop
47
+
48
+ loop.adapt_perception!(new_perception: new_perception)
49
+ { success: true, coupling_id: coupling_id, new_perception: new_perception }
50
+ end
51
+
52
+ def find_action_for(perception:)
53
+ best = @couplings.values
54
+ .select(&:coupled?)
55
+ .select { |lp| lp.perception.to_s == perception.to_s }
56
+ .max_by(&:coupling_strength)
57
+ return nil unless best
58
+
59
+ best
60
+ end
61
+
62
+ def coupled_loops
63
+ @couplings.values.select(&:coupled?)
64
+ end
65
+
66
+ def by_domain(domain:)
67
+ @couplings.values.select { |lp| lp.domain.to_s == domain.to_s }
68
+ end
69
+
70
+ def by_type(loop_type:)
71
+ @couplings.values.select { |lp| lp.loop_type == loop_type }
72
+ end
73
+
74
+ def strongest_couplings(limit: 5)
75
+ @couplings.values.sort_by { |lp| -lp.coupling_strength }.first(limit)
76
+ end
77
+
78
+ def overall_coupling
79
+ return 0.0 if @couplings.empty?
80
+
81
+ total = @couplings.values.sum(&:coupling_strength)
82
+ total / @couplings.size
83
+ end
84
+
85
+ def decay_all
86
+ @couplings.each_value(&:decay!)
87
+ end
88
+
89
+ def prune_decoupled
90
+ @couplings.delete_if { |_id, lp| lp.coupling_strength < SensorimotorLoop::COUPLING_FLOOR + 0.05 }
91
+ end
92
+
93
+ def count
94
+ @couplings.size
95
+ end
96
+
97
+ def to_h
98
+ {
99
+ coupling_count: @couplings.size,
100
+ coupled_count: coupled_loops.size,
101
+ overall_coupling: overall_coupling.round(4),
102
+ strongest: strongest_couplings(limit: 3).map(&:to_h)
103
+ }
104
+ end
105
+
106
+ private
107
+
108
+ def prune_to_limit
109
+ return unless @couplings.size >= SensorimotorLoop::MAX_COUPLINGS
110
+
111
+ weakest = @couplings.values.sort_by(&:coupling_strength).first(10)
112
+ weakest.each { |lp| @couplings.delete(lp.id) }
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end