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,349 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/abductive/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Abductive::Runners::AbductiveReasoning do
|
|
6
|
+
let(:client) { Legion::Extensions::Agentic::Inference::Abductive::Client.new }
|
|
7
|
+
|
|
8
|
+
describe '#record_observation' do
|
|
9
|
+
it 'records an observation and returns success' do
|
|
10
|
+
result = client.record_observation(
|
|
11
|
+
content: 'CPU usage spiked to 100% unexpectedly',
|
|
12
|
+
domain: :system_health,
|
|
13
|
+
surprise_level: :surprising
|
|
14
|
+
)
|
|
15
|
+
expect(result[:success]).to be true
|
|
16
|
+
expect(result[:observation][:id]).to match(/\A[0-9a-f-]{36}\z/)
|
|
17
|
+
expect(result[:observation][:domain]).to eq(:system_health)
|
|
18
|
+
expect(result[:observation][:surprise_level]).to eq(:surprising)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'rejects invalid surprise level' do
|
|
22
|
+
result = client.record_observation(
|
|
23
|
+
content: 'some fact',
|
|
24
|
+
domain: :test,
|
|
25
|
+
surprise_level: :unknown_level
|
|
26
|
+
)
|
|
27
|
+
expect(result[:success]).to be false
|
|
28
|
+
expect(result[:error]).to eq(:invalid_surprise_level)
|
|
29
|
+
expect(result[:valid_levels]).to eq(Legion::Extensions::Agentic::Inference::Abductive::Helpers::Constants::SURPRISE_LEVELS)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'uses notable as default surprise level' do
|
|
33
|
+
result = client.record_observation(content: 'a fact', domain: :test)
|
|
34
|
+
expect(result[:observation][:surprise_level]).to eq(:notable)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'stores context hash' do
|
|
38
|
+
result = client.record_observation(
|
|
39
|
+
content: 'memory leak detected',
|
|
40
|
+
domain: :system,
|
|
41
|
+
context: { pid: 1234, rss_mb: 4096 }
|
|
42
|
+
)
|
|
43
|
+
expect(result[:observation][:context]).to eq({ pid: 1234, rss_mb: 4096 })
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe '#generate_hypothesis' do
|
|
48
|
+
let(:obs_result) { client.record_observation(content: 'service crashed', domain: :ops) }
|
|
49
|
+
let(:obs_id) { obs_result[:observation][:id] }
|
|
50
|
+
|
|
51
|
+
it 'generates a hypothesis and returns success' do
|
|
52
|
+
result = client.generate_hypothesis(
|
|
53
|
+
content: 'Memory leak caused service crash',
|
|
54
|
+
observation_ids: [obs_id],
|
|
55
|
+
domain: :ops,
|
|
56
|
+
simplicity: 0.7,
|
|
57
|
+
explanatory_power: 0.8
|
|
58
|
+
)
|
|
59
|
+
expect(result[:success]).to be true
|
|
60
|
+
expect(result[:hypothesis][:id]).to match(/\A[0-9a-f-]{36}\z/)
|
|
61
|
+
expect(result[:hypothesis][:state]).to eq(:candidate)
|
|
62
|
+
expect(result[:hypothesis][:overall_score]).to be > 0
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'uses default prior probability when not given' do
|
|
66
|
+
result = client.generate_hypothesis(
|
|
67
|
+
content: 'Network partition caused crash',
|
|
68
|
+
observation_ids: [obs_id],
|
|
69
|
+
domain: :ops,
|
|
70
|
+
simplicity: 0.5,
|
|
71
|
+
explanatory_power: 0.6
|
|
72
|
+
)
|
|
73
|
+
expect(result[:hypothesis][:prior_probability]).to eq(
|
|
74
|
+
Legion::Extensions::Agentic::Inference::Abductive::Helpers::Constants::DEFAULT_PLAUSIBILITY
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'uses provided prior probability' do
|
|
79
|
+
result = client.generate_hypothesis(
|
|
80
|
+
content: 'Config error',
|
|
81
|
+
observation_ids: [obs_id],
|
|
82
|
+
domain: :ops,
|
|
83
|
+
simplicity: 0.9,
|
|
84
|
+
explanatory_power: 0.7,
|
|
85
|
+
prior_probability: 0.8
|
|
86
|
+
)
|
|
87
|
+
expect(result[:hypothesis][:prior_probability]).to eq(0.8)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe '#evaluate_hypothesis' do
|
|
92
|
+
let(:obs_id) { client.record_observation(content: 'anomaly', domain: :test)[:observation][:id] }
|
|
93
|
+
let(:hyp_id) do
|
|
94
|
+
client.generate_hypothesis(
|
|
95
|
+
content: 'hypothesis A',
|
|
96
|
+
observation_ids: [obs_id],
|
|
97
|
+
domain: :test,
|
|
98
|
+
simplicity: 0.8,
|
|
99
|
+
explanatory_power: 0.9
|
|
100
|
+
)[:hypothesis][:id]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'evaluates a known hypothesis' do
|
|
104
|
+
result = client.evaluate_hypothesis(hypothesis_id: hyp_id)
|
|
105
|
+
expect(result[:success]).to be true
|
|
106
|
+
expect(result[:score]).to be_a(Float)
|
|
107
|
+
expect(result[:rank]).to be >= 1
|
|
108
|
+
expect(result[:quality_label]).to be_a(Symbol)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'returns not_found for unknown hypothesis' do
|
|
112
|
+
result = client.evaluate_hypothesis(hypothesis_id: 'nonexistent-id')
|
|
113
|
+
expect(result[:success]).to be false
|
|
114
|
+
expect(result[:error]).to eq(:not_found)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe '#add_hypothesis_evidence' do
|
|
119
|
+
let(:obs_id) { client.record_observation(content: 'strange output', domain: :test)[:observation][:id] }
|
|
120
|
+
let(:hyp_id) do
|
|
121
|
+
client.generate_hypothesis(
|
|
122
|
+
content: 'bad config',
|
|
123
|
+
observation_ids: [obs_id],
|
|
124
|
+
domain: :test,
|
|
125
|
+
simplicity: 0.6,
|
|
126
|
+
explanatory_power: 0.7
|
|
127
|
+
)[:hypothesis][:id]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'adds supporting evidence and boosts plausibility' do
|
|
131
|
+
before_plausibility = client.evaluate_hypothesis(hypothesis_id: hyp_id)[:score]
|
|
132
|
+
client.add_hypothesis_evidence(hypothesis_id: hyp_id, supporting: true)
|
|
133
|
+
hyp_after = client.evaluate_hypothesis(hypothesis_id: hyp_id)
|
|
134
|
+
expect(hyp_after[:success]).to be true
|
|
135
|
+
expect(before_plausibility).to be_a(Float)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'transitions to supported after enough supporting evidence' do
|
|
139
|
+
3.times { client.add_hypothesis_evidence(hypothesis_id: hyp_id, supporting: true) }
|
|
140
|
+
result = client.add_hypothesis_evidence(hypothesis_id: hyp_id, supporting: true)
|
|
141
|
+
expect(result[:state]).to eq(:supported)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'adds contradicting evidence' do
|
|
145
|
+
result = client.add_hypothesis_evidence(hypothesis_id: hyp_id, supporting: false)
|
|
146
|
+
expect(result[:success]).to be true
|
|
147
|
+
expect(result[:state]).to eq(:candidate)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it 'returns not_found for unknown hypothesis' do
|
|
151
|
+
result = client.add_hypothesis_evidence(hypothesis_id: 'missing', supporting: true)
|
|
152
|
+
expect(result[:success]).to be false
|
|
153
|
+
expect(result[:error]).to eq(:not_found)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe '#best_explanation' do
|
|
158
|
+
let(:obs_id) { client.record_observation(content: 'disk full warning', domain: :storage)[:observation][:id] }
|
|
159
|
+
|
|
160
|
+
it 'returns nil found when no hypotheses exist' do
|
|
161
|
+
result = client.best_explanation(observation_id: obs_id)
|
|
162
|
+
expect(result[:success]).to be true
|
|
163
|
+
expect(result[:found]).to be false
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'returns best hypothesis by overall_score' do
|
|
167
|
+
client.generate_hypothesis(
|
|
168
|
+
content: 'log files grew unbounded',
|
|
169
|
+
observation_ids: [obs_id],
|
|
170
|
+
domain: :storage,
|
|
171
|
+
simplicity: 0.9,
|
|
172
|
+
explanatory_power: 0.9,
|
|
173
|
+
prior_probability: 0.8
|
|
174
|
+
)
|
|
175
|
+
client.generate_hypothesis(
|
|
176
|
+
content: 'backup job failed and left temp files',
|
|
177
|
+
observation_ids: [obs_id],
|
|
178
|
+
domain: :storage,
|
|
179
|
+
simplicity: 0.3,
|
|
180
|
+
explanatory_power: 0.4,
|
|
181
|
+
prior_probability: 0.2
|
|
182
|
+
)
|
|
183
|
+
result = client.best_explanation(observation_id: obs_id)
|
|
184
|
+
expect(result[:success]).to be true
|
|
185
|
+
expect(result[:found]).to be true
|
|
186
|
+
expect(result[:hypothesis][:content]).to eq('log files grew unbounded')
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
describe '#competing_hypotheses' do
|
|
191
|
+
let(:obs_id) { client.record_observation(content: 'latency spike', domain: :perf)[:observation][:id] }
|
|
192
|
+
|
|
193
|
+
it 'returns empty list when no hypotheses' do
|
|
194
|
+
result = client.competing_hypotheses(observation_id: obs_id)
|
|
195
|
+
expect(result[:success]).to be true
|
|
196
|
+
expect(result[:count]).to eq(0)
|
|
197
|
+
expect(result[:hypotheses]).to eq([])
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it 'returns hypotheses sorted by score descending' do
|
|
201
|
+
client.generate_hypothesis(
|
|
202
|
+
content: 'DB slow query',
|
|
203
|
+
observation_ids: [obs_id],
|
|
204
|
+
domain: :perf,
|
|
205
|
+
simplicity: 0.8,
|
|
206
|
+
explanatory_power: 0.8
|
|
207
|
+
)
|
|
208
|
+
client.generate_hypothesis(
|
|
209
|
+
content: 'Network congestion',
|
|
210
|
+
observation_ids: [obs_id],
|
|
211
|
+
domain: :perf,
|
|
212
|
+
simplicity: 0.2,
|
|
213
|
+
explanatory_power: 0.2
|
|
214
|
+
)
|
|
215
|
+
result = client.competing_hypotheses(observation_id: obs_id)
|
|
216
|
+
expect(result[:count]).to eq(2)
|
|
217
|
+
scores = result[:hypotheses].map { |h| h[:overall_score] }
|
|
218
|
+
expect(scores).to eq(scores.sort.reverse)
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
describe '#refute_hypothesis' do
|
|
223
|
+
let(:obs_id) { client.record_observation(content: 'error 500', domain: :web)[:observation][:id] }
|
|
224
|
+
let(:hyp_id) do
|
|
225
|
+
client.generate_hypothesis(
|
|
226
|
+
content: 'out of memory',
|
|
227
|
+
observation_ids: [obs_id],
|
|
228
|
+
domain: :web,
|
|
229
|
+
simplicity: 0.5,
|
|
230
|
+
explanatory_power: 0.5
|
|
231
|
+
)[:hypothesis][:id]
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it 'refutes a hypothesis' do
|
|
235
|
+
result = client.refute_hypothesis(hypothesis_id: hyp_id)
|
|
236
|
+
expect(result[:success]).to be true
|
|
237
|
+
expect(result[:state]).to eq(:refuted)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it 'excludes refuted hypotheses from competing list' do
|
|
241
|
+
client.refute_hypothesis(hypothesis_id: hyp_id)
|
|
242
|
+
result = client.competing_hypotheses(observation_id: obs_id)
|
|
243
|
+
expect(result[:count]).to eq(0)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it 'returns not_found for unknown hypothesis' do
|
|
247
|
+
result = client.refute_hypothesis(hypothesis_id: 'ghost')
|
|
248
|
+
expect(result[:success]).to be false
|
|
249
|
+
expect(result[:error]).to eq(:not_found)
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
describe '#unexplained_observations' do
|
|
254
|
+
it 'returns observations with no supported hypothesis' do
|
|
255
|
+
client.record_observation(content: 'unexplained event', domain: :mystery)
|
|
256
|
+
result = client.unexplained_observations
|
|
257
|
+
expect(result[:success]).to be true
|
|
258
|
+
expect(result[:count]).to be >= 1
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
it 'excludes observations explained by a supported hypothesis' do
|
|
262
|
+
obs_id = client.record_observation(content: 'explained', domain: :test)[:observation][:id]
|
|
263
|
+
hyp_id = client.generate_hypothesis(
|
|
264
|
+
content: 'known cause',
|
|
265
|
+
observation_ids: [obs_id],
|
|
266
|
+
domain: :test,
|
|
267
|
+
simplicity: 0.9,
|
|
268
|
+
explanatory_power: 0.9
|
|
269
|
+
)[:hypothesis][:id]
|
|
270
|
+
3.times { client.add_hypothesis_evidence(hypothesis_id: hyp_id, supporting: true) }
|
|
271
|
+
client.add_hypothesis_evidence(hypothesis_id: hyp_id, supporting: true)
|
|
272
|
+
|
|
273
|
+
result = client.unexplained_observations
|
|
274
|
+
obs_ids = result[:observations].map { |o| o[:id] }
|
|
275
|
+
expect(obs_ids).not_to include(obs_id)
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
describe '#update_abductive_reasoning' do
|
|
280
|
+
it 'runs decay and prune cycle' do
|
|
281
|
+
result = client.update_abductive_reasoning
|
|
282
|
+
expect(result[:success]).to be true
|
|
283
|
+
expect(result[:decayed]).to be >= 0
|
|
284
|
+
expect(result[:pruned]).to be >= 0
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it 'prunes refuted hypotheses' do
|
|
288
|
+
obs_id = client.record_observation(content: 'obs', domain: :test)[:observation][:id]
|
|
289
|
+
hyp_id = client.generate_hypothesis(
|
|
290
|
+
content: 'bad hyp',
|
|
291
|
+
observation_ids: [obs_id],
|
|
292
|
+
domain: :test,
|
|
293
|
+
simplicity: 0.5,
|
|
294
|
+
explanatory_power: 0.5
|
|
295
|
+
)[:hypothesis][:id]
|
|
296
|
+
client.refute_hypothesis(hypothesis_id: hyp_id)
|
|
297
|
+
|
|
298
|
+
result = client.update_abductive_reasoning
|
|
299
|
+
expect(result[:pruned]).to eq(1)
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
describe '#abductive_reasoning_stats' do
|
|
304
|
+
it 'returns stats hash' do
|
|
305
|
+
result = client.abductive_reasoning_stats
|
|
306
|
+
expect(result[:success]).to be true
|
|
307
|
+
expect(result).to have_key(:observation_count)
|
|
308
|
+
expect(result).to have_key(:hypothesis_count)
|
|
309
|
+
expect(result).to have_key(:supported_count)
|
|
310
|
+
expect(result).to have_key(:refuted_count)
|
|
311
|
+
expect(result).to have_key(:candidate_count)
|
|
312
|
+
expect(result).to have_key(:unexplained_count)
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
it 'reflects accumulated state' do
|
|
316
|
+
client.record_observation(content: 'fact', domain: :test)
|
|
317
|
+
result = client.abductive_reasoning_stats
|
|
318
|
+
expect(result[:observation_count]).to be >= 1
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
describe 'quality labels' do
|
|
323
|
+
let(:obs_id) { client.record_observation(content: 'obs', domain: :test)[:observation][:id] }
|
|
324
|
+
|
|
325
|
+
it 'assigns compelling label for high-scoring hypothesis' do
|
|
326
|
+
result = client.generate_hypothesis(
|
|
327
|
+
content: 'strong hypothesis',
|
|
328
|
+
observation_ids: [obs_id],
|
|
329
|
+
domain: :test,
|
|
330
|
+
simplicity: 1.0,
|
|
331
|
+
explanatory_power: 1.0,
|
|
332
|
+
prior_probability: 1.0
|
|
333
|
+
)
|
|
334
|
+
expect(result[:hypothesis][:quality_label]).to eq(:compelling)
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
it 'assigns implausible label for low-scoring hypothesis' do
|
|
338
|
+
result = client.generate_hypothesis(
|
|
339
|
+
content: 'weak hypothesis',
|
|
340
|
+
observation_ids: [obs_id],
|
|
341
|
+
domain: :test,
|
|
342
|
+
simplicity: 0.0,
|
|
343
|
+
explanatory_power: 0.0,
|
|
344
|
+
prior_probability: 0.0
|
|
345
|
+
)
|
|
346
|
+
expect(result[:hypothesis][:quality_label]).to eq(:implausible)
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/affordance/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Affordance::Client do
|
|
6
|
+
subject(:client) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'detects and evaluates affordances' do
|
|
9
|
+
client.register_capability(name: :http_client)
|
|
10
|
+
client.detect_affordance(action: :send, domain: :comm, affordance_type: :action_possible,
|
|
11
|
+
requires: [:http_client])
|
|
12
|
+
result = client.evaluate_action(action: :send, domain: :comm)
|
|
13
|
+
expect(result[:feasible]).to be true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'detects threats' do
|
|
17
|
+
client.detect_affordance(action: :intrusion, domain: :security, affordance_type: :threat, relevance: 0.9)
|
|
18
|
+
result = client.current_threats
|
|
19
|
+
expect(result[:count]).to eq(1)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'reports stats' do
|
|
23
|
+
result = client.affordance_stats
|
|
24
|
+
expect(result[:success]).to be true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Affordance::Helpers::AffordanceField do
|
|
4
|
+
subject(:field) { described_class.new }
|
|
5
|
+
|
|
6
|
+
let(:constants) { Legion::Extensions::Agentic::Inference::Affordance::Helpers::Constants }
|
|
7
|
+
|
|
8
|
+
describe '#register_capability' do
|
|
9
|
+
it 'adds a capability' do
|
|
10
|
+
result = field.register_capability(name: :http_client, domain: :network)
|
|
11
|
+
expect(result).to be_a(Hash)
|
|
12
|
+
expect(field.capabilities.size).to eq(1)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'enforces limit' do
|
|
16
|
+
constants::MAX_CAPABILITIES.times { |i| field.register_capability(name: :"cap_#{i}") }
|
|
17
|
+
expect(field.register_capability(name: :overflow)).to be_nil
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe '#set_environment' do
|
|
22
|
+
it 'sets a property' do
|
|
23
|
+
result = field.set_environment(property: :network_status, value: :online)
|
|
24
|
+
expect(result).to be_a(Hash)
|
|
25
|
+
expect(field.environment.size).to eq(1)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'updates existing property' do
|
|
29
|
+
field.set_environment(property: :status, value: :offline)
|
|
30
|
+
field.set_environment(property: :status, value: :online)
|
|
31
|
+
expect(field.environment[:status][:value]).to eq(:online)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '#detect_affordance' do
|
|
36
|
+
it 'creates an affordance' do
|
|
37
|
+
aff = field.detect_affordance(action: :send, domain: :comm, affordance_type: :action_possible)
|
|
38
|
+
expect(aff).to be_a(Legion::Extensions::Agentic::Inference::Affordance::Helpers::AffordanceItem)
|
|
39
|
+
expect(field.affordances.size).to eq(1)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'rejects invalid types' do
|
|
43
|
+
expect(field.detect_affordance(action: :x, domain: :d, affordance_type: :bogus)).to be_nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'enforces MAX_AFFORDANCES' do
|
|
47
|
+
constants::MAX_AFFORDANCES.times do |i|
|
|
48
|
+
field.detect_affordance(action: :"a_#{i}", domain: :d, affordance_type: :neutral)
|
|
49
|
+
end
|
|
50
|
+
expect(field.detect_affordance(action: :overflow, domain: :d, affordance_type: :neutral)).to be_nil
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe '#evaluate_action' do
|
|
55
|
+
it 'returns not feasible when no affordance exists' do
|
|
56
|
+
result = field.evaluate_action(action: :fly, domain: :motion)
|
|
57
|
+
expect(result[:feasible]).to be false
|
|
58
|
+
expect(result[:reason]).to eq(:no_affordance)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'returns blocked when blocker exists' do
|
|
62
|
+
field.detect_affordance(action: :send, domain: :comm, affordance_type: :action_blocked)
|
|
63
|
+
result = field.evaluate_action(action: :send, domain: :comm)
|
|
64
|
+
expect(result[:feasible]).to be false
|
|
65
|
+
expect(result[:reason]).to eq(:blocked)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'returns feasible when capable and not blocked' do
|
|
69
|
+
field.register_capability(name: :http_client)
|
|
70
|
+
field.detect_affordance(action: :send, domain: :comm, affordance_type: :action_possible,
|
|
71
|
+
requires: [:http_client])
|
|
72
|
+
result = field.evaluate_action(action: :send, domain: :comm)
|
|
73
|
+
expect(result[:feasible]).to be true
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'returns not feasible when capabilities missing' do
|
|
77
|
+
field.detect_affordance(action: :send, domain: :comm, affordance_type: :action_possible,
|
|
78
|
+
requires: [:missing_cap])
|
|
79
|
+
result = field.evaluate_action(action: :send, domain: :comm)
|
|
80
|
+
expect(result[:feasible]).to be false
|
|
81
|
+
expect(result[:reason]).to eq(:missing_capabilities)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'includes risks' do
|
|
85
|
+
field.detect_affordance(action: :send, domain: :comm, affordance_type: :action_risky)
|
|
86
|
+
result = field.evaluate_action(action: :send, domain: :comm)
|
|
87
|
+
expect(result[:risks]).not_to be_empty
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe '#actionable_affordances' do
|
|
92
|
+
it 'returns only actionable items sorted by relevance' do
|
|
93
|
+
field.detect_affordance(action: :send, domain: :comm, affordance_type: :action_possible, relevance: 0.8)
|
|
94
|
+
field.detect_affordance(action: :block, domain: :comm, affordance_type: :action_blocked)
|
|
95
|
+
items = field.actionable_affordances
|
|
96
|
+
expect(items.size).to eq(1)
|
|
97
|
+
expect(items.first[:action]).to eq(:send)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '#threats' do
|
|
102
|
+
it 'returns threat affordances' do
|
|
103
|
+
field.detect_affordance(action: :attack, domain: :security, affordance_type: :threat)
|
|
104
|
+
expect(field.threats.size).to eq(1)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe '#affordances_in' do
|
|
109
|
+
it 'filters by domain' do
|
|
110
|
+
field.detect_affordance(action: :send, domain: :comm, affordance_type: :action_possible)
|
|
111
|
+
field.detect_affordance(action: :read, domain: :data, affordance_type: :resource_available)
|
|
112
|
+
expect(field.affordances_in(domain: :comm).size).to eq(1)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe '#decay_all' do
|
|
117
|
+
it 'decays and removes faded affordances' do
|
|
118
|
+
field.detect_affordance(action: :faint, domain: :d, affordance_type: :neutral, relevance: 0.06)
|
|
119
|
+
10.times { field.decay_all }
|
|
120
|
+
expect(field.affordances).to be_empty
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe '#to_h' do
|
|
125
|
+
it 'returns summary hash' do
|
|
126
|
+
h = field.to_h
|
|
127
|
+
expect(h).to include(:affordance_count, :capability_count, :environment_props,
|
|
128
|
+
:actionable_count, :blocked_count, :threat_count, :history_size)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Affordance::Helpers::AffordanceItem do
|
|
4
|
+
subject(:item) do
|
|
5
|
+
described_class.new(id: :aff_one, action: :send_message, domain: :communication,
|
|
6
|
+
affordance_type: :action_possible)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:constants) { Legion::Extensions::Agentic::Inference::Affordance::Helpers::Constants }
|
|
10
|
+
|
|
11
|
+
describe '#initialize' do
|
|
12
|
+
it 'sets id, action, domain, and type' do
|
|
13
|
+
expect(item.id).to eq(:aff_one)
|
|
14
|
+
expect(item.action).to eq(:send_message)
|
|
15
|
+
expect(item.domain).to eq(:communication)
|
|
16
|
+
expect(item.affordance_type).to eq(:action_possible)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'defaults relevance' do
|
|
20
|
+
expect(item.relevance).to eq(constants::DEFAULT_RELEVANCE)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#actionable?' do
|
|
25
|
+
it 'returns true for possible action above threshold' do
|
|
26
|
+
expect(item.actionable?).to be true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'returns false for blocked actions' do
|
|
30
|
+
blocked = described_class.new(id: :x, action: :y, domain: :d, affordance_type: :action_blocked)
|
|
31
|
+
expect(blocked.actionable?).to be false
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'returns false when below threshold' do
|
|
35
|
+
item.relevance = 0.2
|
|
36
|
+
expect(item.actionable?).to be false
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#blocked?' do
|
|
41
|
+
it 'returns true for blocked type' do
|
|
42
|
+
b = described_class.new(id: :x, action: :y, domain: :d, affordance_type: :action_blocked)
|
|
43
|
+
expect(b.blocked?).to be true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'returns false otherwise' do
|
|
47
|
+
expect(item.blocked?).to be false
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe '#risky?' do
|
|
52
|
+
it 'returns true for risky type' do
|
|
53
|
+
r = described_class.new(id: :x, action: :y, domain: :d, affordance_type: :action_risky)
|
|
54
|
+
expect(r.risky?).to be true
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe '#threatening?' do
|
|
59
|
+
it 'returns true for threat type' do
|
|
60
|
+
t = described_class.new(id: :x, action: :y, domain: :d, affordance_type: :threat)
|
|
61
|
+
expect(t.threatening?).to be true
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '#decay' do
|
|
66
|
+
it 'reduces relevance' do
|
|
67
|
+
before = item.relevance
|
|
68
|
+
item.decay
|
|
69
|
+
expect(item.relevance).to be < before
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'does not go below zero' do
|
|
73
|
+
100.times { item.decay }
|
|
74
|
+
expect(item.relevance).to be >= 0.0
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe '#faded?' do
|
|
79
|
+
it 'returns false initially' do
|
|
80
|
+
expect(item.faded?).to be false
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'returns true at floor' do
|
|
84
|
+
item.relevance = constants::RELEVANCE_FLOOR
|
|
85
|
+
expect(item.faded?).to be true
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe '#relevance_label' do
|
|
90
|
+
it 'returns :moderate for default relevance' do
|
|
91
|
+
expect(item.relevance_label).to eq(:moderate)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'returns :critical for high relevance' do
|
|
95
|
+
item.relevance = 0.9
|
|
96
|
+
expect(item.relevance_label).to eq(:critical)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe '#to_h' do
|
|
101
|
+
it 'returns expected keys' do
|
|
102
|
+
h = item.to_h
|
|
103
|
+
expect(h).to include(:id, :action, :domain, :affordance_type, :requires,
|
|
104
|
+
:relevance, :relevance_label, :actionable, :blocked, :risky)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/affordance/runners/affordance'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Affordance::Runners::Affordance do
|
|
6
|
+
let(:aff_field) { Legion::Extensions::Agentic::Inference::Affordance::Helpers::AffordanceField.new }
|
|
7
|
+
let(:host) do
|
|
8
|
+
obj = Object.new
|
|
9
|
+
obj.extend(described_class)
|
|
10
|
+
obj.instance_variable_set(:@field, aff_field)
|
|
11
|
+
obj
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '#register_capability' do
|
|
15
|
+
it 'registers successfully' do
|
|
16
|
+
result = host.register_capability(name: :http_client)
|
|
17
|
+
expect(result[:success]).to be true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe '#set_environment' do
|
|
22
|
+
it 'sets property' do
|
|
23
|
+
result = host.set_environment(property: :status, value: :online)
|
|
24
|
+
expect(result[:success]).to be true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#detect_affordance' do
|
|
29
|
+
it 'detects an affordance' do
|
|
30
|
+
result = host.detect_affordance(action: :send, domain: :comm, affordance_type: :action_possible)
|
|
31
|
+
expect(result[:success]).to be true
|
|
32
|
+
expect(result[:affordance][:action]).to eq(:send)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'fails for invalid type' do
|
|
36
|
+
result = host.detect_affordance(action: :x, domain: :d, affordance_type: :bogus)
|
|
37
|
+
expect(result[:success]).to be false
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe '#evaluate_action' do
|
|
42
|
+
it 'evaluates feasibility' do
|
|
43
|
+
host.detect_affordance(action: :send, domain: :comm, affordance_type: :action_possible)
|
|
44
|
+
result = host.evaluate_action(action: :send, domain: :comm)
|
|
45
|
+
expect(result[:success]).to be true
|
|
46
|
+
expect(result[:feasible]).to be true
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe '#actionable_affordances' do
|
|
51
|
+
it 'returns actionable items' do
|
|
52
|
+
result = host.actionable_affordances
|
|
53
|
+
expect(result[:success]).to be true
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#current_threats' do
|
|
58
|
+
it 'returns threats' do
|
|
59
|
+
result = host.current_threats
|
|
60
|
+
expect(result[:success]).to be true
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe '#update_affordances' do
|
|
65
|
+
it 'decays' do
|
|
66
|
+
result = host.update_affordances
|
|
67
|
+
expect(result[:success]).to be true
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '#affordance_stats' do
|
|
72
|
+
it 'returns stats' do
|
|
73
|
+
result = host.affordance_stats
|
|
74
|
+
expect(result[:success]).to be true
|
|
75
|
+
expect(result[:stats]).to include(:affordance_count)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|