lex-agentic-executive 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-executive.gemspec +30 -0
- data/lib/legion/extensions/agentic/executive/autopilot/client.rb +19 -0
- data/lib/legion/extensions/agentic/executive/autopilot/helpers/autopilot_engine.rb +161 -0
- data/lib/legion/extensions/agentic/executive/autopilot/helpers/constants.rb +62 -0
- data/lib/legion/extensions/agentic/executive/autopilot/helpers/mode_event.rb +51 -0
- data/lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb +91 -0
- data/lib/legion/extensions/agentic/executive/autopilot/runners/cognitive_autopilot.rb +93 -0
- data/lib/legion/extensions/agentic/executive/autopilot/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/autopilot.rb +20 -0
- data/lib/legion/extensions/agentic/executive/chunking/client.rb +21 -0
- data/lib/legion/extensions/agentic/executive/chunking/helpers/chunk.rb +92 -0
- data/lib/legion/extensions/agentic/executive/chunking/helpers/chunking_engine.rb +147 -0
- data/lib/legion/extensions/agentic/executive/chunking/helpers/constants.rb +56 -0
- data/lib/legion/extensions/agentic/executive/chunking/helpers/information_item.rb +51 -0
- data/lib/legion/extensions/agentic/executive/chunking/runners/cognitive_chunking.rb +111 -0
- data/lib/legion/extensions/agentic/executive/chunking/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/chunking.rb +21 -0
- data/lib/legion/extensions/agentic/executive/cognitive_debt/client.rb +28 -0
- data/lib/legion/extensions/agentic/executive/cognitive_debt/helpers/constants.rb +36 -0
- data/lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_engine.rb +118 -0
- data/lib/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item.rb +83 -0
- data/lib/legion/extensions/agentic/executive/cognitive_debt/runners/cognitive_debt.rb +84 -0
- data/lib/legion/extensions/agentic/executive/cognitive_debt/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/cognitive_debt.rb +19 -0
- data/lib/legion/extensions/agentic/executive/compass/client.rb +15 -0
- data/lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb +79 -0
- data/lib/legion/extensions/agentic/executive/compass/helpers/compass_engine.rb +108 -0
- data/lib/legion/extensions/agentic/executive/compass/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/executive/compass/helpers/magnetic_bias.rb +81 -0
- data/lib/legion/extensions/agentic/executive/compass/runners/cognitive_compass.rb +76 -0
- data/lib/legion/extensions/agentic/executive/compass/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/compass.rb +22 -0
- data/lib/legion/extensions/agentic/executive/control/client.rb +19 -0
- data/lib/legion/extensions/agentic/executive/control/helpers/constants.rb +45 -0
- data/lib/legion/extensions/agentic/executive/control/helpers/control_signal.rb +79 -0
- data/lib/legion/extensions/agentic/executive/control/helpers/controller.rb +140 -0
- data/lib/legion/extensions/agentic/executive/control/helpers/goal.rb +72 -0
- data/lib/legion/extensions/agentic/executive/control/runners/cognitive_control.rb +74 -0
- data/lib/legion/extensions/agentic/executive/control/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/control.rb +21 -0
- data/lib/legion/extensions/agentic/executive/decision_fatigue/client.rb +28 -0
- data/lib/legion/extensions/agentic/executive/decision_fatigue/helpers/constants.rb +51 -0
- data/lib/legion/extensions/agentic/executive/decision_fatigue/helpers/decision_record.rb +50 -0
- data/lib/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine.rb +114 -0
- data/lib/legion/extensions/agentic/executive/decision_fatigue/runners/decision_fatigue.rb +94 -0
- data/lib/legion/extensions/agentic/executive/decision_fatigue/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/decision_fatigue.rb +19 -0
- data/lib/legion/extensions/agentic/executive/disengagement/client.rb +24 -0
- data/lib/legion/extensions/agentic/executive/disengagement/helpers/constants.rb +48 -0
- data/lib/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine.rb +101 -0
- data/lib/legion/extensions/agentic/executive/disengagement/helpers/goal.rb +105 -0
- data/lib/legion/extensions/agentic/executive/disengagement/runners/cognitive_disengagement.rb +90 -0
- data/lib/legion/extensions/agentic/executive/disengagement/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/disengagement.rb +19 -0
- data/lib/legion/extensions/agentic/executive/dissonance_resolution/client.rb +19 -0
- data/lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/constants.rb +38 -0
- data/lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict.rb +90 -0
- data/lib/legion/extensions/agentic/executive/dissonance_resolution/helpers/resolution_engine.rb +155 -0
- data/lib/legion/extensions/agentic/executive/dissonance_resolution/runners/cognitive_dissonance_resolution.rb +74 -0
- data/lib/legion/extensions/agentic/executive/dissonance_resolution/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/dissonance_resolution.rb +19 -0
- data/lib/legion/extensions/agentic/executive/dual_process/client.rb +25 -0
- data/lib/legion/extensions/agentic/executive/dual_process/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/executive/dual_process/helpers/decision.rb +50 -0
- data/lib/legion/extensions/agentic/executive/dual_process/helpers/dual_process_engine.rb +200 -0
- data/lib/legion/extensions/agentic/executive/dual_process/helpers/heuristic.rb +67 -0
- data/lib/legion/extensions/agentic/executive/dual_process/runners/dual_process.rb +87 -0
- data/lib/legion/extensions/agentic/executive/dual_process/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/dual_process.rb +20 -0
- data/lib/legion/extensions/agentic/executive/dwell/client.rb +19 -0
- data/lib/legion/extensions/agentic/executive/dwell/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/executive/dwell/helpers/dwell_engine.rb +126 -0
- data/lib/legion/extensions/agentic/executive/dwell/helpers/dwell_topic.rb +119 -0
- data/lib/legion/extensions/agentic/executive/dwell/runners/cognitive_dwell.rb +87 -0
- data/lib/legion/extensions/agentic/executive/dwell/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/dwell.rb +19 -0
- data/lib/legion/extensions/agentic/executive/executive_function/actors/recovery.rb +45 -0
- data/lib/legion/extensions/agentic/executive/executive_function/client.rb +27 -0
- data/lib/legion/extensions/agentic/executive/executive_function/helpers/ef_component.rb +58 -0
- data/lib/legion/extensions/agentic/executive/executive_function/helpers/executive_controller.rb +129 -0
- data/lib/legion/extensions/agentic/executive/executive_function/runners/executive_function.rb +104 -0
- data/lib/legion/extensions/agentic/executive/executive_function/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/executive_function.rb +18 -0
- data/lib/legion/extensions/agentic/executive/flexibility/actors/tick.rb +31 -0
- data/lib/legion/extensions/agentic/executive/flexibility/client.rb +28 -0
- data/lib/legion/extensions/agentic/executive/flexibility/helpers/constants.rb +39 -0
- data/lib/legion/extensions/agentic/executive/flexibility/helpers/flexibility_engine.rb +109 -0
- data/lib/legion/extensions/agentic/executive/flexibility/helpers/task_set.rb +69 -0
- data/lib/legion/extensions/agentic/executive/flexibility/runners/cognitive_flexibility.rb +77 -0
- data/lib/legion/extensions/agentic/executive/flexibility/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/flexibility.rb +19 -0
- data/lib/legion/extensions/agentic/executive/flexibility_training/client.rb +29 -0
- data/lib/legion/extensions/agentic/executive/flexibility_training/helpers/constants.rb +57 -0
- data/lib/legion/extensions/agentic/executive/flexibility_training/helpers/flexibility_engine.rb +178 -0
- data/lib/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial.rb +54 -0
- data/lib/legion/extensions/agentic/executive/flexibility_training/helpers/training_task.rb +54 -0
- data/lib/legion/extensions/agentic/executive/flexibility_training/runners/cognitive_flexibility_training.rb +134 -0
- data/lib/legion/extensions/agentic/executive/flexibility_training/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/flexibility_training.rb +20 -0
- data/lib/legion/extensions/agentic/executive/goal_management/client.rb +28 -0
- data/lib/legion/extensions/agentic/executive/goal_management/helpers/constants.rb +49 -0
- data/lib/legion/extensions/agentic/executive/goal_management/helpers/goal.rb +153 -0
- data/lib/legion/extensions/agentic/executive/goal_management/helpers/goal_engine.rb +265 -0
- data/lib/legion/extensions/agentic/executive/goal_management/runners/goal_management.rb +169 -0
- data/lib/legion/extensions/agentic/executive/goal_management/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/goal_management.rb +19 -0
- data/lib/legion/extensions/agentic/executive/inertia/client.rb +15 -0
- data/lib/legion/extensions/agentic/executive/inertia/helpers/belief.rb +99 -0
- data/lib/legion/extensions/agentic/executive/inertia/helpers/constants.rb +45 -0
- data/lib/legion/extensions/agentic/executive/inertia/helpers/inertia_engine.rb +111 -0
- data/lib/legion/extensions/agentic/executive/inertia/runners/cognitive_inertia.rb +74 -0
- data/lib/legion/extensions/agentic/executive/inertia/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/inertia.rb +19 -0
- data/lib/legion/extensions/agentic/executive/inhibition/client.rb +27 -0
- data/lib/legion/extensions/agentic/executive/inhibition/helpers/constants.rb +36 -0
- data/lib/legion/extensions/agentic/executive/inhibition/helpers/impulse.rb +37 -0
- data/lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model.rb +122 -0
- data/lib/legion/extensions/agentic/executive/inhibition/helpers/inhibition_store.rb +72 -0
- data/lib/legion/extensions/agentic/executive/inhibition/runners/inhibition.rb +155 -0
- data/lib/legion/extensions/agentic/executive/inhibition/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/inhibition.rb +20 -0
- data/lib/legion/extensions/agentic/executive/load/client.rb +25 -0
- data/lib/legion/extensions/agentic/executive/load/helpers/constants.rb +36 -0
- data/lib/legion/extensions/agentic/executive/load/helpers/load_model.rb +146 -0
- data/lib/legion/extensions/agentic/executive/load/runners/cognitive_load.rb +120 -0
- data/lib/legion/extensions/agentic/executive/load/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/load.rb +18 -0
- data/lib/legion/extensions/agentic/executive/load_balancing/client.rb +19 -0
- data/lib/legion/extensions/agentic/executive/load_balancing/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/executive/load_balancing/helpers/load_balancer.rb +137 -0
- data/lib/legion/extensions/agentic/executive/load_balancing/helpers/subsystem.rb +101 -0
- data/lib/legion/extensions/agentic/executive/load_balancing/runners/cognitive_load_balancing.rb +69 -0
- data/lib/legion/extensions/agentic/executive/load_balancing/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/load_balancing.rb +19 -0
- data/lib/legion/extensions/agentic/executive/planning/client.rb +27 -0
- data/lib/legion/extensions/agentic/executive/planning/helpers/constants.rb +26 -0
- data/lib/legion/extensions/agentic/executive/planning/helpers/plan.rb +110 -0
- data/lib/legion/extensions/agentic/executive/planning/helpers/plan_step.rb +82 -0
- data/lib/legion/extensions/agentic/executive/planning/helpers/plan_store.rb +161 -0
- data/lib/legion/extensions/agentic/executive/planning/runners/planning.rb +123 -0
- data/lib/legion/extensions/agentic/executive/planning/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/planning.rb +20 -0
- data/lib/legion/extensions/agentic/executive/prospective_memory/client.rb +28 -0
- data/lib/legion/extensions/agentic/executive/prospective_memory/helpers/constants.rb +32 -0
- data/lib/legion/extensions/agentic/executive/prospective_memory/helpers/intention.rb +94 -0
- data/lib/legion/extensions/agentic/executive/prospective_memory/helpers/prospective_engine.rb +157 -0
- data/lib/legion/extensions/agentic/executive/prospective_memory/runners/prospective_memory.rb +146 -0
- data/lib/legion/extensions/agentic/executive/prospective_memory/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/prospective_memory.rb +19 -0
- data/lib/legion/extensions/agentic/executive/triage/client.rb +19 -0
- data/lib/legion/extensions/agentic/executive/triage/helpers/constants.rb +70 -0
- data/lib/legion/extensions/agentic/executive/triage/helpers/demand.rb +101 -0
- data/lib/legion/extensions/agentic/executive/triage/helpers/triage_engine.rb +150 -0
- data/lib/legion/extensions/agentic/executive/triage/runners/cognitive_triage.rb +110 -0
- data/lib/legion/extensions/agentic/executive/triage/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/triage.rb +19 -0
- data/lib/legion/extensions/agentic/executive/version.rb +11 -0
- data/lib/legion/extensions/agentic/executive/volition/client.rb +27 -0
- data/lib/legion/extensions/agentic/executive/volition/helpers/constants.rb +51 -0
- data/lib/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer.rb +158 -0
- data/lib/legion/extensions/agentic/executive/volition/helpers/intention.rb +56 -0
- data/lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb +140 -0
- data/lib/legion/extensions/agentic/executive/volition/runners/volition.rb +129 -0
- data/lib/legion/extensions/agentic/executive/volition/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/volition.rb +20 -0
- data/lib/legion/extensions/agentic/executive/working_memory/client.rb +21 -0
- data/lib/legion/extensions/agentic/executive/working_memory/helpers/buffer.rb +124 -0
- data/lib/legion/extensions/agentic/executive/working_memory/helpers/buffer_item.rb +72 -0
- data/lib/legion/extensions/agentic/executive/working_memory/helpers/constants.rb +47 -0
- data/lib/legion/extensions/agentic/executive/working_memory/runners/working_memory.rb +102 -0
- data/lib/legion/extensions/agentic/executive/working_memory/version.rb +13 -0
- data/lib/legion/extensions/agentic/executive/working_memory.rb +19 -0
- data/lib/legion/extensions/agentic/executive.rb +40 -0
- data/spec/legion/extensions/agentic/executive/autopilot/client_spec.rb +21 -0
- data/spec/legion/extensions/agentic/executive/autopilot/cognitive_autopilot_spec.rb +7 -0
- data/spec/legion/extensions/agentic/executive/autopilot/helpers/autopilot_engine_spec.rb +166 -0
- data/spec/legion/extensions/agentic/executive/autopilot/helpers/constants_spec.rb +37 -0
- data/spec/legion/extensions/agentic/executive/autopilot/helpers/mode_event_spec.rb +30 -0
- data/spec/legion/extensions/agentic/executive/autopilot/helpers/routine_spec.rb +133 -0
- data/spec/legion/extensions/agentic/executive/autopilot/runners_spec.rb +108 -0
- data/spec/legion/extensions/agentic/executive/chunking/client_spec.rb +67 -0
- data/spec/legion/extensions/agentic/executive/chunking/helpers/chunk_spec.rb +187 -0
- data/spec/legion/extensions/agentic/executive/chunking/helpers/chunking_engine_spec.rb +290 -0
- data/spec/legion/extensions/agentic/executive/chunking/helpers/constants_spec.rb +116 -0
- data/spec/legion/extensions/agentic/executive/chunking/helpers/information_item_spec.rb +75 -0
- data/spec/legion/extensions/agentic/executive/chunking/runners/cognitive_chunking_spec.rb +169 -0
- data/spec/legion/extensions/agentic/executive/cognitive_debt/client_spec.rb +73 -0
- data/spec/legion/extensions/agentic/executive/cognitive_debt/cognitive_debt_spec.rb +15 -0
- data/spec/legion/extensions/agentic/executive/cognitive_debt/helpers/constants_spec.rb +78 -0
- data/spec/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_engine_spec.rb +297 -0
- data/spec/legion/extensions/agentic/executive/cognitive_debt/helpers/debt_item_spec.rb +233 -0
- data/spec/legion/extensions/agentic/executive/cognitive_debt/runners/cognitive_debt_spec.rb +196 -0
- data/spec/legion/extensions/agentic/executive/compass/client_spec.rb +16 -0
- data/spec/legion/extensions/agentic/executive/compass/helpers/bearing_spec.rb +93 -0
- data/spec/legion/extensions/agentic/executive/compass/helpers/compass_engine_spec.rb +113 -0
- data/spec/legion/extensions/agentic/executive/compass/helpers/constants_spec.rb +45 -0
- data/spec/legion/extensions/agentic/executive/compass/helpers/magnetic_bias_spec.rb +103 -0
- data/spec/legion/extensions/agentic/executive/compass/runners/cognitive_compass_spec.rb +80 -0
- data/spec/legion/extensions/agentic/executive/control/client_spec.rb +23 -0
- data/spec/legion/extensions/agentic/executive/control/helpers/control_signal_spec.rb +118 -0
- data/spec/legion/extensions/agentic/executive/control/helpers/controller_spec.rb +167 -0
- data/spec/legion/extensions/agentic/executive/control/helpers/goal_spec.rb +99 -0
- data/spec/legion/extensions/agentic/executive/control/runners/cognitive_control_spec.rb +107 -0
- data/spec/legion/extensions/agentic/executive/decision_fatigue/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/executive/decision_fatigue/helpers/constants_spec.rb +93 -0
- data/spec/legion/extensions/agentic/executive/decision_fatigue/helpers/decision_record_spec.rb +89 -0
- data/spec/legion/extensions/agentic/executive/decision_fatigue/helpers/fatigue_engine_spec.rb +216 -0
- data/spec/legion/extensions/agentic/executive/decision_fatigue/runners/decision_fatigue_spec.rb +180 -0
- data/spec/legion/extensions/agentic/executive/disengagement/helpers/constants_spec.rb +81 -0
- data/spec/legion/extensions/agentic/executive/disengagement/helpers/disengagement_engine_spec.rb +213 -0
- data/spec/legion/extensions/agentic/executive/disengagement/helpers/goal_spec.rb +289 -0
- data/spec/legion/extensions/agentic/executive/disengagement/runners/cognitive_disengagement_spec.rb +215 -0
- data/spec/legion/extensions/agentic/executive/dissonance_resolution/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/executive/dissonance_resolution/helpers/dissonance_conflict_spec.rb +107 -0
- data/spec/legion/extensions/agentic/executive/dissonance_resolution/helpers/resolution_engine_spec.rb +122 -0
- data/spec/legion/extensions/agentic/executive/dissonance_resolution/runners/cognitive_dissonance_resolution_spec.rb +49 -0
- data/spec/legion/extensions/agentic/executive/dual_process/client_spec.rb +74 -0
- data/spec/legion/extensions/agentic/executive/dual_process/helpers/constants_spec.rb +55 -0
- data/spec/legion/extensions/agentic/executive/dual_process/helpers/decision_spec.rb +76 -0
- data/spec/legion/extensions/agentic/executive/dual_process/helpers/dual_process_engine_spec.rb +274 -0
- data/spec/legion/extensions/agentic/executive/dual_process/helpers/heuristic_spec.rb +144 -0
- data/spec/legion/extensions/agentic/executive/dual_process/runners/dual_process_spec.rb +188 -0
- data/spec/legion/extensions/agentic/executive/dwell/cognitive_dwell_spec.rb +7 -0
- data/spec/legion/extensions/agentic/executive/dwell/helpers/dwell_engine_spec.rb +136 -0
- data/spec/legion/extensions/agentic/executive/dwell/helpers/dwell_topic_spec.rb +152 -0
- data/spec/legion/extensions/agentic/executive/executive_function/client_spec.rb +40 -0
- data/spec/legion/extensions/agentic/executive/executive_function/helpers/ef_component_spec.rb +108 -0
- data/spec/legion/extensions/agentic/executive/executive_function/helpers/executive_controller_spec.rb +136 -0
- data/spec/legion/extensions/agentic/executive/executive_function/runners/executive_function_spec.rb +191 -0
- data/spec/legion/extensions/agentic/executive/flexibility/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/executive/flexibility/helpers/flexibility_engine_spec.rb +119 -0
- data/spec/legion/extensions/agentic/executive/flexibility/helpers/task_set_spec.rb +87 -0
- data/spec/legion/extensions/agentic/executive/flexibility/runners/cognitive_flexibility_spec.rb +69 -0
- data/spec/legion/extensions/agentic/executive/flexibility_training/client_spec.rb +39 -0
- data/spec/legion/extensions/agentic/executive/flexibility_training/helpers/constants_spec.rb +67 -0
- data/spec/legion/extensions/agentic/executive/flexibility_training/helpers/flexibility_engine_spec.rb +209 -0
- data/spec/legion/extensions/agentic/executive/flexibility_training/helpers/switch_trial_spec.rb +77 -0
- data/spec/legion/extensions/agentic/executive/flexibility_training/helpers/training_task_spec.rb +97 -0
- data/spec/legion/extensions/agentic/executive/flexibility_training/runners/cognitive_flexibility_training_spec.rb +171 -0
- data/spec/legion/extensions/agentic/executive/goal_management/client_spec.rb +34 -0
- data/spec/legion/extensions/agentic/executive/goal_management/goal_management_spec.rb +11 -0
- data/spec/legion/extensions/agentic/executive/goal_management/helpers/constants_spec.rb +94 -0
- data/spec/legion/extensions/agentic/executive/goal_management/helpers/goal_engine_spec.rb +358 -0
- data/spec/legion/extensions/agentic/executive/goal_management/helpers/goal_spec.rb +283 -0
- data/spec/legion/extensions/agentic/executive/goal_management/runners/goal_management_spec.rb +244 -0
- data/spec/legion/extensions/agentic/executive/inertia/helpers/belief_spec.rb +128 -0
- data/spec/legion/extensions/agentic/executive/inertia/helpers/inertia_engine_spec.rb +104 -0
- data/spec/legion/extensions/agentic/executive/inertia/runners/cognitive_inertia_spec.rb +59 -0
- data/spec/legion/extensions/agentic/executive/inhibition/client_spec.rb +43 -0
- data/spec/legion/extensions/agentic/executive/inhibition/helpers/constants_spec.rb +108 -0
- data/spec/legion/extensions/agentic/executive/inhibition/helpers/impulse_spec.rb +101 -0
- data/spec/legion/extensions/agentic/executive/inhibition/helpers/inhibition_model_spec.rb +245 -0
- data/spec/legion/extensions/agentic/executive/inhibition/helpers/inhibition_store_spec.rb +126 -0
- data/spec/legion/extensions/agentic/executive/inhibition/runners/inhibition_spec.rb +242 -0
- data/spec/legion/extensions/agentic/executive/load/client_spec.rb +94 -0
- data/spec/legion/extensions/agentic/executive/load/helpers/constants_spec.rb +62 -0
- data/spec/legion/extensions/agentic/executive/load/helpers/load_model_spec.rb +314 -0
- data/spec/legion/extensions/agentic/executive/load/runners/cognitive_load_spec.rb +231 -0
- data/spec/legion/extensions/agentic/executive/load_balancing/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/executive/load_balancing/helpers/load_balancer_spec.rb +106 -0
- data/spec/legion/extensions/agentic/executive/load_balancing/helpers/subsystem_spec.rb +106 -0
- data/spec/legion/extensions/agentic/executive/load_balancing/runners/cognitive_load_balancing_spec.rb +52 -0
- data/spec/legion/extensions/agentic/executive/planning/client_spec.rb +91 -0
- data/spec/legion/extensions/agentic/executive/planning/helpers/constants_spec.rb +91 -0
- data/spec/legion/extensions/agentic/executive/planning/helpers/plan_spec.rb +230 -0
- data/spec/legion/extensions/agentic/executive/planning/helpers/plan_step_spec.rb +159 -0
- data/spec/legion/extensions/agentic/executive/planning/helpers/plan_store_spec.rb +317 -0
- data/spec/legion/extensions/agentic/executive/planning/runners/planning_spec.rb +217 -0
- data/spec/legion/extensions/agentic/executive/prospective_memory/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/executive/prospective_memory/helpers/constants_spec.rb +84 -0
- data/spec/legion/extensions/agentic/executive/prospective_memory/helpers/intention_spec.rb +194 -0
- data/spec/legion/extensions/agentic/executive/prospective_memory/helpers/prospective_engine_spec.rb +255 -0
- data/spec/legion/extensions/agentic/executive/prospective_memory/runners/prospective_memory_spec.rb +220 -0
- data/spec/legion/extensions/agentic/executive/triage/client_spec.rb +28 -0
- data/spec/legion/extensions/agentic/executive/triage/cognitive_triage_spec.rb +7 -0
- data/spec/legion/extensions/agentic/executive/triage/helpers/constants_spec.rb +41 -0
- data/spec/legion/extensions/agentic/executive/triage/helpers/demand_spec.rb +139 -0
- data/spec/legion/extensions/agentic/executive/triage/helpers/triage_engine_spec.rb +183 -0
- data/spec/legion/extensions/agentic/executive/triage/runners_spec.rb +127 -0
- data/spec/legion/extensions/agentic/executive/volition/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/executive/volition/helpers/drive_synthesizer_spec.rb +99 -0
- data/spec/legion/extensions/agentic/executive/volition/helpers/intention_spec.rb +93 -0
- data/spec/legion/extensions/agentic/executive/volition/helpers/intention_stack_spec.rb +129 -0
- data/spec/legion/extensions/agentic/executive/volition/runners/volition_spec.rb +135 -0
- data/spec/legion/extensions/agentic/executive/working_memory/client_spec.rb +93 -0
- data/spec/legion/extensions/agentic/executive/working_memory/helpers/buffer_item_spec.rb +185 -0
- data/spec/legion/extensions/agentic/executive/working_memory/helpers/buffer_spec.rb +232 -0
- data/spec/legion/extensions/agentic/executive/working_memory/helpers/constants_spec.rb +99 -0
- data/spec/legion/extensions/agentic/executive/working_memory/runners/working_memory_spec.rb +191 -0
- data/spec/spec_helper.rb +46 -0
- metadata +380 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Executive
|
|
7
|
+
module LoadBalancing
|
|
8
|
+
module Helpers
|
|
9
|
+
class LoadBalancer
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@subsystems = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def register_subsystem(name:, subsystem_type: :general, capacity: DEFAULT_CAPACITY)
|
|
17
|
+
prune_if_needed
|
|
18
|
+
subsystem = Subsystem.new(
|
|
19
|
+
name: name,
|
|
20
|
+
subsystem_type: subsystem_type,
|
|
21
|
+
capacity: capacity
|
|
22
|
+
)
|
|
23
|
+
@subsystems[subsystem.id] = subsystem
|
|
24
|
+
subsystem
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def assign_load(subsystem_id:, amount:)
|
|
28
|
+
subsystem = @subsystems[subsystem_id]
|
|
29
|
+
return nil unless subsystem
|
|
30
|
+
|
|
31
|
+
subsystem.add_load!(amount: amount)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def shed_load(subsystem_id:, amount:)
|
|
35
|
+
subsystem = @subsystems[subsystem_id]
|
|
36
|
+
return nil unless subsystem
|
|
37
|
+
|
|
38
|
+
subsystem.shed_load!(amount: amount)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def auto_assign(amount:, subsystem_type: nil)
|
|
42
|
+
candidates = if subsystem_type
|
|
43
|
+
@subsystems.values.select { |s| s.subsystem_type == subsystem_type.to_sym }
|
|
44
|
+
else
|
|
45
|
+
@subsystems.values
|
|
46
|
+
end
|
|
47
|
+
return nil if candidates.empty?
|
|
48
|
+
|
|
49
|
+
best = candidates.min_by(&:utilization)
|
|
50
|
+
best.add_load!(amount: amount)
|
|
51
|
+
best
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def rebalance
|
|
55
|
+
overloaded = @subsystems.values.select(&:overloaded?)
|
|
56
|
+
underloaded = @subsystems.values.select(&:underloaded?)
|
|
57
|
+
transfers = 0
|
|
58
|
+
|
|
59
|
+
overloaded.each do |over|
|
|
60
|
+
target = underloaded.min_by(&:utilization)
|
|
61
|
+
break unless target
|
|
62
|
+
|
|
63
|
+
transfer_amount = [REBALANCE_STEP, over.current_load * 0.2].min
|
|
64
|
+
shed = over.shed_load!(amount: transfer_amount)
|
|
65
|
+
target.add_load!(amount: shed)
|
|
66
|
+
transfers += 1
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
transfers
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def overloaded_subsystems
|
|
73
|
+
@subsystems.values.select(&:overloaded?)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def underloaded_subsystems
|
|
77
|
+
@subsystems.values.select(&:underloaded?)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def subsystems_by_type(subsystem_type:)
|
|
81
|
+
st = subsystem_type.to_sym
|
|
82
|
+
@subsystems.values.select { |s| s.subsystem_type == st }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def most_loaded(limit: 5)
|
|
86
|
+
@subsystems.values.sort_by { |s| -s.utilization }.first(limit)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def overall_utilization
|
|
90
|
+
return 0.0 if @subsystems.empty?
|
|
91
|
+
|
|
92
|
+
utils = @subsystems.values.map(&:utilization)
|
|
93
|
+
(utils.sum / utils.size).round(10)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def overall_health
|
|
97
|
+
return 1.0 if @subsystems.empty?
|
|
98
|
+
|
|
99
|
+
healths = @subsystems.values.map(&:health)
|
|
100
|
+
(healths.sum / healths.size).round(10)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def balance_report
|
|
104
|
+
{
|
|
105
|
+
total_subsystems: @subsystems.size,
|
|
106
|
+
overloaded_count: overloaded_subsystems.size,
|
|
107
|
+
underloaded_count: underloaded_subsystems.size,
|
|
108
|
+
overall_utilization: overall_utilization,
|
|
109
|
+
overall_health: overall_health,
|
|
110
|
+
most_loaded: most_loaded(limit: 3).map(&:to_h)
|
|
111
|
+
}
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def to_h
|
|
115
|
+
{
|
|
116
|
+
total_subsystems: @subsystems.size,
|
|
117
|
+
overall_utilization: overall_utilization,
|
|
118
|
+
overall_health: overall_health,
|
|
119
|
+
overloaded_count: overloaded_subsystems.size
|
|
120
|
+
}
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
def prune_if_needed
|
|
126
|
+
return if @subsystems.size < MAX_SUBSYSTEMS
|
|
127
|
+
|
|
128
|
+
least_used = @subsystems.values.min_by(&:tasks_processed)
|
|
129
|
+
@subsystems.delete(least_used.id) if least_used
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Executive
|
|
9
|
+
module LoadBalancing
|
|
10
|
+
module Helpers
|
|
11
|
+
class Subsystem
|
|
12
|
+
include Constants
|
|
13
|
+
|
|
14
|
+
attr_reader :id, :name, :subsystem_type, :capacity, :current_load,
|
|
15
|
+
:tasks_processed, :tasks_shed, :created_at
|
|
16
|
+
|
|
17
|
+
def initialize(name:, subsystem_type: :general, capacity: DEFAULT_CAPACITY)
|
|
18
|
+
@id = SecureRandom.uuid
|
|
19
|
+
@name = name
|
|
20
|
+
@subsystem_type = subsystem_type.to_sym
|
|
21
|
+
@capacity = capacity.to_f.clamp(0.1, 5.0)
|
|
22
|
+
@current_load = 0.0
|
|
23
|
+
@tasks_processed = 0
|
|
24
|
+
@tasks_shed = 0
|
|
25
|
+
@created_at = Time.now.utc
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def utilization
|
|
29
|
+
return 0.0 if @capacity.zero?
|
|
30
|
+
|
|
31
|
+
(@current_load / @capacity).clamp(0.0, 1.5).round(10)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def load_label
|
|
35
|
+
match = LOAD_LABELS.find { |range, _| range.cover?(utilization) }
|
|
36
|
+
match ? match.last : :overloaded
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def overloaded?
|
|
40
|
+
utilization >= OVERLOAD_THRESHOLD
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def underloaded?
|
|
44
|
+
utilization <= UNDERLOAD_THRESHOLD
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def health
|
|
48
|
+
if overloaded?
|
|
49
|
+
[1.0 - ((utilization - OVERLOAD_THRESHOLD) * 3), 0.0].max.round(10)
|
|
50
|
+
else
|
|
51
|
+
1.0
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def health_label
|
|
56
|
+
match = HEALTH_LABELS.find { |range, _| range.cover?(health) }
|
|
57
|
+
match ? match.last : :failing
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def add_load!(amount:)
|
|
61
|
+
@current_load = (@current_load + amount.to_f).clamp(0.0, @capacity * 1.5).round(10)
|
|
62
|
+
@tasks_processed += 1
|
|
63
|
+
self
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def shed_load!(amount:)
|
|
67
|
+
removed = [amount.to_f, @current_load].min
|
|
68
|
+
@current_load = (@current_load - removed).clamp(0.0, @capacity * 1.5).round(10)
|
|
69
|
+
@tasks_shed += 1
|
|
70
|
+
removed
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def available_capacity
|
|
74
|
+
[(@capacity - @current_load), 0.0].max.round(10)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def to_h
|
|
78
|
+
{
|
|
79
|
+
id: @id,
|
|
80
|
+
name: @name,
|
|
81
|
+
subsystem_type: @subsystem_type,
|
|
82
|
+
capacity: @capacity,
|
|
83
|
+
current_load: @current_load,
|
|
84
|
+
utilization: utilization,
|
|
85
|
+
load_label: load_label,
|
|
86
|
+
overloaded: overloaded?,
|
|
87
|
+
health: health,
|
|
88
|
+
health_label: health_label,
|
|
89
|
+
available_capacity: available_capacity,
|
|
90
|
+
tasks_processed: @tasks_processed,
|
|
91
|
+
tasks_shed: @tasks_shed,
|
|
92
|
+
created_at: @created_at
|
|
93
|
+
}
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
data/lib/legion/extensions/agentic/executive/load_balancing/runners/cognitive_load_balancing.rb
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Executive
|
|
7
|
+
module LoadBalancing
|
|
8
|
+
module Runners
|
|
9
|
+
module CognitiveLoadBalancing
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
11
|
+
|
|
12
|
+
def register_cognitive_subsystem(name:, subsystem_type: :general,
|
|
13
|
+
capacity: nil, **)
|
|
14
|
+
cap = capacity || Helpers::Constants::DEFAULT_CAPACITY
|
|
15
|
+
sub = engine.register_subsystem(name: name, subsystem_type: subsystem_type,
|
|
16
|
+
capacity: cap)
|
|
17
|
+
{ success: true }.merge(sub.to_h)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def assign_cognitive_load(subsystem_id:, amount:, **)
|
|
21
|
+
result = engine.assign_load(subsystem_id: subsystem_id, amount: amount)
|
|
22
|
+
return { success: false, error: 'subsystem not found' } unless result
|
|
23
|
+
|
|
24
|
+
{ success: true }.merge(result.to_h)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def shed_cognitive_load(subsystem_id:, amount:, **)
|
|
28
|
+
result = engine.shed_load(subsystem_id: subsystem_id, amount: amount)
|
|
29
|
+
return { success: false, error: 'subsystem not found' } unless result
|
|
30
|
+
|
|
31
|
+
{ success: true, shed: result }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def auto_assign_load(amount:, subsystem_type: nil, **)
|
|
35
|
+
result = engine.auto_assign(amount: amount, subsystem_type: subsystem_type)
|
|
36
|
+
return { success: false, error: 'no available subsystem' } unless result
|
|
37
|
+
|
|
38
|
+
{ success: true, assigned_to: result.name }.merge(result.to_h)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def rebalance_cognitive_load(**)
|
|
42
|
+
transfers = engine.rebalance
|
|
43
|
+
{ success: true, transfers: transfers, stats: engine.to_h }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def overloaded_subsystems_report(**)
|
|
47
|
+
subs = engine.overloaded_subsystems
|
|
48
|
+
{ success: true, count: subs.size, subsystems: subs.map(&:to_h) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def most_loaded_report(limit: 5, **)
|
|
52
|
+
subs = engine.most_loaded(limit: limit)
|
|
53
|
+
{ success: true, limit: limit, subsystems: subs.map(&:to_h) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def cognitive_load_balance_report(**)
|
|
57
|
+
engine.balance_report
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def cognitive_load_balancing_stats(**)
|
|
61
|
+
engine.to_h
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'load_balancing/version'
|
|
4
|
+
require_relative 'load_balancing/helpers/constants'
|
|
5
|
+
require_relative 'load_balancing/helpers/subsystem'
|
|
6
|
+
require_relative 'load_balancing/helpers/load_balancer'
|
|
7
|
+
require_relative 'load_balancing/runners/cognitive_load_balancing'
|
|
8
|
+
require_relative 'load_balancing/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module Agentic
|
|
13
|
+
module Executive
|
|
14
|
+
module LoadBalancing
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/executive/planning/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/executive/planning/helpers/plan_step'
|
|
5
|
+
require 'legion/extensions/agentic/executive/planning/helpers/plan'
|
|
6
|
+
require 'legion/extensions/agentic/executive/planning/helpers/plan_store'
|
|
7
|
+
require 'legion/extensions/agentic/executive/planning/runners/planning'
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Agentic
|
|
12
|
+
module Executive
|
|
13
|
+
module Planning
|
|
14
|
+
class Client
|
|
15
|
+
include Runners::Planning
|
|
16
|
+
|
|
17
|
+
attr_reader :plan_store
|
|
18
|
+
|
|
19
|
+
def initialize(plan_store: nil, **)
|
|
20
|
+
@plan_store = plan_store || Helpers::PlanStore.new
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Executive
|
|
7
|
+
module Planning
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
PLAN_STATUSES = %i[forming active executing completed failed abandoned].freeze
|
|
11
|
+
STEP_STATUSES = %i[pending active completed failed skipped blocked].freeze
|
|
12
|
+
PRIORITIES = { critical: 1.0, high: 0.75, medium: 0.5, low: 0.25 }.freeze
|
|
13
|
+
MAX_PLANS = 50
|
|
14
|
+
MAX_STEPS_PER_PLAN = 100
|
|
15
|
+
MAX_CONTINGENCIES = 20
|
|
16
|
+
REPLAN_LIMIT = 3
|
|
17
|
+
STALE_PLAN_THRESHOLD = 3600
|
|
18
|
+
COMPLETION_THRESHOLD = 0.95
|
|
19
|
+
PLANNING_HORIZON = 10
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Executive
|
|
9
|
+
module Planning
|
|
10
|
+
module Helpers
|
|
11
|
+
class Plan
|
|
12
|
+
attr_reader :id, :goal, :description, :priority, :steps, :contingencies,
|
|
13
|
+
:parent_plan_id, :created_at, :replan_count
|
|
14
|
+
attr_accessor :status, :updated_at
|
|
15
|
+
|
|
16
|
+
def initialize(goal:, steps: [], priority: :medium, contingencies: {}, parent_plan_id: nil, description: nil, **)
|
|
17
|
+
@id = SecureRandom.uuid
|
|
18
|
+
@goal = goal
|
|
19
|
+
@description = description
|
|
20
|
+
@priority = priority
|
|
21
|
+
@status = :forming
|
|
22
|
+
@steps = steps.dup
|
|
23
|
+
@contingencies = contingencies.dup
|
|
24
|
+
@parent_plan_id = parent_plan_id
|
|
25
|
+
@created_at = Time.now.utc
|
|
26
|
+
@updated_at = Time.now.utc
|
|
27
|
+
@replan_count = 0
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def progress
|
|
31
|
+
return 0.0 if @steps.empty?
|
|
32
|
+
|
|
33
|
+
done = @steps.count { |s| %i[completed skipped].include?(s.status) }
|
|
34
|
+
done.to_f / @steps.size
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def active_step
|
|
38
|
+
@steps.find { |s| s.status == :active }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def completed_step_ids
|
|
42
|
+
@steps.select { |s| %i[completed skipped].include?(s.status) }.map(&:id)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def advance!(step_id, result: nil)
|
|
46
|
+
step = @steps.find { |s| s.id == step_id }
|
|
47
|
+
return nil unless step
|
|
48
|
+
|
|
49
|
+
step.complete!(result: result)
|
|
50
|
+
@updated_at = Time.now.utc
|
|
51
|
+
@status = :completed if progress >= Constants::COMPLETION_THRESHOLD
|
|
52
|
+
step
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def fail_step!(step_id, reason: nil)
|
|
56
|
+
step = @steps.find { |s| s.id == step_id }
|
|
57
|
+
return nil unless step
|
|
58
|
+
|
|
59
|
+
step.fail!(reason: reason)
|
|
60
|
+
@updated_at = Time.now.utc
|
|
61
|
+
step
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def complete?
|
|
65
|
+
@status == :completed || progress >= Constants::COMPLETION_THRESHOLD
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def failed?
|
|
69
|
+
@status == :failed
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def stale?
|
|
73
|
+
(Time.now.utc - @updated_at) > Constants::STALE_PLAN_THRESHOLD
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def increment_replan!
|
|
77
|
+
@replan_count += 1
|
|
78
|
+
@updated_at = Time.now.utc
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def replace_remaining_steps!(new_steps)
|
|
82
|
+
pending = @steps.reject { |s| %i[completed skipped failed].include?(s.status) }
|
|
83
|
+
pending.each { |s| @steps.delete(s) }
|
|
84
|
+
new_steps.each { |s| @steps << s }
|
|
85
|
+
@updated_at = Time.now.utc
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def to_h
|
|
89
|
+
{
|
|
90
|
+
id: @id,
|
|
91
|
+
goal: @goal,
|
|
92
|
+
description: @description,
|
|
93
|
+
priority: @priority,
|
|
94
|
+
status: @status,
|
|
95
|
+
progress: progress.round(4),
|
|
96
|
+
steps: @steps.map(&:to_h),
|
|
97
|
+
contingencies: @contingencies,
|
|
98
|
+
parent_plan_id: @parent_plan_id,
|
|
99
|
+
replan_count: @replan_count,
|
|
100
|
+
created_at: @created_at,
|
|
101
|
+
updated_at: @updated_at
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Executive
|
|
9
|
+
module Planning
|
|
10
|
+
module Helpers
|
|
11
|
+
class PlanStep
|
|
12
|
+
attr_reader :id, :action, :description, :depends_on, :estimated_effort,
|
|
13
|
+
:started_at, :completed_at, :result
|
|
14
|
+
attr_accessor :status, :actual_effort
|
|
15
|
+
|
|
16
|
+
def initialize(action:, description: nil, depends_on: [], estimated_effort: 1, **)
|
|
17
|
+
@id = SecureRandom.uuid
|
|
18
|
+
@action = action
|
|
19
|
+
@description = description
|
|
20
|
+
@status = :pending
|
|
21
|
+
@depends_on = Array(depends_on).dup
|
|
22
|
+
@estimated_effort = estimated_effort
|
|
23
|
+
@actual_effort = nil
|
|
24
|
+
@result = nil
|
|
25
|
+
@started_at = nil
|
|
26
|
+
@completed_at = nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def ready?(completed_step_ids)
|
|
30
|
+
return false if %i[completed failed skipped].include?(@status)
|
|
31
|
+
|
|
32
|
+
@depends_on.all? { |dep_id| completed_step_ids.include?(dep_id) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def duration
|
|
36
|
+
return nil unless @started_at && @completed_at
|
|
37
|
+
|
|
38
|
+
@completed_at - @started_at
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def blocked?
|
|
42
|
+
@status == :blocked
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def complete!(result: nil)
|
|
46
|
+
@status = :completed
|
|
47
|
+
@result = result
|
|
48
|
+
@completed_at = Time.now.utc
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def fail!(reason: nil)
|
|
52
|
+
@status = :failed
|
|
53
|
+
@result = { reason: reason }
|
|
54
|
+
@completed_at = Time.now.utc
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def start!
|
|
58
|
+
@status = :active
|
|
59
|
+
@started_at = Time.now.utc
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def to_h
|
|
63
|
+
{
|
|
64
|
+
id: @id,
|
|
65
|
+
action: @action,
|
|
66
|
+
description: @description,
|
|
67
|
+
status: @status,
|
|
68
|
+
depends_on: @depends_on,
|
|
69
|
+
estimated_effort: @estimated_effort,
|
|
70
|
+
actual_effort: @actual_effort,
|
|
71
|
+
result: @result,
|
|
72
|
+
started_at: @started_at,
|
|
73
|
+
completed_at: @completed_at
|
|
74
|
+
}
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|