lex-agentic-integration 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-integration.gemspec +30 -0
- data/lib/legion/extensions/agentic/integration/boundary/client.rb +15 -0
- data/lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb +90 -0
- data/lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb +123 -0
- data/lib/legion/extensions/agentic/integration/boundary/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/integration/boundary/runners/cognitive_boundary.rb +100 -0
- data/lib/legion/extensions/agentic/integration/boundary/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/boundary.rb +19 -0
- data/lib/legion/extensions/agentic/integration/context/client.rb +26 -0
- data/lib/legion/extensions/agentic/integration/context/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/integration/context/helpers/context_manager.rb +150 -0
- data/lib/legion/extensions/agentic/integration/context/helpers/frame.rb +99 -0
- data/lib/legion/extensions/agentic/integration/context/runners/context.rb +94 -0
- data/lib/legion/extensions/agentic/integration/context/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/context.rb +19 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/helpers/constants.rb +51 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/helpers/distribution_engine.rb +159 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/helpers/participant.rb +100 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/runners/distributed_cognition.rb +107 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition.rb +19 -0
- data/lib/legion/extensions/agentic/integration/gestalt/client.rb +21 -0
- data/lib/legion/extensions/agentic/integration/gestalt/helpers/constants.rb +51 -0
- data/lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb +90 -0
- data/lib/legion/extensions/agentic/integration/gestalt/helpers/pattern_store.rb +123 -0
- data/lib/legion/extensions/agentic/integration/gestalt/runners/gestalt.rb +82 -0
- data/lib/legion/extensions/agentic/integration/gestalt/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/gestalt.rb +19 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/actors/competition.rb +45 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/client.rb +29 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb +62 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/helpers/competitor.rb +59 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/helpers/workspace.rb +188 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb +104 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/global_workspace.rb +20 -0
- data/lib/legion/extensions/agentic/integration/integration/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/integration/helpers/constants.rb +62 -0
- data/lib/legion/extensions/agentic/integration/integration/helpers/integrated_representation.rb +106 -0
- data/lib/legion/extensions/agentic/integration/integration/helpers/integration_engine.rb +163 -0
- data/lib/legion/extensions/agentic/integration/integration/helpers/modal_signal.rb +62 -0
- data/lib/legion/extensions/agentic/integration/integration/runners/cognitive_integration.rb +105 -0
- data/lib/legion/extensions/agentic/integration/integration/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/integration.rb +20 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/actors/thread_walker.rb +45 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/client.rb +23 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/helpers/constants.rb +39 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/helpers/labyrinth.rb +138 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/helpers/labyrinth_engine.rb +177 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb +64 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/runners/cognitive_labyrinth.rb +128 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/labyrinth.rb +22 -0
- data/lib/legion/extensions/agentic/integration/map/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/integration/map/client.rb +29 -0
- data/lib/legion/extensions/agentic/integration/map/helpers/cognitive_map_store.rb +179 -0
- data/lib/legion/extensions/agentic/integration/map/helpers/constants.rb +71 -0
- data/lib/legion/extensions/agentic/integration/map/helpers/graph_traversal.rb +124 -0
- data/lib/legion/extensions/agentic/integration/map/helpers/location.rb +71 -0
- data/lib/legion/extensions/agentic/integration/map/runners/cognitive_map.rb +95 -0
- data/lib/legion/extensions/agentic/integration/map/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/map.rb +20 -0
- data/lib/legion/extensions/agentic/integration/mosaic/client.rb +15 -0
- data/lib/legion/extensions/agentic/integration/mosaic/helpers/constants.rb +55 -0
- data/lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb +111 -0
- data/lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic_engine.rb +124 -0
- data/lib/legion/extensions/agentic/integration/mosaic/helpers/tessera.rb +86 -0
- data/lib/legion/extensions/agentic/integration/mosaic/runners/cognitive_mosaic.rb +76 -0
- data/lib/legion/extensions/agentic/integration/mosaic/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/mosaic.rb +22 -0
- data/lib/legion/extensions/agentic/integration/mycelium/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/constants.rb +52 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/fruiting_body.rb +50 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb +76 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb +72 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb +151 -0
- data/lib/legion/extensions/agentic/integration/mycelium/runners/cognitive_mycelium.rb +73 -0
- data/lib/legion/extensions/agentic/integration/mycelium/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/mycelium.rb +23 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/client.rb +25 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb +156 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb +72 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/stream.rb +51 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/runners/phenomenal_binding.rb +110 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding.rb +20 -0
- data/lib/legion/extensions/agentic/integration/qualia/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/qualia/helpers/constants.rb +74 -0
- data/lib/legion/extensions/agentic/integration/qualia/helpers/quale.rb +103 -0
- data/lib/legion/extensions/agentic/integration/qualia/helpers/qualia_engine.rb +142 -0
- data/lib/legion/extensions/agentic/integration/qualia/runners/qualia.rb +67 -0
- data/lib/legion/extensions/agentic/integration/qualia/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/qualia.rb +19 -0
- data/lib/legion/extensions/agentic/integration/situation_model/client.rb +28 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/client.rb +23 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/situation_engine.rb +73 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/situation_event.rb +56 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/situation_model.rb +90 -0
- data/lib/legion/extensions/agentic/integration/situation_model/runners/situation_model.rb +99 -0
- data/lib/legion/extensions/agentic/integration/situation_model/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/situation_model.rb +21 -0
- data/lib/legion/extensions/agentic/integration/synthesis/client.rb +29 -0
- data/lib/legion/extensions/agentic/integration/synthesis/helpers/constants.rb +41 -0
- data/lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis.rb +63 -0
- data/lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_engine.rb +213 -0
- data/lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb +67 -0
- data/lib/legion/extensions/agentic/integration/synthesis/runners/cognitive_synthesis.rb +82 -0
- data/lib/legion/extensions/agentic/integration/synthesis/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/synthesis.rb +20 -0
- data/lib/legion/extensions/agentic/integration/tapestry/client.rb +15 -0
- data/lib/legion/extensions/agentic/integration/tapestry/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/integration/tapestry/helpers/loom_engine.rb +125 -0
- data/lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb +144 -0
- data/lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb +112 -0
- data/lib/legion/extensions/agentic/integration/tapestry/runners/cognitive_tapestry.rb +81 -0
- data/lib/legion/extensions/agentic/integration/tapestry/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/tapestry.rb +22 -0
- data/lib/legion/extensions/agentic/integration/tessellation/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/tessellation/helpers/constants.rb +72 -0
- data/lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb +99 -0
- data/lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb +141 -0
- data/lib/legion/extensions/agentic/integration/tessellation/helpers/tile.rb +76 -0
- data/lib/legion/extensions/agentic/integration/tessellation/runners/cognitive_tessellation.rb +58 -0
- data/lib/legion/extensions/agentic/integration/tessellation/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/tessellation.rb +22 -0
- data/lib/legion/extensions/agentic/integration/version.rb +11 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/cognitive_signal.rb +38 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/constants.rb +64 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/trend_window.rb +80 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/zeitgeist_engine.rb +157 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/runners/cognitive_zeitgeist.rb +99 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist.rb +22 -0
- data/lib/legion/extensions/agentic/integration.rb +34 -0
- data/spec/legion/extensions/agentic/integration/boundary/helpers/boundary_engine_spec.rb +165 -0
- data/spec/legion/extensions/agentic/integration/boundary/helpers/boundary_spec.rb +168 -0
- data/spec/legion/extensions/agentic/integration/boundary/helpers/constants_spec.rb +65 -0
- data/spec/legion/extensions/agentic/integration/boundary/runners/cognitive_boundary_spec.rb +111 -0
- data/spec/legion/extensions/agentic/integration/context/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/integration/context/helpers/constants_spec.rb +32 -0
- data/spec/legion/extensions/agentic/integration/context/helpers/context_manager_spec.rb +190 -0
- data/spec/legion/extensions/agentic/integration/context/helpers/frame_spec.rb +164 -0
- data/spec/legion/extensions/agentic/integration/context/runners/context_spec.rb +142 -0
- data/spec/legion/extensions/agentic/integration/distributed_cognition/client_spec.rb +21 -0
- data/spec/legion/extensions/agentic/integration/distributed_cognition/helpers/distribution_engine_spec.rb +149 -0
- data/spec/legion/extensions/agentic/integration/distributed_cognition/helpers/participant_spec.rb +116 -0
- data/spec/legion/extensions/agentic/integration/distributed_cognition/runners/distributed_cognition_spec.rb +102 -0
- data/spec/legion/extensions/agentic/integration/gestalt/client_spec.rb +53 -0
- data/spec/legion/extensions/agentic/integration/gestalt/helpers/constants_spec.rb +27 -0
- data/spec/legion/extensions/agentic/integration/gestalt/helpers/pattern_spec.rb +128 -0
- data/spec/legion/extensions/agentic/integration/gestalt/helpers/pattern_store_spec.rb +155 -0
- data/spec/legion/extensions/agentic/integration/gestalt/runners/gestalt_spec.rb +114 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/client_spec.rb +49 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/helpers/broadcast_spec.rb +83 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/helpers/competitor_spec.rb +84 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/helpers/workspace_spec.rb +174 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/runners/global_workspace_spec.rb +118 -0
- data/spec/legion/extensions/agentic/integration/integration/cognitive_integration_spec.rb +7 -0
- data/spec/legion/extensions/agentic/integration/integration/helpers/integrated_representation_spec.rb +149 -0
- data/spec/legion/extensions/agentic/integration/integration/helpers/integration_engine_spec.rb +191 -0
- data/spec/legion/extensions/agentic/integration/integration/helpers/modal_signal_spec.rb +81 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/client_spec.rb +122 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/cognitive_labyrinth_spec.rb +19 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/helpers/constants_spec.rb +72 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/helpers/labyrinth_engine_spec.rb +222 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/helpers/labyrinth_spec.rb +235 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/helpers/node_spec.rb +157 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/runners/cognitive_labyrinth_spec.rb +209 -0
- data/spec/legion/extensions/agentic/integration/map/client_spec.rb +89 -0
- data/spec/legion/extensions/agentic/integration/map/helpers/cognitive_map_store_spec.rb +321 -0
- data/spec/legion/extensions/agentic/integration/map/helpers/location_spec.rb +165 -0
- data/spec/legion/extensions/agentic/integration/map/runners/cognitive_map_spec.rb +190 -0
- data/spec/legion/extensions/agentic/integration/mosaic/client_spec.rb +16 -0
- data/spec/legion/extensions/agentic/integration/mosaic/helpers/constants_spec.rb +37 -0
- data/spec/legion/extensions/agentic/integration/mosaic/helpers/mosaic_engine_spec.rb +108 -0
- data/spec/legion/extensions/agentic/integration/mosaic/helpers/mosaic_spec.rb +120 -0
- data/spec/legion/extensions/agentic/integration/mosaic/helpers/tessera_spec.rb +92 -0
- data/spec/legion/extensions/agentic/integration/mosaic/runners/cognitive_mosaic_spec.rb +88 -0
- data/spec/legion/extensions/agentic/integration/mycelium/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/integration/mycelium/cognitive_mycelium_spec.rb +7 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/constants_spec.rb +28 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/fruiting_body_spec.rb +33 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/hypha_spec.rb +69 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node_spec.rb +79 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine_spec.rb +136 -0
- data/spec/legion/extensions/agentic/integration/mycelium/runners/cognitive_mycelium_spec.rb +61 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/client_spec.rb +52 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine_spec.rb +290 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit_spec.rb +195 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/helpers/constants_spec.rb +92 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/helpers/stream_spec.rb +128 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/runners/phenomenal_binding_spec.rb +174 -0
- data/spec/legion/extensions/agentic/integration/qualia/client_spec.rb +21 -0
- data/spec/legion/extensions/agentic/integration/qualia/helpers/quale_spec.rb +168 -0
- data/spec/legion/extensions/agentic/integration/qualia/helpers/qualia_engine_spec.rb +174 -0
- data/spec/legion/extensions/agentic/integration/qualia/qualia_spec.rb +7 -0
- data/spec/legion/extensions/agentic/integration/qualia/runners_spec.rb +70 -0
- data/spec/legion/extensions/agentic/integration/situation_model/client_spec.rb +51 -0
- data/spec/legion/extensions/agentic/integration/situation_model/helpers/constants_spec.rb +56 -0
- data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_engine_spec.rb +203 -0
- data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_event_spec.rb +94 -0
- data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_model_spec.rb +235 -0
- data/spec/legion/extensions/agentic/integration/situation_model/runners/situation_model_spec.rb +204 -0
- data/spec/legion/extensions/agentic/integration/synthesis/client_spec.rb +26 -0
- data/spec/legion/extensions/agentic/integration/synthesis/helpers/constants_spec.rb +87 -0
- data/spec/legion/extensions/agentic/integration/synthesis/helpers/synthesis_engine_spec.rb +233 -0
- data/spec/legion/extensions/agentic/integration/synthesis/helpers/synthesis_spec.rb +101 -0
- data/spec/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream_spec.rb +116 -0
- data/spec/legion/extensions/agentic/integration/synthesis/runners/cognitive_synthesis_spec.rb +181 -0
- data/spec/legion/extensions/agentic/integration/tapestry/client_spec.rb +55 -0
- data/spec/legion/extensions/agentic/integration/tapestry/helpers/constants_spec.rb +88 -0
- data/spec/legion/extensions/agentic/integration/tapestry/helpers/loom_engine_spec.rb +225 -0
- data/spec/legion/extensions/agentic/integration/tapestry/helpers/tapestry_spec.rb +229 -0
- data/spec/legion/extensions/agentic/integration/tapestry/helpers/thread_spec.rb +211 -0
- data/spec/legion/extensions/agentic/integration/tapestry/runners/cognitive_tapestry_spec.rb +171 -0
- data/spec/legion/extensions/agentic/integration/tessellation/client_spec.rb +40 -0
- data/spec/legion/extensions/agentic/integration/tessellation/helpers/mosaic_spec.rb +99 -0
- data/spec/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine_spec.rb +145 -0
- data/spec/legion/extensions/agentic/integration/tessellation/helpers/tile_spec.rb +138 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/helpers/cognitive_signal_spec.rb +62 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/helpers/constants_spec.rb +73 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/helpers/trend_window_spec.rb +100 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/helpers/zeitgeist_engine_spec.rb +163 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/runners/cognitive_zeitgeist_spec.rb +165 -0
- data/spec/spec_helper.rb +46 -0
- metadata +320 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Integration::SituationModel::Helpers::Constants do
|
|
4
|
+
it 'defines 5 dimensions' do
|
|
5
|
+
expect(described_class::DIMENSIONS.size).to eq(5)
|
|
6
|
+
expect(described_class::DIMENSIONS).to include(:space, :time, :causation, :intentionality, :protagonist)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'CONTINUITY_LABELS covers the full 0..1 range' do
|
|
10
|
+
[0.0, 0.1, 0.2, 0.3, 0.5, 0.6, 0.8, 0.9, 1.0].each do |v|
|
|
11
|
+
match = described_class::CONTINUITY_LABELS.find { |range, _| range.cover?(v) }
|
|
12
|
+
expect(match).not_to be_nil, "no label for #{v}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'assigns :rupture for very low continuity' do
|
|
17
|
+
label = described_class::CONTINUITY_LABELS.find { |r, _| r.cover?(0.1) }&.last
|
|
18
|
+
expect(label).to eq(:rupture)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'assigns :continuous for high continuity' do
|
|
22
|
+
label = described_class::CONTINUITY_LABELS.find { |r, _| r.cover?(0.9) }&.last
|
|
23
|
+
expect(label).to eq(:continuous)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'assigns :shift for mid-range continuity' do
|
|
27
|
+
label = described_class::CONTINUITY_LABELS.find { |r, _| r.cover?(0.6) }&.last
|
|
28
|
+
expect(label).to eq(:shift)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'MODEL_HEALTH_LABELS covers full range' do
|
|
32
|
+
[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1.0].each do |v|
|
|
33
|
+
match = described_class::MODEL_HEALTH_LABELS.find { |range, _| range.cover?(v) }
|
|
34
|
+
expect(match).not_to be_nil, "no health label for #{v}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'assigns :vivid for coherence >= 0.8' do
|
|
39
|
+
label = described_class::MODEL_HEALTH_LABELS.find { |r, _| r.cover?(0.85) }&.last
|
|
40
|
+
expect(label).to eq(:vivid)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'assigns :collapsed for coherence <= 0.2' do
|
|
44
|
+
label = described_class::MODEL_HEALTH_LABELS.find { |r, _| r.cover?(0.05) }&.last
|
|
45
|
+
expect(label).to eq(:collapsed)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'has sensible numeric constants' do
|
|
49
|
+
expect(described_class::MAX_MODELS).to eq(100)
|
|
50
|
+
expect(described_class::MAX_EVENTS_PER_MODEL).to eq(200)
|
|
51
|
+
expect(described_class::DECAY_RATE).to eq(0.01)
|
|
52
|
+
expect(described_class::DEFAULT_DIMENSION_VALUE).to eq(0.5)
|
|
53
|
+
expect(described_class::COHERENCE_FLOOR).to eq(0.0)
|
|
54
|
+
expect(described_class::COHERENCE_CEILING).to eq(1.0)
|
|
55
|
+
end
|
|
56
|
+
end
|
data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_engine_spec.rb
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEngine do
|
|
4
|
+
let(:engine) { described_class.new }
|
|
5
|
+
|
|
6
|
+
def add_coherent_events(model_id, count)
|
|
7
|
+
count.times do |i|
|
|
8
|
+
engine.add_event_to_model(
|
|
9
|
+
model_id: model_id,
|
|
10
|
+
content: "event #{i}",
|
|
11
|
+
dimension_values: { space: 0.8, time: 0.8, causation: 0.8, intentionality: 0.8, protagonist: 0.8 }
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '#create_model' do
|
|
17
|
+
it 'returns a SituationModel' do
|
|
18
|
+
model = engine.create_model(label: 'test')
|
|
19
|
+
expect(model).to be_a(Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationModel)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'assigns the given label' do
|
|
23
|
+
model = engine.create_model(label: 'narrative_x')
|
|
24
|
+
expect(model.label).to eq('narrative_x')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'stores the model by id' do
|
|
28
|
+
model = engine.create_model(label: 'stored')
|
|
29
|
+
expect(engine.model_coherence(model_id: model.id)).not_to be_nil
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#add_event_to_model' do
|
|
34
|
+
it 'returns the created event' do
|
|
35
|
+
model = engine.create_model(label: 'e')
|
|
36
|
+
event = engine.add_event_to_model(model_id: model.id, content: 'hi')
|
|
37
|
+
expect(event).to be_a(Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEvent)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns nil for unknown model_id' do
|
|
41
|
+
result = engine.add_event_to_model(model_id: 'nonexistent', content: 'x')
|
|
42
|
+
expect(result).to be_nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'grows the model event count' do
|
|
46
|
+
model = engine.create_model(label: 'growing')
|
|
47
|
+
engine.add_event_to_model(model_id: model.id, content: 'first')
|
|
48
|
+
engine.add_event_to_model(model_id: model.id, content: 'second')
|
|
49
|
+
expect(model.events.size).to eq(2)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'passes dimension values to the event' do
|
|
53
|
+
model = engine.create_model(label: 'dims')
|
|
54
|
+
engine.add_event_to_model(model_id: model.id, content: 'test',
|
|
55
|
+
dimension_values: { space: 0.9, time: 0.1, causation: 0.5,
|
|
56
|
+
intentionality: 0.5, protagonist: 0.5 })
|
|
57
|
+
expect(model.events.last.dimension_values[:space]).to be_within(0.001).of(0.9)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '#model_coherence' do
|
|
62
|
+
it 'returns nil for unknown model' do
|
|
63
|
+
expect(engine.model_coherence(model_id: 'bad')).to be_nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'returns 1.0 for empty model' do
|
|
67
|
+
model = engine.create_model(label: 'empty')
|
|
68
|
+
expect(engine.model_coherence(model_id: model.id)).to eq(1.0)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'returns coherence value for model with events' do
|
|
72
|
+
model = engine.create_model(label: 'coh')
|
|
73
|
+
add_coherent_events(model.id, 3)
|
|
74
|
+
expect(engine.model_coherence(model_id: model.id)).to be > 0.8
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe '#find_boundaries' do
|
|
79
|
+
it 'returns nil for unknown model' do
|
|
80
|
+
expect(engine.find_boundaries(model_id: 'bad')).to be_nil
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'returns empty array for highly coherent model' do
|
|
84
|
+
model = engine.create_model(label: 'coherent')
|
|
85
|
+
add_coherent_events(model.id, 3)
|
|
86
|
+
expect(engine.find_boundaries(model_id: model.id, threshold: 0.5)).to be_empty
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'detects discontinuities' do
|
|
90
|
+
model = engine.create_model(label: 'jump')
|
|
91
|
+
engine.add_event_to_model(model_id: model.id, content: 'high',
|
|
92
|
+
dimension_values: { space: 0.9, time: 0.9, causation: 0.9, intentionality: 0.9, protagonist: 0.9 })
|
|
93
|
+
engine.add_event_to_model(model_id: model.id, content: 'low',
|
|
94
|
+
dimension_values: { space: 0.0, time: 0.0, causation: 0.0, intentionality: 0.0, protagonist: 0.0 })
|
|
95
|
+
boundaries = engine.find_boundaries(model_id: model.id, threshold: 0.3)
|
|
96
|
+
expect(boundaries).to include(1)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe '#dimension_trajectory' do
|
|
101
|
+
it 'returns nil for unknown model' do
|
|
102
|
+
expect(engine.dimension_trajectory(model_id: 'bad', dimension: :space)).to be_nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'returns array of values for known dimension' do
|
|
106
|
+
model = engine.create_model(label: 'traj')
|
|
107
|
+
engine.add_event_to_model(model_id: model.id, content: 'a',
|
|
108
|
+
dimension_values: { space: 0.3, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
109
|
+
engine.add_event_to_model(model_id: model.id, content: 'b',
|
|
110
|
+
dimension_values: { space: 0.7, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
111
|
+
traj = engine.dimension_trajectory(model_id: model.id, dimension: :space)
|
|
112
|
+
expect(traj).to eq([0.3, 0.7])
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe '#most_coherent' do
|
|
117
|
+
it 'returns models sorted by coherence desc' do
|
|
118
|
+
m1 = engine.create_model(label: 'low')
|
|
119
|
+
engine.add_event_to_model(model_id: m1.id, content: 'a',
|
|
120
|
+
dimension_values: { space: 0.9, time: 0.9, causation: 0.9, intentionality: 0.9, protagonist: 0.9 })
|
|
121
|
+
engine.add_event_to_model(model_id: m1.id, content: 'b',
|
|
122
|
+
dimension_values: { space: 0.0, time: 0.0, causation: 0.0, intentionality: 0.0, protagonist: 0.0 })
|
|
123
|
+
|
|
124
|
+
m2 = engine.create_model(label: 'high')
|
|
125
|
+
add_coherent_events(m2.id, 3)
|
|
126
|
+
|
|
127
|
+
results = engine.most_coherent(limit: 2)
|
|
128
|
+
expect(results.first.id).to eq(m2.id)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'respects limit' do
|
|
132
|
+
3.times { |i| engine.create_model(label: "m#{i}") }
|
|
133
|
+
expect(engine.most_coherent(limit: 2).size).to eq(2)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
describe '#models_by_label' do
|
|
138
|
+
it 'returns models matching label' do
|
|
139
|
+
engine.create_model(label: 'alpha')
|
|
140
|
+
engine.create_model(label: 'alpha')
|
|
141
|
+
engine.create_model(label: 'beta')
|
|
142
|
+
result = engine.models_by_label(label: 'alpha')
|
|
143
|
+
expect(result.size).to eq(2)
|
|
144
|
+
expect(result.all? { |m| m.label == 'alpha' }).to be(true)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'returns empty array for unknown label' do
|
|
148
|
+
expect(engine.models_by_label(label: 'nope')).to be_empty
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
describe '#decay_all' do
|
|
153
|
+
it 'decays all models' do
|
|
154
|
+
m1 = engine.create_model(label: 'a')
|
|
155
|
+
m2 = engine.create_model(label: 'b')
|
|
156
|
+
engine.add_event_to_model(model_id: m1.id, content: 'e1',
|
|
157
|
+
dimension_values: { space: 0.8, time: 0.8, causation: 0.8, intentionality: 0.8, protagonist: 0.8 })
|
|
158
|
+
engine.add_event_to_model(model_id: m2.id, content: 'e2',
|
|
159
|
+
dimension_values: { space: 0.6, time: 0.6, causation: 0.6, intentionality: 0.6, protagonist: 0.6 })
|
|
160
|
+
|
|
161
|
+
before_m1 = m1.current_state[:space]
|
|
162
|
+
before_m2 = m2.current_state[:space]
|
|
163
|
+
engine.decay_all
|
|
164
|
+
expect(m1.current_state[:space]).to be < before_m1
|
|
165
|
+
expect(m2.current_state[:space]).to be < before_m2
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
describe '#prune_collapsed' do
|
|
170
|
+
it 'removes models with coherence <= 0.1' do
|
|
171
|
+
model = engine.create_model(label: 'collapse')
|
|
172
|
+
# Add maximally discontinuous events repeatedly to drive coherence very low
|
|
173
|
+
5.times do |i|
|
|
174
|
+
engine.add_event_to_model(
|
|
175
|
+
model_id: model.id,
|
|
176
|
+
content: "e#{i}",
|
|
177
|
+
dimension_values: if i.even?
|
|
178
|
+
{ space: 0.0, time: 0.0, causation: 0.0, intentionality: 0.0, protagonist: 0.0 }
|
|
179
|
+
else
|
|
180
|
+
{ space: 1.0, time: 1.0, causation: 1.0, intentionality: 1.0, protagonist: 1.0 }
|
|
181
|
+
end
|
|
182
|
+
)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
coherent_model = engine.create_model(label: 'coherent')
|
|
186
|
+
add_coherent_events(coherent_model.id, 3)
|
|
187
|
+
|
|
188
|
+
engine.prune_collapsed
|
|
189
|
+
# coherent model should survive
|
|
190
|
+
expect(engine.model_coherence(model_id: coherent_model.id)).not_to be_nil
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
describe '#to_h' do
|
|
195
|
+
it 'includes model_count and models' do
|
|
196
|
+
engine.create_model(label: 'x')
|
|
197
|
+
h = engine.to_h
|
|
198
|
+
expect(h[:model_count]).to eq(1)
|
|
199
|
+
expect(h[:models]).to be_an(Array)
|
|
200
|
+
expect(h[:models].size).to eq(1)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_event_spec.rb
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEvent do
|
|
4
|
+
let(:default_dims) { { space: 0.5, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 } }
|
|
5
|
+
let(:event_a) { described_class.new(content: 'hero walks into room', dimension_values: default_dims) }
|
|
6
|
+
let(:event_b) { described_class.new(content: 'hero walks forward', dimension_values: default_dims) }
|
|
7
|
+
|
|
8
|
+
describe '#initialize' do
|
|
9
|
+
it 'stores content' do
|
|
10
|
+
expect(event_a.content).to eq('hero walks into room')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'stores all 5 dimension values' do
|
|
14
|
+
expect(event_a.dimension_values.keys).to contain_exactly(*Legion::Extensions::Agentic::Integration::SituationModel::Helpers::Constants::DIMENSIONS)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'defaults missing dimensions to 0.5' do
|
|
18
|
+
event = described_class.new(content: 'test')
|
|
19
|
+
expect(event.dimension_values[:space]).to eq(0.5)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'clamps dimension values to [0, 1]' do
|
|
23
|
+
event = described_class.new(content: 'test', dimension_values: { space: 1.5, time: -0.3 })
|
|
24
|
+
expect(event.dimension_values[:space]).to eq(1.0)
|
|
25
|
+
expect(event.dimension_values[:time]).to eq(0.0)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'records created_at timestamp' do
|
|
29
|
+
expect(event_a.created_at).to be_a(Time)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#continuity_with' do
|
|
34
|
+
it 'returns 1.0 for identical events' do
|
|
35
|
+
expect(event_a.continuity_with(event_b)).to be_within(0.001).of(1.0)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'returns 0.0 when all dimensions are maximally different' do
|
|
39
|
+
e1 = described_class.new(content: 'a', dimension_values: { space: 0.0, time: 0.0, causation: 0.0, intentionality: 0.0, protagonist: 0.0 })
|
|
40
|
+
e2 = described_class.new(content: 'b', dimension_values: { space: 1.0, time: 1.0, causation: 1.0, intentionality: 1.0, protagonist: 1.0 })
|
|
41
|
+
expect(e1.continuity_with(e2)).to be_within(0.001).of(0.0)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'returns intermediate value for partial differences' do
|
|
45
|
+
e1 = described_class.new(content: 'a', dimension_values: { space: 0.0, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
46
|
+
e2 = described_class.new(content: 'b', dimension_values: { space: 1.0, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
47
|
+
# Only space differs by 1.0, avg diff = 1.0/5 = 0.2, continuity = 0.8
|
|
48
|
+
expect(e1.continuity_with(e2)).to be_within(0.001).of(0.8)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'is symmetric' do
|
|
52
|
+
e1 = described_class.new(content: 'x', dimension_values: { space: 0.2, time: 0.8, causation: 0.5, intentionality: 0.3, protagonist: 0.7 })
|
|
53
|
+
e2 = described_class.new(content: 'y', dimension_values: { space: 0.6, time: 0.4, causation: 0.9, intentionality: 0.1, protagonist: 0.5 })
|
|
54
|
+
expect(e1.continuity_with(e2)).to be_within(0.001).of(e2.continuity_with(e1))
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe '#discontinuous_dimensions' do
|
|
59
|
+
it 'returns empty for identical events' do
|
|
60
|
+
expect(event_a.discontinuous_dimensions(event_b)).to be_empty
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'returns dimensions that exceed threshold' do
|
|
64
|
+
e1 = described_class.new(content: 'a', dimension_values: { space: 0.0, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
65
|
+
e2 = described_class.new(content: 'b', dimension_values: { space: 0.8, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
66
|
+
result = e1.discontinuous_dimensions(e2, threshold: 0.3)
|
|
67
|
+
expect(result).to include(:space)
|
|
68
|
+
expect(result).not_to include(:time, :causation, :intentionality, :protagonist)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'uses threshold 0.3 by default' do
|
|
72
|
+
e1 = described_class.new(content: 'a', dimension_values: { space: 0.0, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
73
|
+
e2 = described_class.new(content: 'b', dimension_values: { space: 0.5, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
74
|
+
# space differs by 0.5 > 0.3
|
|
75
|
+
expect(e1.discontinuous_dimensions(e2)).to include(:space)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'respects custom threshold' do
|
|
79
|
+
e1 = described_class.new(content: 'a', dimension_values: { space: 0.0, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
80
|
+
e2 = described_class.new(content: 'b', dimension_values: { space: 0.4, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 })
|
|
81
|
+
# space diff = 0.4, with threshold 0.5 should NOT be discontinuous
|
|
82
|
+
expect(e1.discontinuous_dimensions(e2, threshold: 0.5)).not_to include(:space)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#to_h' do
|
|
87
|
+
it 'includes content, dimension_values, and created_at' do
|
|
88
|
+
h = event_a.to_h
|
|
89
|
+
expect(h[:content]).to eq('hero walks into room')
|
|
90
|
+
expect(h[:dimension_values]).to be_a(Hash)
|
|
91
|
+
expect(h[:created_at]).to be_a(String)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_model_spec.rb
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationModel do
|
|
4
|
+
let(:model) { described_class.new(label: 'test_narrative') }
|
|
5
|
+
|
|
6
|
+
let(:event_a) do
|
|
7
|
+
Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEvent.new(
|
|
8
|
+
content: 'opening scene',
|
|
9
|
+
dimension_values: { space: 0.8, time: 0.8, causation: 0.8, intentionality: 0.8, protagonist: 0.8 }
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:event_b) do
|
|
14
|
+
Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEvent.new(
|
|
15
|
+
content: 'continuing scene',
|
|
16
|
+
dimension_values: { space: 0.8, time: 0.9, causation: 0.8, intentionality: 0.7, protagonist: 0.8 }
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let(:event_distant) do
|
|
21
|
+
Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEvent.new(
|
|
22
|
+
content: 'teleport scene',
|
|
23
|
+
dimension_values: { space: 0.0, time: 0.0, causation: 0.0, intentionality: 0.0, protagonist: 0.0 }
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '#initialize' do
|
|
28
|
+
it 'assigns a UUID id' do
|
|
29
|
+
expect(model.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'stores label' do
|
|
33
|
+
expect(model.label).to eq('test_narrative')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'starts with empty events' do
|
|
37
|
+
expect(model.events).to be_empty
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'initializes current_state with default values' do
|
|
41
|
+
Legion::Extensions::Agentic::Integration::SituationModel::Helpers::Constants::DIMENSIONS.each do |dim|
|
|
42
|
+
expect(model.current_state[dim]).to eq(0.5)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe '#add_event' do
|
|
48
|
+
it 'appends event to events array' do
|
|
49
|
+
model.add_event(event_a)
|
|
50
|
+
expect(model.events.size).to eq(1)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'returns 1.0 for first event (no previous)' do
|
|
54
|
+
result = model.add_event(event_a)
|
|
55
|
+
expect(result).to eq(1.0)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'returns continuity score for subsequent events' do
|
|
59
|
+
model.add_event(event_a)
|
|
60
|
+
result = model.add_event(event_b)
|
|
61
|
+
expect(result).to be_a(Float)
|
|
62
|
+
expect(result).to be_between(0.0, 1.0)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'updates current_state to the new event dimension values' do
|
|
66
|
+
model.add_event(event_a)
|
|
67
|
+
expect(model.current_state[:space]).to be_within(0.001).of(0.8)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'updates last_updated_at' do
|
|
71
|
+
original = model.last_updated_at
|
|
72
|
+
sleep(0.01)
|
|
73
|
+
model.add_event(event_a)
|
|
74
|
+
expect(model.last_updated_at).to be >= original
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe '#coherence' do
|
|
79
|
+
it 'returns 1.0 for empty model' do
|
|
80
|
+
expect(model.coherence).to eq(1.0)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'returns 1.0 for single event' do
|
|
84
|
+
model.add_event(event_a)
|
|
85
|
+
expect(model.coherence).to eq(1.0)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'returns high coherence for similar events' do
|
|
89
|
+
model.add_event(event_a)
|
|
90
|
+
model.add_event(event_b)
|
|
91
|
+
expect(model.coherence).to be > 0.8
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'returns lower coherence for dissimilar events' do
|
|
95
|
+
model.add_event(event_a)
|
|
96
|
+
model.add_event(event_distant)
|
|
97
|
+
expect(model.coherence).to be < 0.5
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'is between 0 and 1' do
|
|
101
|
+
model.add_event(event_a)
|
|
102
|
+
model.add_event(event_b)
|
|
103
|
+
model.add_event(event_distant)
|
|
104
|
+
expect(model.coherence).to be_between(0.0, 1.0)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe '#health_label' do
|
|
109
|
+
it 'returns :vivid for fresh model with coherent events' do
|
|
110
|
+
model.add_event(event_a)
|
|
111
|
+
model.add_event(event_b)
|
|
112
|
+
expect(model.health_label).to eq(:vivid)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'returns a known health symbol' do
|
|
116
|
+
labels = %i[vivid clear hazy fading collapsed]
|
|
117
|
+
expect(labels).to include(model.health_label)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe '#dominant_dimension' do
|
|
122
|
+
it 'returns the dimension with highest current_state value' do
|
|
123
|
+
model.add_event(
|
|
124
|
+
Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEvent.new(
|
|
125
|
+
content: 'high space',
|
|
126
|
+
dimension_values: { space: 0.9, time: 0.3, causation: 0.4, intentionality: 0.2, protagonist: 0.1 }
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
expect(model.dominant_dimension).to eq(:space)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
describe '#weakest_dimension' do
|
|
134
|
+
it 'returns the dimension with lowest current_state value' do
|
|
135
|
+
model.add_event(
|
|
136
|
+
Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEvent.new(
|
|
137
|
+
content: 'weak protagonist',
|
|
138
|
+
dimension_values: { space: 0.9, time: 0.8, causation: 0.7, intentionality: 0.6, protagonist: 0.1 }
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
expect(model.weakest_dimension).to eq(:protagonist)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe '#event_boundaries' do
|
|
146
|
+
it 'returns empty array when no boundaries' do
|
|
147
|
+
model.add_event(event_a)
|
|
148
|
+
model.add_event(event_b)
|
|
149
|
+
# Events are similar - expect no or minimal boundaries
|
|
150
|
+
result = model.event_boundaries(threshold: 0.5)
|
|
151
|
+
expect(result).to be_an(Array)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'detects boundaries on large dimension shifts' do
|
|
155
|
+
model.add_event(event_a)
|
|
156
|
+
model.add_event(event_distant)
|
|
157
|
+
# event_distant is all zeros vs event_a all 0.8 - should produce boundary
|
|
158
|
+
boundaries = model.event_boundaries(threshold: 0.3)
|
|
159
|
+
expect(boundaries).to include(1)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'uses threshold 0.3 by default' do
|
|
163
|
+
model.add_event(event_a)
|
|
164
|
+
model.add_event(event_distant)
|
|
165
|
+
boundaries_default = model.event_boundaries
|
|
166
|
+
boundaries_strict = model.event_boundaries(threshold: 0.9)
|
|
167
|
+
# strict threshold should catch fewer boundaries
|
|
168
|
+
expect(boundaries_default.size).to be >= boundaries_strict.size
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe '#dimension_trajectory' do
|
|
173
|
+
it 'returns an array of values for each event' do
|
|
174
|
+
model.add_event(event_a)
|
|
175
|
+
model.add_event(event_b)
|
|
176
|
+
trajectory = model.dimension_trajectory(:space)
|
|
177
|
+
expect(trajectory.size).to eq(2)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'contains the correct values in order' do
|
|
181
|
+
model.add_event(event_a)
|
|
182
|
+
model.add_event(event_b)
|
|
183
|
+
trajectory = model.dimension_trajectory(:space)
|
|
184
|
+
expect(trajectory[0]).to be_within(0.001).of(0.8)
|
|
185
|
+
expect(trajectory[1]).to be_within(0.001).of(0.8)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it 'returns empty for model with no events' do
|
|
189
|
+
expect(model.dimension_trajectory(:time)).to be_empty
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
describe '#decay!' do
|
|
194
|
+
it 'reduces all current_state values by DECAY_RATE' do
|
|
195
|
+
model.add_event(event_a)
|
|
196
|
+
before = model.current_state[:space]
|
|
197
|
+
model.decay!
|
|
198
|
+
expect(model.current_state[:space]).to be_within(0.001).of(before - 0.01)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it 'clamps at 0.0' do
|
|
202
|
+
low_event = Legion::Extensions::Agentic::Integration::SituationModel::Helpers::SituationEvent.new(
|
|
203
|
+
content: 'near zero',
|
|
204
|
+
dimension_values: { space: 0.005, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 }
|
|
205
|
+
)
|
|
206
|
+
model.add_event(low_event)
|
|
207
|
+
model.decay!
|
|
208
|
+
expect(model.current_state[:space]).to be >= 0.0
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it 'applies decay to all 5 dimensions' do
|
|
212
|
+
model.add_event(event_a)
|
|
213
|
+
before = model.current_state.dup
|
|
214
|
+
model.decay!
|
|
215
|
+
Legion::Extensions::Agentic::Integration::SituationModel::Helpers::Constants::DIMENSIONS.each do |dim|
|
|
216
|
+
expect(model.current_state[dim]).to be < before[dim]
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
describe '#to_h' do
|
|
222
|
+
it 'includes all expected keys' do
|
|
223
|
+
h = model.to_h
|
|
224
|
+
%i[id label event_count current_state coherence health_label created_at last_updated_at].each do |k|
|
|
225
|
+
expect(h).to have_key(k)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it 'reflects event count' do
|
|
230
|
+
model.add_event(event_a)
|
|
231
|
+
model.add_event(event_b)
|
|
232
|
+
expect(model.to_h[:event_count]).to eq(2)
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
end
|