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,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Horizon::Helpers::Constants do
|
|
4
|
+
describe 'numeric constants' do
|
|
5
|
+
it 'MAX_PROJECTIONS is 200' do
|
|
6
|
+
expect(described_module::MAX_PROJECTIONS).to eq(200)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'DEFAULT_HORIZON is 0.5' do
|
|
10
|
+
expect(described_module::DEFAULT_HORIZON).to eq(0.5)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'HORIZON_EXPAND is 0.08' do
|
|
14
|
+
expect(described_module::HORIZON_EXPAND).to eq(0.08)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'HORIZON_CONTRACT is 0.1' do
|
|
18
|
+
expect(described_module::HORIZON_CONTRACT).to eq(0.1)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'MIN_HORIZON is 0.1' do
|
|
22
|
+
expect(described_module::MIN_HORIZON).to eq(0.1)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'MAX_HORIZON is 1.0' do
|
|
26
|
+
expect(described_module::MAX_HORIZON).to eq(1.0)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'STRESS_CONTRACTION is 0.15' do
|
|
30
|
+
expect(described_module::STRESS_CONTRACTION).to eq(0.15)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'CONFIDENCE_DECAY_PER_STEP is 0.1' do
|
|
34
|
+
expect(described_module::CONFIDENCE_DECAY_PER_STEP).to eq(0.1)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe 'HORIZON_LEVELS' do
|
|
39
|
+
it 'has 5 levels' do
|
|
40
|
+
expect(described_module::HORIZON_LEVELS.size).to eq(5)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'starts with :immediate' do
|
|
44
|
+
expect(described_module::HORIZON_LEVELS.first).to eq(:immediate)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'ends with :strategic' do
|
|
48
|
+
expect(described_module::HORIZON_LEVELS.last).to eq(:strategic)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'contains :near_term, :medium_term, :long_term' do
|
|
52
|
+
expect(described_module::HORIZON_LEVELS).to include(:near_term, :medium_term, :long_term)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'is frozen' do
|
|
56
|
+
expect(described_module::HORIZON_LEVELS).to be_frozen
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe 'CONSTRUAL_LABELS' do
|
|
61
|
+
it 'has 5 entries' do
|
|
62
|
+
expect(described_module::CONSTRUAL_LABELS.size).to eq(5)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'maps low distances to :concrete' do
|
|
66
|
+
entry = described_module::CONSTRUAL_LABELS.find { |e| e[:range].cover?(0.1) }
|
|
67
|
+
expect(entry[:label]).to eq(:concrete)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'maps mid distances to :balanced' do
|
|
71
|
+
entry = described_module::CONSTRUAL_LABELS.find { |e| e[:range].cover?(0.5) }
|
|
72
|
+
expect(entry[:label]).to eq(:balanced)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'maps high distances to :abstract' do
|
|
76
|
+
entry = described_module::CONSTRUAL_LABELS.find { |e| e[:range].cover?(0.9) }
|
|
77
|
+
expect(entry[:label]).to eq(:abstract)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'maps 0.3 to :detailed' do
|
|
81
|
+
entry = described_module::CONSTRUAL_LABELS.find { |e| e[:range].cover?(0.3) }
|
|
82
|
+
expect(entry[:label]).to eq(:detailed)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'maps 0.7 to :schematic' do
|
|
86
|
+
entry = described_module::CONSTRUAL_LABELS.find { |e| e[:range].cover?(0.7) }
|
|
87
|
+
expect(entry[:label]).to eq(:schematic)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'is frozen' do
|
|
91
|
+
expect(described_module::CONSTRUAL_LABELS).to be_frozen
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def described_module
|
|
96
|
+
Legion::Extensions::Agentic::Inference::Horizon::Helpers::Constants
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Horizon::Helpers::HorizonEngine do
|
|
4
|
+
subject(:engine) { described_class.new }
|
|
5
|
+
|
|
6
|
+
let(:constants) { Legion::Extensions::Agentic::Inference::Horizon::Helpers::Constants }
|
|
7
|
+
|
|
8
|
+
describe '#initialize' do
|
|
9
|
+
it 'starts with empty projections' do
|
|
10
|
+
expect(engine.projections).to be_empty
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'starts with DEFAULT_HORIZON' do
|
|
14
|
+
expect(engine.current_horizon).to eq(constants::DEFAULT_HORIZON)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'starts with zero stress' do
|
|
18
|
+
expect(engine.stress_level).to eq(0.0)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'accepts custom initial_horizon' do
|
|
22
|
+
e = described_class.new(initial_horizon: 0.8)
|
|
23
|
+
expect(e.current_horizon).to eq(0.8)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'clamps initial_horizon to MIN_HORIZON' do
|
|
27
|
+
e = described_class.new(initial_horizon: 0.0)
|
|
28
|
+
expect(e.current_horizon).to eq(constants::MIN_HORIZON)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'clamps initial_horizon to MAX_HORIZON' do
|
|
32
|
+
e = described_class.new(initial_horizon: 1.5)
|
|
33
|
+
expect(e.current_horizon).to eq(constants::MAX_HORIZON)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe '#add_projection' do
|
|
38
|
+
it 'adds a projection to the list' do
|
|
39
|
+
engine.add_projection(description: 'test')
|
|
40
|
+
expect(engine.projections.size).to eq(1)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'returns a Projection object' do
|
|
44
|
+
proj = engine.add_projection(description: 'test')
|
|
45
|
+
expect(proj).to be_a(Legion::Extensions::Agentic::Inference::Horizon::Helpers::Projection)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'uses current_horizon as default distance' do
|
|
49
|
+
proj = engine.add_projection(description: 'test')
|
|
50
|
+
expect(proj.horizon_distance).to eq(engine.current_horizon)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'accepts explicit horizon_distance' do
|
|
54
|
+
proj = engine.add_projection(description: 'test', horizon_distance: 0.9)
|
|
55
|
+
expect(proj.horizon_distance).to eq(0.9)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'caps projections at MAX_PROJECTIONS' do
|
|
59
|
+
(constants::MAX_PROJECTIONS + 10).times { |i| engine.add_projection(description: "proj #{i}") }
|
|
60
|
+
expect(engine.projections.size).to eq(constants::MAX_PROJECTIONS)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'keeps the most recent projections when capping' do
|
|
64
|
+
(constants::MAX_PROJECTIONS + 5).times { |i| engine.add_projection(description: "proj #{i}") }
|
|
65
|
+
expect(engine.projections.last.description).to eq("proj #{constants::MAX_PROJECTIONS + 4}")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe '#expand_horizon!' do
|
|
70
|
+
it 'increases current_horizon' do
|
|
71
|
+
before = engine.current_horizon
|
|
72
|
+
engine.expand_horizon!
|
|
73
|
+
expect(engine.current_horizon).to be > before
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'increases by HORIZON_EXPAND by default' do
|
|
77
|
+
before = engine.current_horizon
|
|
78
|
+
engine.expand_horizon!
|
|
79
|
+
expect(engine.current_horizon).to eq((before + constants::HORIZON_EXPAND).clamp(constants::MIN_HORIZON, constants::MAX_HORIZON))
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'accepts a custom amount' do
|
|
83
|
+
before = engine.current_horizon
|
|
84
|
+
engine.expand_horizon!(amount: 0.2)
|
|
85
|
+
expect(engine.current_horizon).to eq((before + 0.2).clamp(constants::MIN_HORIZON, constants::MAX_HORIZON))
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'does not exceed MAX_HORIZON' do
|
|
89
|
+
engine = described_class.new(initial_horizon: 0.99)
|
|
90
|
+
engine.expand_horizon!(amount: 0.5)
|
|
91
|
+
expect(engine.current_horizon).to eq(constants::MAX_HORIZON)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'returns the new horizon value' do
|
|
95
|
+
result = engine.expand_horizon!
|
|
96
|
+
expect(result).to eq(engine.current_horizon)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe '#contract_horizon!' do
|
|
101
|
+
it 'decreases current_horizon' do
|
|
102
|
+
before = engine.current_horizon
|
|
103
|
+
engine.contract_horizon!
|
|
104
|
+
expect(engine.current_horizon).to be < before
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'decreases by HORIZON_CONTRACT by default' do
|
|
108
|
+
before = engine.current_horizon
|
|
109
|
+
engine.contract_horizon!
|
|
110
|
+
expect(engine.current_horizon).to eq((before - constants::HORIZON_CONTRACT).clamp(constants::MIN_HORIZON, constants::MAX_HORIZON))
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'does not go below MIN_HORIZON' do
|
|
114
|
+
e = described_class.new(initial_horizon: constants::MIN_HORIZON)
|
|
115
|
+
e.contract_horizon!(amount: 0.5)
|
|
116
|
+
expect(e.current_horizon).to eq(constants::MIN_HORIZON)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'returns the new horizon value' do
|
|
120
|
+
result = engine.contract_horizon!
|
|
121
|
+
expect(result).to eq(engine.current_horizon)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe '#apply_stress!' do
|
|
126
|
+
it 'sets stress_level' do
|
|
127
|
+
engine.apply_stress!(0.5)
|
|
128
|
+
expect(engine.stress_level).to eq(0.5)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'reduces current_horizon proportionally' do
|
|
132
|
+
before = engine.current_horizon
|
|
133
|
+
engine.apply_stress!(1.0)
|
|
134
|
+
expect(engine.current_horizon).to be <= before
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'clamps stress to 0..1' do
|
|
138
|
+
engine.apply_stress!(2.0)
|
|
139
|
+
expect(engine.stress_level).to eq(1.0)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'clamps stress below 0.0 to 0.0' do
|
|
143
|
+
engine.apply_stress!(-0.5)
|
|
144
|
+
expect(engine.stress_level).to eq(0.0)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'ensures horizon does not go below MIN_HORIZON under max stress' do
|
|
148
|
+
engine.apply_stress!(1.0)
|
|
149
|
+
expect(engine.current_horizon).to be >= constants::MIN_HORIZON
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'returns the new horizon value' do
|
|
153
|
+
result = engine.apply_stress!(0.3)
|
|
154
|
+
expect(result).to be_a(Float)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
describe '#relieve_stress!' do
|
|
159
|
+
before { engine.apply_stress!(0.6) }
|
|
160
|
+
|
|
161
|
+
it 'reduces stress_level' do
|
|
162
|
+
before = engine.stress_level
|
|
163
|
+
engine.relieve_stress!
|
|
164
|
+
expect(engine.stress_level).to be < before
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'accepts custom amount' do
|
|
168
|
+
engine.relieve_stress!(amount: 0.3)
|
|
169
|
+
expect(engine.stress_level).to be_within(0.001).of(0.3)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it 'does not go below 0.0' do
|
|
173
|
+
engine.relieve_stress!(amount: 10.0)
|
|
174
|
+
expect(engine.stress_level).to eq(0.0)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
describe '#effective_horizon' do
|
|
179
|
+
it 'equals current_horizon when stress is zero' do
|
|
180
|
+
expect(engine.effective_horizon).to eq(engine.current_horizon)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it 'is less than current_horizon when stressed' do
|
|
184
|
+
engine.apply_stress!(0.5)
|
|
185
|
+
# after apply_stress! current_horizon already contracted;
|
|
186
|
+
# effective_horizon contracts further based on residual stress
|
|
187
|
+
expect(engine.effective_horizon).to be <= engine.current_horizon
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it 'never goes below MIN_HORIZON' do
|
|
191
|
+
engine.apply_stress!(1.0)
|
|
192
|
+
expect(engine.effective_horizon).to be >= constants::MIN_HORIZON
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
describe '#projections_within_horizon' do
|
|
197
|
+
before do
|
|
198
|
+
engine.add_projection(description: 'near', horizon_distance: 0.2)
|
|
199
|
+
engine.add_projection(description: 'at horizon', horizon_distance: engine.effective_horizon)
|
|
200
|
+
engine.add_projection(description: 'far', horizon_distance: 0.99)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'returns projections at or within effective_horizon' do
|
|
204
|
+
within = engine.projections_within_horizon
|
|
205
|
+
within.each { |p| expect(p.horizon_distance).to be <= engine.effective_horizon }
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
it 'excludes projections beyond effective_horizon' do
|
|
209
|
+
within = engine.projections_within_horizon
|
|
210
|
+
descriptions = within.map(&:description)
|
|
211
|
+
expect(descriptions).not_to include('far')
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
describe '#beyond_horizon_projections' do
|
|
216
|
+
before do
|
|
217
|
+
engine.add_projection(description: 'near', horizon_distance: 0.1)
|
|
218
|
+
engine.add_projection(description: 'far', horizon_distance: 0.99)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it 'returns projections beyond effective_horizon' do
|
|
222
|
+
beyond = engine.beyond_horizon_projections
|
|
223
|
+
beyond.each { |p| expect(p.horizon_distance).to be > engine.effective_horizon }
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
describe '#nearest_projections' do
|
|
228
|
+
before do
|
|
229
|
+
[0.9, 0.1, 0.5, 0.3, 0.7].each { |d| engine.add_projection(description: "p#{d}", horizon_distance: d) }
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it 'returns num nearest by horizon_distance' do
|
|
233
|
+
result = engine.nearest_projections(num: 3)
|
|
234
|
+
expect(result.size).to eq(3)
|
|
235
|
+
expect(result.map(&:horizon_distance)).to eq([0.1, 0.3, 0.5])
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it 'defaults to 5' do
|
|
239
|
+
result = engine.nearest_projections
|
|
240
|
+
expect(result.size).to eq(5)
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
describe '#farthest_projections' do
|
|
245
|
+
before do
|
|
246
|
+
[0.9, 0.1, 0.5, 0.3, 0.7].each { |d| engine.add_projection(description: "p#{d}", horizon_distance: d) }
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it 'returns num farthest in descending order' do
|
|
250
|
+
result = engine.farthest_projections(num: 2)
|
|
251
|
+
expect(result.map(&:horizon_distance)).to eq([0.9, 0.7])
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
describe '#construal_label' do
|
|
256
|
+
it 'returns a symbol' do
|
|
257
|
+
expect(engine.construal_label).to be_a(Symbol)
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
it 'returns :concrete for low effective horizon' do
|
|
261
|
+
e = described_class.new(initial_horizon: 0.15)
|
|
262
|
+
expect(e.construal_label).to eq(:concrete)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it 'returns :abstract for high effective horizon' do
|
|
266
|
+
e = described_class.new(initial_horizon: 0.95)
|
|
267
|
+
expect(e.construal_label).to eq(:abstract)
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
describe '#horizon_report' do
|
|
272
|
+
let(:report) { engine.horizon_report }
|
|
273
|
+
|
|
274
|
+
it 'includes current_horizon' do
|
|
275
|
+
expect(report).to have_key(:current_horizon)
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
it 'includes stress_level' do
|
|
279
|
+
expect(report).to have_key(:stress_level)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
it 'includes effective_horizon' do
|
|
283
|
+
expect(report).to have_key(:effective_horizon)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
it 'includes construal_label' do
|
|
287
|
+
expect(report).to have_key(:construal_label)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
it 'includes horizon_level' do
|
|
291
|
+
expect(report).to have_key(:horizon_level)
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
it 'includes total_projections' do
|
|
295
|
+
expect(report).to have_key(:total_projections)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
it 'includes within_horizon count' do
|
|
299
|
+
expect(report).to have_key(:within_horizon)
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
it 'includes beyond_horizon count' do
|
|
303
|
+
expect(report).to have_key(:beyond_horizon)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
it 'rounds values to 10 places' do
|
|
307
|
+
expect(report[:current_horizon]).to be_a(Float)
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
describe '#to_h' do
|
|
312
|
+
it 'includes projections array' do
|
|
313
|
+
engine.add_projection(description: 'test')
|
|
314
|
+
h = engine.to_h
|
|
315
|
+
expect(h[:projections]).to be_an(Array)
|
|
316
|
+
expect(h[:projections].size).to eq(1)
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
it 'includes report fields' do
|
|
320
|
+
h = engine.to_h
|
|
321
|
+
expect(h).to have_key(:current_horizon)
|
|
322
|
+
expect(h).to have_key(:construal_label)
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Horizon::Helpers::Projection do
|
|
4
|
+
let(:proj) { described_class.new(description: 'Deploy new feature', domain: :code, horizon_distance: 0.4) }
|
|
5
|
+
|
|
6
|
+
describe '#initialize' do
|
|
7
|
+
it 'assigns a UUID id' do
|
|
8
|
+
expect(proj.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'sets description' do
|
|
12
|
+
expect(proj.description).to eq('Deploy new feature')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'sets domain' do
|
|
16
|
+
expect(proj.domain).to eq(:code)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'sets horizon_distance' do
|
|
20
|
+
expect(proj.horizon_distance).to eq(0.4)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'defaults confidence to 1.0' do
|
|
24
|
+
expect(proj.confidence).to eq(1.0)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'sets created_at' do
|
|
28
|
+
expect(proj.created_at).to be_a(Time)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'clamps horizon_distance above 1.0 to 1.0' do
|
|
32
|
+
p = described_class.new(description: 'x', horizon_distance: 1.5)
|
|
33
|
+
expect(p.horizon_distance).to eq(1.0)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'clamps horizon_distance below 0.0 to 0.0' do
|
|
37
|
+
p = described_class.new(description: 'x', horizon_distance: -0.5)
|
|
38
|
+
expect(p.horizon_distance).to eq(0.0)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'clamps confidence above 1.0 to 1.0' do
|
|
42
|
+
p = described_class.new(description: 'x', confidence: 2.0)
|
|
43
|
+
expect(p.confidence).to eq(1.0)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'clamps confidence below 0.0 to 0.0' do
|
|
47
|
+
p = described_class.new(description: 'x', confidence: -0.1)
|
|
48
|
+
expect(p.confidence).to eq(0.0)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'accepts explicit construal_level' do
|
|
52
|
+
p = described_class.new(description: 'x', construal_level: :abstract)
|
|
53
|
+
expect(p.construal_level).to eq(:abstract)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#concrete?' do
|
|
58
|
+
it 'returns true for distance <= 0.3' do
|
|
59
|
+
p = described_class.new(description: 'x', horizon_distance: 0.2)
|
|
60
|
+
expect(p.concrete?).to be true
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'returns true at exactly 0.3' do
|
|
64
|
+
p = described_class.new(description: 'x', horizon_distance: 0.3)
|
|
65
|
+
expect(p.concrete?).to be true
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'returns false for distance > 0.3' do
|
|
69
|
+
p = described_class.new(description: 'x', horizon_distance: 0.5)
|
|
70
|
+
expect(p.concrete?).to be false
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe '#abstract?' do
|
|
75
|
+
it 'returns true for distance >= 0.7' do
|
|
76
|
+
p = described_class.new(description: 'x', horizon_distance: 0.8)
|
|
77
|
+
expect(p.abstract?).to be true
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'returns true at exactly 0.7' do
|
|
81
|
+
p = described_class.new(description: 'x', horizon_distance: 0.7)
|
|
82
|
+
expect(p.abstract?).to be true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'returns false for distance < 0.7' do
|
|
86
|
+
p = described_class.new(description: 'x', horizon_distance: 0.5)
|
|
87
|
+
expect(p.abstract?).to be false
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe '#construal_level derived' do
|
|
92
|
+
it 'derives :concrete for distance 0.1' do
|
|
93
|
+
p = described_class.new(description: 'x', horizon_distance: 0.1)
|
|
94
|
+
expect(p.construal_level).to eq(:concrete)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'derives :balanced for distance 0.5' do
|
|
98
|
+
p = described_class.new(description: 'x', horizon_distance: 0.5)
|
|
99
|
+
expect(p.construal_level).to eq(:balanced)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'derives :abstract for distance 0.9' do
|
|
103
|
+
p = described_class.new(description: 'x', horizon_distance: 0.9)
|
|
104
|
+
expect(p.construal_level).to eq(:abstract)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe '#to_h' do
|
|
109
|
+
let(:h) { proj.to_h }
|
|
110
|
+
|
|
111
|
+
it 'includes id' do
|
|
112
|
+
expect(h[:id]).to eq(proj.id)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'includes description' do
|
|
116
|
+
expect(h[:description]).to eq('Deploy new feature')
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'includes domain' do
|
|
120
|
+
expect(h[:domain]).to eq(:code)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'includes horizon_distance rounded to 10 places' do
|
|
124
|
+
expect(h[:horizon_distance]).to eq(proj.horizon_distance.round(10))
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'includes confidence rounded to 10 places' do
|
|
128
|
+
expect(h[:confidence]).to eq(proj.confidence.round(10))
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'includes construal_level' do
|
|
132
|
+
expect(h[:construal_level]).to be_a(Symbol)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'includes concrete flag' do
|
|
136
|
+
expect(h).to have_key(:concrete)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'includes abstract flag' do
|
|
140
|
+
expect(h).to have_key(:abstract)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it 'includes created_at' do
|
|
144
|
+
expect(h[:created_at]).to be_a(Time)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
describe 'unique IDs' do
|
|
149
|
+
it 'generates different IDs for different projections' do
|
|
150
|
+
p1 = described_class.new(description: 'a')
|
|
151
|
+
p2 = described_class.new(description: 'b')
|
|
152
|
+
expect(p1.id).not_to eq(p2.id)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|