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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/lex-agentic-inference.gemspec +30 -0
- data/lib/legion/extensions/agentic/inference/abductive/client.rb +25 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/abduction_engine.rb +164 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/constants.rb +39 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/hypothesis.rb +106 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/observation.rb +39 -0
- data/lib/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning.rb +129 -0
- data/lib/legion/extensions/agentic/inference/abductive/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/abductive.rb +20 -0
- data/lib/legion/extensions/agentic/inference/affordance/actors/scan.rb +31 -0
- data/lib/legion/extensions/agentic/inference/affordance/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb +123 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb +75 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/inference/affordance/runners/affordance.rb +90 -0
- data/lib/legion/extensions/agentic/inference/affordance/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/affordance.rb +19 -0
- data/lib/legion/extensions/agentic/inference/analogical/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/analogy_engine.rb +209 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/constants.rb +38 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/structure_map.rb +113 -0
- data/lib/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning.rb +106 -0
- data/lib/legion/extensions/agentic/inference/analogical/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/analogical.rb +19 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb +102 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine.rb +131 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping.rb +78 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping.rb +19 -0
- data/lib/legion/extensions/agentic/inference/bayesian/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief.rb +96 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief_network.rb +147 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/constants.rb +36 -0
- data/lib/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief.rb +125 -0
- data/lib/legion/extensions/agentic/inference/bayesian/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/bayesian.rb +19 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief.rb +155 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief_network.rb +193 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/constants.rb +54 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/evidence.rb +49 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb +89 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/belief_revision.rb +21 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb +92 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine.rb +159 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution.rb +111 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution.rb +18 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/client.rb +24 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge.rb +101 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph.rb +184 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning.rb +111 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning.rb +19 -0
- data/lib/legion/extensions/agentic/inference/coherence/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/coherence_engine.rb +170 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/proposition.rb +100 -0
- data/lib/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence.rb +123 -0
- data/lib/legion/extensions/agentic/inference/coherence/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/coherence.rb +19 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine.rb +157 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb +98 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/runners/counterfactual.rb +106 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/counterfactual.rb +19 -0
- data/lib/legion/extensions/agentic/inference/debugging/client.rb +30 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb +51 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/correction.rb +56 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/debugging_engine.rb +156 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/reasoning_error.rb +97 -0
- data/lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb +178 -0
- data/lib/legion/extensions/agentic/inference/debugging/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/debugging.rb +21 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb +120 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop.rb +122 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb +124 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition.rb +18 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/constants.rb +47 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/expectation.rb +82 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine.rb +126 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb +76 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation.rb +19 -0
- data/lib/legion/extensions/agentic/inference/free_energy/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/belief.rb +127 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine.rb +156 -0
- data/lib/legion/extensions/agentic/inference/free_energy/runners/free_energy.rb +97 -0
- data/lib/legion/extensions/agentic/inference/free_energy/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/free_energy.rb +19 -0
- data/lib/legion/extensions/agentic/inference/gravity/client.rb +29 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb +77 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/constants.rb +76 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb +164 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb +64 -0
- data/lib/legion/extensions/agentic/inference/gravity/runners/gravity.rb +132 -0
- data/lib/legion/extensions/agentic/inference/gravity/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/gravity.rb +20 -0
- data/lib/legion/extensions/agentic/inference/horizon/actors/adjust.rb +45 -0
- data/lib/legion/extensions/agentic/inference/horizon/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/constants.rb +43 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb +110 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/projection.rb +59 -0
- data/lib/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon.rb +107 -0
- data/lib/legion/extensions/agentic/inference/horizon/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/horizon.rb +19 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants.rb +37 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb +83 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine.rb +97 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb +115 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/intuition/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/constants.rb +60 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb +66 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb +157 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/pattern.rb +105 -0
- data/lib/legion/extensions/agentic/inference/intuition/runners/intuition.rb +87 -0
- data/lib/legion/extensions/agentic/inference/intuition/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/intuition.rb +20 -0
- data/lib/legion/extensions/agentic/inference/magnet/client.rb +29 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/constants.rb +57 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/field.rb +105 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/magnet_engine.rb +179 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb +80 -0
- data/lib/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet.rb +124 -0
- data/lib/legion/extensions/agentic/inference/magnet/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/magnet.rb +21 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb +112 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb +127 -0
- data/lib/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum.rb +101 -0
- data/lib/legion/extensions/agentic/inference/momentum/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/momentum.rb +19 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field.rb +154 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb +100 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb +120 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference.rb +19 -0
- data/lib/legion/extensions/agentic/inference/prediction/actors/expire_predictions.rb +45 -0
- data/lib/legion/extensions/agentic/inference/prediction/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/prediction/helpers/modes.rb +28 -0
- data/lib/legion/extensions/agentic/inference/prediction/helpers/prediction_store.rb +66 -0
- data/lib/legion/extensions/agentic/inference/prediction/runners/prediction.rb +146 -0
- data/lib/legion/extensions/agentic/inference/prediction/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/prediction.rb +18 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model.rb +187 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb +59 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding.rb +171 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding.rb +20 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model.rb +142 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor.rb +129 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb +104 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb +98 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/constants.rb +41 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine.rb +104 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/runners/reality_testing.rb +94 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/reality_testing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/schema/client.rb +26 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb +70 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/constants.rb +50 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/world_model.rb +173 -0
- data/lib/legion/extensions/agentic/inference/schema/runners/schema.rb +101 -0
- data/lib/legion/extensions/agentic/inference/schema/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/schema.rb +19 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb +66 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine.rb +139 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb +129 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance.rb +19 -0
- data/lib/legion/extensions/agentic/inference/version.rb +11 -0
- data/lib/legion/extensions/agentic/inference.rb +44 -0
- data/spec/legion/extensions/agentic/inference/abductive/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning_spec.rb +349 -0
- data/spec/legion/extensions/agentic/inference/affordance/client_spec.rb +26 -0
- data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_field_spec.rb +131 -0
- data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_item_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/affordance/runners/affordance_spec.rb +78 -0
- data/spec/legion/extensions/agentic/inference/analogical/client_spec.rb +31 -0
- data/spec/legion/extensions/agentic/inference/analogical/helpers/analogy_engine_spec.rb +276 -0
- data/spec/legion/extensions/agentic/inference/analogical/helpers/structure_map_spec.rb +255 -0
- data/spec/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning_spec.rb +213 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine_spec.rb +218 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_spec.rb +231 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping_spec.rb +171 -0
- data/spec/legion/extensions/agentic/inference/bayesian/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_network_spec.rb +178 -0
- data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_spec.rb +137 -0
- data/spec/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief_spec.rb +176 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/client_spec.rb +31 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_network_spec.rb +176 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_spec.rb +153 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/evidence_spec.rb +51 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/runners/belief_revision_spec.rb +106 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine_spec.rb +181 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_spec.rb +108 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution_spec.rb +142 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/client_spec.rb +35 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge_spec.rb +158 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph_spec.rb +259 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning_spec.rb +161 -0
- data/spec/legion/extensions/agentic/inference/coherence/client_spec.rb +17 -0
- data/spec/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence_spec.rb +267 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/client_spec.rb +48 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/constants_spec.rb +55 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine_spec.rb +234 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/scenario_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/runners/counterfactual_spec.rb +179 -0
- data/spec/legion/extensions/agentic/inference/debugging/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/causal_trace_spec.rb +84 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/constants_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/correction_spec.rb +98 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/debugging_engine_spec.rb +290 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/reasoning_error_spec.rb +164 -0
- data/spec/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging_spec.rb +301 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/client_spec.rb +19 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine_spec.rb +181 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop_spec.rb +184 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition_spec.rb +214 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/expectation_violation_spec.rb +11 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/expectation_spec.rb +102 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine_spec.rb +121 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation_spec.rb +59 -0
- data/spec/legion/extensions/agentic/inference/free_energy/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/free_energy/helpers/belief_spec.rb +183 -0
- data/spec/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine_spec.rb +211 -0
- data/spec/legion/extensions/agentic/inference/free_energy/runners/free_energy_spec.rb +118 -0
- data/spec/legion/extensions/agentic/inference/gravity/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/attractor_spec.rb +143 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/constants_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/gravity_engine_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought_spec.rb +103 -0
- data/spec/legion/extensions/agentic/inference/gravity/runners/gravity_spec.rb +159 -0
- data/spec/legion/extensions/agentic/inference/horizon/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/constants_spec.rb +98 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/horizon_engine_spec.rb +325 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/projection_spec.rb +155 -0
- data/spec/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon_spec.rb +269 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants_spec.rb +38 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine_spec.rb +182 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_spec.rb +172 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/hypothesis_testing_spec.rb +16 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing_spec.rb +159 -0
- data/spec/legion/extensions/agentic/inference/intuition/client_spec.rb +33 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/heuristic_spec.rb +82 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/intuition_engine_spec.rb +163 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/pattern_spec.rb +160 -0
- data/spec/legion/extensions/agentic/inference/intuition/runners/intuition_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/magnet/client_spec.rb +30 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/constants_spec.rb +120 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/field_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/magnet_engine_spec.rb +281 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/pole_spec.rb +211 -0
- data/spec/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet_spec.rb +201 -0
- data/spec/legion/extensions/agentic/inference/momentum/cognitive_momentum_spec.rb +11 -0
- data/spec/legion/extensions/agentic/inference/momentum/helpers/idea_spec.rb +152 -0
- data/spec/legion/extensions/agentic/inference/momentum/helpers/momentum_engine_spec.rb +154 -0
- data/spec/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/client_spec.rb +39 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/constants_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field_spec.rb +270 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis_spec.rb +206 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference_spec.rb +305 -0
- data/spec/legion/extensions/agentic/inference/prediction/actors/expire_predictions_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/prediction/client_spec.rb +14 -0
- data/spec/legion/extensions/agentic/inference/prediction/helpers/modes_spec.rb +118 -0
- data/spec/legion/extensions/agentic/inference/prediction/helpers/prediction_store_spec.rb +262 -0
- data/spec/legion/extensions/agentic/inference/prediction/runners/prediction_spec.rb +116 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/client_spec.rb +74 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model_spec.rb +194 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error_spec.rb +109 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding_spec.rb +210 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/client_spec.rb +82 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model_spec.rb +220 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor_spec.rb +206 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing_spec.rb +213 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/client_spec.rb +29 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/belief_spec.rb +197 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/constants_spec.rb +78 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine_spec.rb +191 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/runners/reality_testing_spec.rb +154 -0
- data/spec/legion/extensions/agentic/inference/schema/client_spec.rb +53 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/causal_relation_spec.rb +108 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/constants_spec.rb +54 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/world_model_spec.rb +179 -0
- data/spec/legion/extensions/agentic/inference/schema/runners/schema_spec.rb +146 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants_spec.rb +62 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision_spec.rb +125 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine_spec.rb +184 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance_spec.rb +157 -0
- data/spec/spec_helper.rb +46 -0
- metadata +412 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Counterfactual::Helpers::Scenario do
|
|
4
|
+
let(:base_params) do
|
|
5
|
+
{
|
|
6
|
+
scenario_type: :upward,
|
|
7
|
+
mutation_type: :action,
|
|
8
|
+
actual_outcome: 'project failed',
|
|
9
|
+
counterfactual_outcome: 'project succeeded',
|
|
10
|
+
antecedent: 'had reviewed code',
|
|
11
|
+
domain: :engineering,
|
|
12
|
+
plausibility: 0.8,
|
|
13
|
+
regret_magnitude: 0.6
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
subject(:scenario) { described_class.new(**base_params) }
|
|
18
|
+
|
|
19
|
+
describe '#initialize' do
|
|
20
|
+
it 'assigns a UUID id' do
|
|
21
|
+
expect(scenario.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'assigns scenario_type' do
|
|
25
|
+
expect(scenario.scenario_type).to eq(:upward)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'assigns mutation_type' do
|
|
29
|
+
expect(scenario.mutation_type).to eq(:action)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'assigns actual_outcome' do
|
|
33
|
+
expect(scenario.actual_outcome).to eq('project failed')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'assigns counterfactual_outcome' do
|
|
37
|
+
expect(scenario.counterfactual_outcome).to eq('project succeeded')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'assigns antecedent' do
|
|
41
|
+
expect(scenario.antecedent).to eq('had reviewed code')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'assigns domain' do
|
|
45
|
+
expect(scenario.domain).to eq(:engineering)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'clamps plausibility to [0, 1]' do
|
|
49
|
+
s = described_class.new(**base_params, plausibility: 1.5)
|
|
50
|
+
expect(s.plausibility).to eq(1.0)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'clamps regret_magnitude to [0, 1]' do
|
|
54
|
+
s = described_class.new(**base_params, regret_magnitude: -0.5)
|
|
55
|
+
expect(s.regret_magnitude).to eq(0.0)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'starts unresolved' do
|
|
59
|
+
expect(scenario.resolved).to be false
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'sets created_at' do
|
|
63
|
+
expect(scenario.created_at).to be_a(Time)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'has nil lesson initially' do
|
|
67
|
+
expect(scenario.lesson).to be_nil
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'has nil resolved_at initially' do
|
|
71
|
+
expect(scenario.resolved_at).to be_nil
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe '#upward?' do
|
|
76
|
+
it 'returns true for upward type' do
|
|
77
|
+
expect(scenario.upward?).to be true
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'returns false for non-upward type' do
|
|
81
|
+
s = described_class.new(**base_params, scenario_type: :downward)
|
|
82
|
+
expect(s.upward?).to be false
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#downward?' do
|
|
87
|
+
it 'returns true for downward type' do
|
|
88
|
+
s = described_class.new(**base_params, scenario_type: :downward)
|
|
89
|
+
expect(s.downward?).to be true
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'returns false for upward type' do
|
|
93
|
+
expect(scenario.downward?).to be false
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe '#prefactual?' do
|
|
98
|
+
it 'returns true for prefactual type' do
|
|
99
|
+
s = described_class.new(**base_params, scenario_type: :prefactual)
|
|
100
|
+
expect(s.prefactual?).to be true
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'returns false for upward type' do
|
|
104
|
+
expect(scenario.prefactual?).to be false
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe '#emotional_response' do
|
|
109
|
+
it 'returns :regret for upward' do
|
|
110
|
+
expect(scenario.emotional_response).to eq(:regret)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'returns :relief for downward' do
|
|
114
|
+
s = described_class.new(**base_params, scenario_type: :downward)
|
|
115
|
+
expect(s.emotional_response).to eq(:relief)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'returns :acceptance for semifactual' do
|
|
119
|
+
s = described_class.new(**base_params, scenario_type: :semifactual)
|
|
120
|
+
expect(s.emotional_response).to eq(:acceptance)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'returns :anxiety for prefactual' do
|
|
124
|
+
s = described_class.new(**base_params, scenario_type: :prefactual)
|
|
125
|
+
expect(s.emotional_response).to eq(:anxiety)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'returns :neutral for unmapped types' do
|
|
129
|
+
s = described_class.new(**base_params, scenario_type: :additive)
|
|
130
|
+
expect(s.emotional_response).to eq(:neutral)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
describe '#emotional_valence' do
|
|
135
|
+
it 'is negative for upward (regret)' do
|
|
136
|
+
expect(scenario.emotional_valence).to be < 0
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'is positive for downward (relief)' do
|
|
140
|
+
s = described_class.new(**base_params, scenario_type: :downward)
|
|
141
|
+
expect(s.emotional_valence).to be > 0
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'is -0.2 for prefactual' do
|
|
145
|
+
s = described_class.new(**base_params, scenario_type: :prefactual)
|
|
146
|
+
expect(s.emotional_valence).to eq(-0.2)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'is 0.0 for additive (unmapped)' do
|
|
150
|
+
s = described_class.new(**base_params, scenario_type: :additive)
|
|
151
|
+
expect(s.emotional_valence).to eq(0.0)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
describe '#resolve' do
|
|
156
|
+
it 'marks scenario as resolved' do
|
|
157
|
+
scenario.resolve(lesson: 'always review code')
|
|
158
|
+
expect(scenario.resolved).to be true
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it 'sets the lesson' do
|
|
162
|
+
scenario.resolve(lesson: 'always review code')
|
|
163
|
+
expect(scenario.lesson).to eq('always review code')
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'sets resolved_at' do
|
|
167
|
+
scenario.resolve(lesson: 'lesson')
|
|
168
|
+
expect(scenario.resolved_at).to be_a(Time)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'returns self' do
|
|
172
|
+
result = scenario.resolve(lesson: 'lesson')
|
|
173
|
+
expect(result).to eq(scenario)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
describe '#to_h' do
|
|
178
|
+
it 'returns a hash with all key fields' do
|
|
179
|
+
h = scenario.to_h
|
|
180
|
+
expect(h[:id]).to eq(scenario.id)
|
|
181
|
+
expect(h[:scenario_type]).to eq(:upward)
|
|
182
|
+
expect(h[:mutation_type]).to eq(:action)
|
|
183
|
+
expect(h[:actual_outcome]).to eq('project failed')
|
|
184
|
+
expect(h[:counterfactual_outcome]).to eq('project succeeded')
|
|
185
|
+
expect(h[:antecedent]).to eq('had reviewed code')
|
|
186
|
+
expect(h[:domain]).to eq(:engineering)
|
|
187
|
+
expect(h[:plausibility]).to eq(0.8)
|
|
188
|
+
expect(h[:regret_magnitude]).to eq(0.6)
|
|
189
|
+
expect(h[:emotional_response]).to eq(:regret)
|
|
190
|
+
expect(h[:resolved]).to be false
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Counterfactual::Runners::Counterfactual do
|
|
4
|
+
let(:client) { Legion::Extensions::Agentic::Inference::Counterfactual::Client.new }
|
|
5
|
+
|
|
6
|
+
let(:valid_imagine_params) do
|
|
7
|
+
{
|
|
8
|
+
actual_outcome: 'deployment failed',
|
|
9
|
+
counterfactual_outcome: 'deployment succeeded',
|
|
10
|
+
antecedent: 'had run staging first',
|
|
11
|
+
scenario_type: :upward,
|
|
12
|
+
mutation_type: :action,
|
|
13
|
+
domain: :ops,
|
|
14
|
+
plausibility: 0.8
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#imagine_counterfactual' do
|
|
19
|
+
it 'returns success: true with a scenario hash' do
|
|
20
|
+
result = client.imagine_counterfactual(**valid_imagine_params)
|
|
21
|
+
expect(result[:success]).to be true
|
|
22
|
+
expect(result[:scenario]).to be_a(Hash)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'scenario hash includes expected keys' do
|
|
26
|
+
result = client.imagine_counterfactual(**valid_imagine_params)
|
|
27
|
+
s = result[:scenario]
|
|
28
|
+
expect(s[:id]).not_to be_nil
|
|
29
|
+
expect(s[:scenario_type]).to eq(:upward)
|
|
30
|
+
expect(s[:domain]).to eq(:ops)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'returns success: false for invalid scenario_type' do
|
|
34
|
+
result = client.imagine_counterfactual(**valid_imagine_params, scenario_type: :invalid)
|
|
35
|
+
expect(result[:success]).to be false
|
|
36
|
+
expect(result[:error]).to eq(:invalid_scenario_type)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'returns success: false for invalid mutation_type' do
|
|
40
|
+
result = client.imagine_counterfactual(**valid_imagine_params, mutation_type: :bogus)
|
|
41
|
+
expect(result[:success]).to be false
|
|
42
|
+
expect(result[:error]).to eq(:invalid_mutation_type)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'accepts all valid counterfactual types' do
|
|
46
|
+
Legion::Extensions::Agentic::Inference::Counterfactual::Helpers::Constants::COUNTERFACTUAL_TYPES.each do |type|
|
|
47
|
+
result = client.imagine_counterfactual(**valid_imagine_params, scenario_type: type)
|
|
48
|
+
expect(result[:success]).to be true
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'accepts all valid mutation types' do
|
|
53
|
+
Legion::Extensions::Agentic::Inference::Counterfactual::Helpers::Constants::MUTATION_TYPES.each do |mutation|
|
|
54
|
+
result = client.imagine_counterfactual(**valid_imagine_params, mutation_type: mutation)
|
|
55
|
+
expect(result[:success]).to be true
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'ignores extra keyword arguments' do
|
|
60
|
+
result = client.imagine_counterfactual(**valid_imagine_params, extra_key: 'ignored')
|
|
61
|
+
expect(result[:success]).to be true
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '#generate_alternatives' do
|
|
66
|
+
it 'returns success: true with alternatives array' do
|
|
67
|
+
result = client.generate_alternatives(actual_outcome: 'outcome', domain: :testing)
|
|
68
|
+
expect(result[:success]).to be true
|
|
69
|
+
expect(result[:alternatives]).to be_an(Array)
|
|
70
|
+
expect(result[:count]).to be > 0
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'count matches alternatives length' do
|
|
74
|
+
result = client.generate_alternatives(actual_outcome: 'outcome', domain: :testing)
|
|
75
|
+
expect(result[:count]).to eq(result[:alternatives].size)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe '#resolve_counterfactual' do
|
|
80
|
+
it 'resolves an existing scenario' do
|
|
81
|
+
imagine_result = client.imagine_counterfactual(**valid_imagine_params)
|
|
82
|
+
scenario_id = imagine_result[:scenario][:id]
|
|
83
|
+
|
|
84
|
+
result = client.resolve_counterfactual(scenario_id: scenario_id, lesson: 'always use staging')
|
|
85
|
+
expect(result[:success]).to be true
|
|
86
|
+
expect(result[:scenario][:lesson]).to eq('always use staging')
|
|
87
|
+
expect(result[:scenario][:resolved]).to be true
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'returns success: false for unknown scenario_id' do
|
|
91
|
+
result = client.resolve_counterfactual(scenario_id: 'does-not-exist', lesson: 'lesson')
|
|
92
|
+
expect(result[:success]).to be false
|
|
93
|
+
expect(result[:reason]).to eq(:not_found)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe '#compute_regret' do
|
|
98
|
+
it 'returns success: true with regret value' do
|
|
99
|
+
imagine_result = client.imagine_counterfactual(**valid_imagine_params)
|
|
100
|
+
scenario_id = imagine_result[:scenario][:id]
|
|
101
|
+
|
|
102
|
+
result = client.compute_regret(scenario_id: scenario_id)
|
|
103
|
+
expect(result[:success]).to be true
|
|
104
|
+
expect(result[:regret]).to be_a(Float)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'returns 0.0 for unknown scenario' do
|
|
108
|
+
result = client.compute_regret(scenario_id: 'ghost')
|
|
109
|
+
expect(result[:success]).to be true
|
|
110
|
+
expect(result[:regret]).to eq(0.0)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe '#net_regret_level' do
|
|
115
|
+
it 'returns success: true with net_regret float' do
|
|
116
|
+
result = client.net_regret_level
|
|
117
|
+
expect(result[:success]).to be true
|
|
118
|
+
expect(result[:net_regret]).to be_a(Float)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'increases after adding upward scenarios' do
|
|
122
|
+
before = client.net_regret_level[:net_regret]
|
|
123
|
+
client.imagine_counterfactual(**valid_imagine_params, scenario_type: :upward, plausibility: 1.0)
|
|
124
|
+
after = client.net_regret_level[:net_regret]
|
|
125
|
+
expect(after).to be > before
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe '#domain_regret' do
|
|
130
|
+
it 'returns success: true with domain-specific regret' do
|
|
131
|
+
result = client.domain_regret(domain: :ops)
|
|
132
|
+
expect(result[:success]).to be true
|
|
133
|
+
expect(result[:domain]).to eq(:ops)
|
|
134
|
+
expect(result[:regret]).to be_a(Float)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe '#lessons_learned' do
|
|
139
|
+
it 'returns empty lessons array when none resolved' do
|
|
140
|
+
result = client.lessons_learned
|
|
141
|
+
expect(result[:success]).to be true
|
|
142
|
+
expect(result[:lessons]).to be_an(Array)
|
|
143
|
+
expect(result[:count]).to eq(0)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it 'returns lessons after resolving scenarios' do
|
|
147
|
+
imagine_result = client.imagine_counterfactual(**valid_imagine_params)
|
|
148
|
+
client.resolve_counterfactual(
|
|
149
|
+
scenario_id: imagine_result[:scenario][:id],
|
|
150
|
+
lesson: 'test everything'
|
|
151
|
+
)
|
|
152
|
+
result = client.lessons_learned
|
|
153
|
+
expect(result[:count]).to eq(1)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe '#update_counterfactual' do
|
|
158
|
+
it 'returns success: true with action: :regret_decay' do
|
|
159
|
+
result = client.update_counterfactual
|
|
160
|
+
expect(result[:success]).to be true
|
|
161
|
+
expect(result[:action]).to eq(:regret_decay)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
describe '#counterfactual_stats' do
|
|
166
|
+
it 'returns success: true with stats hash' do
|
|
167
|
+
result = client.counterfactual_stats
|
|
168
|
+
expect(result[:success]).to be true
|
|
169
|
+
expect(result[:stats]).to be_a(Hash)
|
|
170
|
+
expect(result[:stats][:total]).to be_a(Integer)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it 'tracks total after adding scenarios' do
|
|
174
|
+
client.imagine_counterfactual(**valid_imagine_params)
|
|
175
|
+
result = client.counterfactual_stats
|
|
176
|
+
expect(result[:stats][:total]).to eq(1)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/debugging/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Debugging::Client do
|
|
6
|
+
it 'responds to all runner methods' do
|
|
7
|
+
client = described_class.new
|
|
8
|
+
expect(client).to respond_to(:detect_error)
|
|
9
|
+
expect(client).to respond_to(:trace_error)
|
|
10
|
+
expect(client).to respond_to(:propose_correction)
|
|
11
|
+
expect(client).to respond_to(:apply_correction)
|
|
12
|
+
expect(client).to respond_to(:measure_correction)
|
|
13
|
+
expect(client).to respond_to(:resolve_error)
|
|
14
|
+
expect(client).to respond_to(:active_errors)
|
|
15
|
+
expect(client).to respond_to(:resolved_errors)
|
|
16
|
+
expect(client).to respond_to(:errors_by_type)
|
|
17
|
+
expect(client).to respond_to(:errors_by_phase)
|
|
18
|
+
expect(client).to respond_to(:most_common_error_type)
|
|
19
|
+
expect(client).to respond_to(:most_effective_strategy)
|
|
20
|
+
expect(client).to respond_to(:correction_success_rate)
|
|
21
|
+
expect(client).to respond_to(:debugging_report)
|
|
22
|
+
expect(client).to respond_to(:snapshot)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'accepts an injected engine' do
|
|
26
|
+
engine = Legion::Extensions::Agentic::Inference::Debugging::Helpers::DebuggingEngine.new
|
|
27
|
+
client = described_class.new(engine: engine)
|
|
28
|
+
result = client.detect_error(
|
|
29
|
+
error_type: :overconfidence,
|
|
30
|
+
description: 'Test injection',
|
|
31
|
+
severity: 0.5,
|
|
32
|
+
source_phase: :tick,
|
|
33
|
+
confidence_at_detection: 0.8
|
|
34
|
+
)
|
|
35
|
+
expect(result[:success]).to be true
|
|
36
|
+
expect(engine.errors.size).to eq(1)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'creates a fresh engine when none injected' do
|
|
40
|
+
c1 = described_class.new
|
|
41
|
+
c2 = described_class.new
|
|
42
|
+
c1.detect_error(error_type: :inconsistency, description: 'x', severity: 0.5,
|
|
43
|
+
source_phase: :tick, confidence_at_detection: 0.5)
|
|
44
|
+
expect(c2.active_errors[:count]).to eq(0)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Debugging::Helpers::CausalTrace do
|
|
4
|
+
let(:trace) do
|
|
5
|
+
described_class.new(error_id: 'error-uuid', root_cause: :faulty_premise, confidence: 0.8)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe '#initialize' do
|
|
9
|
+
it 'assigns a UUID id' do
|
|
10
|
+
expect(trace.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'sets error_id' do
|
|
14
|
+
expect(trace.error_id).to eq('error-uuid')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'sets root_cause' do
|
|
18
|
+
expect(trace.root_cause).to eq(:faulty_premise)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'clamps confidence to [0, 1]' do
|
|
22
|
+
t = described_class.new(error_id: 'x', root_cause: :y, confidence: 1.5)
|
|
23
|
+
expect(t.confidence).to eq(1.0)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'initializes empty steps' do
|
|
27
|
+
expect(trace.steps).to be_empty
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#add_step!' do
|
|
32
|
+
it 'appends a step with phase, description, and timestamp' do
|
|
33
|
+
trace.add_step!(phase: :emotional_evaluation, description: 'Urgency spike caused premature conclusion')
|
|
34
|
+
expect(trace.steps.size).to eq(1)
|
|
35
|
+
step = trace.steps.first
|
|
36
|
+
expect(step[:phase]).to eq(:emotional_evaluation)
|
|
37
|
+
expect(step[:description]).to eq('Urgency spike caused premature conclusion')
|
|
38
|
+
expect(step[:timestamp]).to be_a(Time)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'returns self for chaining' do
|
|
42
|
+
result = trace.add_step!(phase: :tick, description: 'step 1')
|
|
43
|
+
expect(result).to be(trace)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'accumulates multiple steps' do
|
|
47
|
+
trace.add_step!(phase: :tick, description: 'step 1')
|
|
48
|
+
trace.add_step!(phase: :memory_retrieval, description: 'step 2')
|
|
49
|
+
trace.add_step!(phase: :prediction_engine, description: 'step 3')
|
|
50
|
+
expect(trace.steps.size).to eq(3)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe '#depth' do
|
|
55
|
+
it 'returns 0 for empty trace' do
|
|
56
|
+
expect(trace.depth).to eq(0)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'returns step count' do
|
|
60
|
+
trace.add_step!(phase: :tick, description: 'a')
|
|
61
|
+
trace.add_step!(phase: :tick, description: 'b')
|
|
62
|
+
expect(trace.depth).to eq(2)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe '#to_h' do
|
|
67
|
+
it 'returns a hash with expected keys' do
|
|
68
|
+
trace.add_step!(phase: :tick, description: 'step')
|
|
69
|
+
h = trace.to_h
|
|
70
|
+
expect(h).to include(:id, :error_id, :steps, :root_cause, :confidence, :depth)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'includes depth in hash' do
|
|
74
|
+
trace.add_step!(phase: :tick, description: 'step')
|
|
75
|
+
expect(trace.to_h[:depth]).to eq(1)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'returns dup of steps' do
|
|
79
|
+
trace.add_step!(phase: :tick, description: 'step')
|
|
80
|
+
h = trace.to_h
|
|
81
|
+
expect(h[:steps]).not_to be(trace.steps)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Debugging::Helpers::Constants do
|
|
4
|
+
describe 'ERROR_TYPES' do
|
|
5
|
+
it 'contains 8 error types' do
|
|
6
|
+
expect(described_class::ERROR_TYPES.size).to eq(8)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'includes :inconsistency' do
|
|
10
|
+
expect(described_class::ERROR_TYPES).to include(:inconsistency)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'includes :circular_logic' do
|
|
14
|
+
expect(described_class::ERROR_TYPES).to include(:circular_logic)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'includes :overconfidence' do
|
|
18
|
+
expect(described_class::ERROR_TYPES).to include(:overconfidence)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'includes :confirmation_bias' do
|
|
22
|
+
expect(described_class::ERROR_TYPES).to include(:confirmation_bias)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'is frozen' do
|
|
26
|
+
expect(described_class::ERROR_TYPES).to be_frozen
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe 'CORRECTION_STRATEGIES' do
|
|
31
|
+
it 'contains 7 strategies' do
|
|
32
|
+
expect(described_class::CORRECTION_STRATEGIES.size).to eq(7)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'includes :retrace' do
|
|
36
|
+
expect(described_class::CORRECTION_STRATEGIES).to include(:retrace)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'includes :devil_advocate' do
|
|
40
|
+
expect(described_class::CORRECTION_STRATEGIES).to include(:devil_advocate)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'is frozen' do
|
|
44
|
+
expect(described_class::CORRECTION_STRATEGIES).to be_frozen
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe 'capacity limits' do
|
|
49
|
+
it 'sets MAX_ERRORS to 300' do
|
|
50
|
+
expect(described_class::MAX_ERRORS).to eq(300)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'sets MAX_TRACES to 500' do
|
|
54
|
+
expect(described_class::MAX_TRACES).to eq(500)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'sets MAX_CORRECTIONS to 200' do
|
|
58
|
+
expect(described_class::MAX_CORRECTIONS).to eq(200)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe '.severity_label' do
|
|
63
|
+
it 'returns :trivial for 0.0' do
|
|
64
|
+
expect(described_class.severity_label(0.0)).to eq(:trivial)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'returns :trivial for 0.1' do
|
|
68
|
+
expect(described_class.severity_label(0.1)).to eq(:trivial)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'returns :minor for 0.2' do
|
|
72
|
+
expect(described_class.severity_label(0.2)).to eq(:minor)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'returns :moderate for 0.4' do
|
|
76
|
+
expect(described_class.severity_label(0.4)).to eq(:moderate)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'returns :major for 0.6' do
|
|
80
|
+
expect(described_class.severity_label(0.6)).to eq(:major)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'returns :critical for 0.8' do
|
|
84
|
+
expect(described_class.severity_label(0.8)).to eq(:critical)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'returns :critical for 1.0' do
|
|
88
|
+
expect(described_class.severity_label(1.0)).to eq(:critical)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe 'STATUS_LABELS' do
|
|
93
|
+
it 'contains expected statuses' do
|
|
94
|
+
expect(described_class::STATUS_LABELS).to include(:detected, :traced, :correcting, :resolved, :unresolvable)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Debugging::Helpers::Correction do
|
|
4
|
+
let(:correction) do
|
|
5
|
+
described_class.new(error_id: 'error-uuid', strategy: :retrace, description: 'Re-examine assumptions')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe '#initialize' do
|
|
9
|
+
it 'assigns a UUID id' do
|
|
10
|
+
expect(correction.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'sets error_id' do
|
|
14
|
+
expect(correction.error_id).to eq('error-uuid')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'sets strategy' do
|
|
18
|
+
expect(correction.strategy).to eq(:retrace)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'sets description' do
|
|
22
|
+
expect(correction.description).to eq('Re-examine assumptions')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'initializes applied as false' do
|
|
26
|
+
expect(correction.applied).to be false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'initializes effectiveness as nil' do
|
|
30
|
+
expect(correction.effectiveness).to be_nil
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#apply!' do
|
|
35
|
+
it 'sets applied to true' do
|
|
36
|
+
correction.apply!
|
|
37
|
+
expect(correction.applied).to be true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns self for chaining' do
|
|
41
|
+
expect(correction.apply!).to be(correction)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe '#measure_effectiveness!' do
|
|
46
|
+
it 'sets effectiveness' do
|
|
47
|
+
correction.measure_effectiveness!(0.8)
|
|
48
|
+
expect(correction.effectiveness).to eq(0.8)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'clamps effectiveness to [0, 1]' do
|
|
52
|
+
correction.measure_effectiveness!(1.5)
|
|
53
|
+
expect(correction.effectiveness).to eq(1.0)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'clamps negative values to 0.0' do
|
|
57
|
+
correction.measure_effectiveness!(-0.2)
|
|
58
|
+
expect(correction.effectiveness).to eq(0.0)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'returns self for chaining' do
|
|
62
|
+
expect(correction.measure_effectiveness!(0.7)).to be(correction)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe '#effective?' do
|
|
67
|
+
it 'returns false when effectiveness is nil' do
|
|
68
|
+
expect(correction.effective?).to be false
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'returns true when effectiveness >= 0.6' do
|
|
72
|
+
correction.measure_effectiveness!(0.6)
|
|
73
|
+
expect(correction.effective?).to be true
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'returns true for high effectiveness' do
|
|
77
|
+
correction.measure_effectiveness!(0.9)
|
|
78
|
+
expect(correction.effective?).to be true
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'returns false when effectiveness < 0.6' do
|
|
82
|
+
correction.measure_effectiveness!(0.5)
|
|
83
|
+
expect(correction.effective?).to be false
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe '#to_h' do
|
|
88
|
+
it 'includes expected keys' do
|
|
89
|
+
h = correction.to_h
|
|
90
|
+
expect(h).to include(:id, :error_id, :strategy, :description, :applied, :effectiveness, :effective)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'reflects effective? result' do
|
|
94
|
+
correction.measure_effectiveness!(0.7)
|
|
95
|
+
expect(correction.to_h[:effective]).to be true
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|