Class: Legion::Extensions::Agentic::Defense::Friction::Helpers::StateTransition
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Friction::Helpers::StateTransition
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb
Constant Summary
Constants included from Constants
Constants::DEFAULT_FRICTION, Constants::FRICTION_BOOST, Constants::FRICTION_DECAY, Constants::FRICTION_LABELS, Constants::INERTIA_THRESHOLD, Constants::MAX_TRANSITIONS, Constants::MOMENTUM_THRESHOLD, Constants::STATE_TYPES, Constants::TRANSITION_OUTCOMES
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#force_applied ⇒ Object
readonly
Returns the value of attribute force_applied.
-
#friction ⇒ Object
readonly
Returns the value of attribute friction.
-
#from_state ⇒ Object
readonly
Returns the value of attribute from_state.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#outcome ⇒ Object
readonly
Returns the value of attribute outcome.
-
#to_state ⇒ Object
readonly
Returns the value of attribute to_state.
Instance Method Summary collapse
- #attempt!(force: 0.5) ⇒ Object
- #completed? ⇒ Boolean
- #force!(force: 1.0) ⇒ Object
- #friction_label ⇒ Object
-
#initialize(from_state:, to_state:, friction: DEFAULT_FRICTION) ⇒ StateTransition
constructor
A new instance of StateTransition.
- #to_h ⇒ Object
Constructor Details
#initialize(from_state:, to_state:, friction: DEFAULT_FRICTION) ⇒ StateTransition
Returns a new instance of StateTransition.
17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 17 def initialize(from_state:, to_state:, friction: DEFAULT_FRICTION) @id = SecureRandom.uuid @from_state = from_state.to_sym @to_state = to_state.to_sym @friction = friction.to_f.clamp(0.0, 1.0) @outcome = nil @force_applied = 0.0 @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 14 def created_at @created_at end |
#force_applied ⇒ Object (readonly)
Returns the value of attribute force_applied.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 14 def force_applied @force_applied end |
#friction ⇒ Object (readonly)
Returns the value of attribute friction.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 14 def friction @friction end |
#from_state ⇒ Object (readonly)
Returns the value of attribute from_state.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 14 def from_state @from_state end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 14 def id @id end |
#outcome ⇒ Object (readonly)
Returns the value of attribute outcome.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 14 def outcome @outcome end |
#to_state ⇒ Object (readonly)
Returns the value of attribute to_state.
14 15 16 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 14 def to_state @to_state end |
Instance Method Details
#attempt!(force: 0.5) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 27 def attempt!(force: 0.5) @force_applied = force.to_f.clamp(0.0, 1.0) @outcome = if @force_applied > @friction :completed elsif @force_applied > (@friction * 0.7) :deferred else :resisted end self end |
#completed? ⇒ Boolean
45 46 47 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 45 def completed? %i[completed forced].include?(@outcome) end |
#force!(force: 1.0) ⇒ Object
39 40 41 42 43 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 39 def force!(force: 1.0) @force_applied = force.to_f.clamp(0.0, 1.0) @outcome = :forced self end |
#friction_label ⇒ Object
49 50 51 52 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 49 def friction_label match = FRICTION_LABELS.find { |range, _| range.cover?(@friction) } match ? match.last : :locked end |
#to_h ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/legion/extensions/agentic/defense/friction/helpers/state_transition.rb', line 54 def to_h { id: @id, from_state: @from_state, to_state: @to_state, friction: @friction, friction_label: friction_label, outcome: @outcome, force_applied: @force_applied, completed: completed?, created_at: @created_at } end |