lex-agentic-self 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-self.gemspec +31 -0
- data/lib/legion/extensions/agentic/self/agency/client.rb +21 -0
- data/lib/legion/extensions/agentic/self/agency/helpers/constants.rb +77 -0
- data/lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb +136 -0
- data/lib/legion/extensions/agentic/self/agency/helpers/outcome_event.rb +52 -0
- data/lib/legion/extensions/agentic/self/agency/runners/agency.rb +117 -0
- data/lib/legion/extensions/agentic/self/agency/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/agency.rb +19 -0
- data/lib/legion/extensions/agentic/self/anchor/client.rb +15 -0
- data/lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb +92 -0
- data/lib/legion/extensions/agentic/self/anchor/helpers/anchor_engine.rb +123 -0
- data/lib/legion/extensions/agentic/self/anchor/helpers/chain.rb +93 -0
- data/lib/legion/extensions/agentic/self/anchor/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/self/anchor/runners/cognitive_anchor.rb +70 -0
- data/lib/legion/extensions/agentic/self/anchor/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/anchor.rb +22 -0
- data/lib/legion/extensions/agentic/self/anosognosia/client.rb +28 -0
- data/lib/legion/extensions/agentic/self/anosognosia/helpers/anosognosia_engine.rb +153 -0
- data/lib/legion/extensions/agentic/self/anosognosia/helpers/cognitive_deficit.rb +71 -0
- data/lib/legion/extensions/agentic/self/anosognosia/helpers/constants.rb +29 -0
- data/lib/legion/extensions/agentic/self/anosognosia/runners/anosognosia.rb +98 -0
- data/lib/legion/extensions/agentic/self/anosognosia/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/anosognosia.rb +19 -0
- data/lib/legion/extensions/agentic/self/architecture/client.rb +19 -0
- data/lib/legion/extensions/agentic/self/architecture/helpers/architecture_engine.rb +167 -0
- data/lib/legion/extensions/agentic/self/architecture/helpers/connection.rb +57 -0
- data/lib/legion/extensions/agentic/self/architecture/helpers/constants.rb +37 -0
- data/lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb +80 -0
- data/lib/legion/extensions/agentic/self/architecture/runners/cognitive_architecture.rb +125 -0
- data/lib/legion/extensions/agentic/self/architecture/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/architecture.rb +20 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/actors/idle.rb +45 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/client.rb +28 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/helpers/constants.rb +53 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/helpers/dmn_engine.rb +221 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/helpers/wandering_thought.rb +60 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb +122 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/default_mode_network.rb +20 -0
- data/lib/legion/extensions/agentic/self/fingerprint/client.rb +28 -0
- data/lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb +73 -0
- data/lib/legion/extensions/agentic/self/fingerprint/helpers/constants.rb +60 -0
- data/lib/legion/extensions/agentic/self/fingerprint/helpers/fingerprint_engine.rb +169 -0
- data/lib/legion/extensions/agentic/self/fingerprint/runners/cognitive_fingerprint.rb +86 -0
- data/lib/legion/extensions/agentic/self/fingerprint/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/fingerprint.rb +19 -0
- data/lib/legion/extensions/agentic/self/identity/actors/credential_refresh.rb +49 -0
- data/lib/legion/extensions/agentic/self/identity/actors/orphan_check.rb +52 -0
- data/lib/legion/extensions/agentic/self/identity/client.rb +27 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/dimensions.rb +75 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/fingerprint.rb +170 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/graph_client.rb +29 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/graph_token.rb +36 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/token_cache.rb +59 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/vault_secrets.rb +80 -0
- data/lib/legion/extensions/agentic/self/identity/local_migrations/20260316000030_create_fingerprint.rb +20 -0
- data/lib/legion/extensions/agentic/self/identity/runners/entra.rb +402 -0
- data/lib/legion/extensions/agentic/self/identity/runners/identity.rb +90 -0
- data/lib/legion/extensions/agentic/self/identity/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/identity.rb +28 -0
- data/lib/legion/extensions/agentic/self/metacognition/client.rb +27 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/constants.rb +377 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/narrator_bridge.rb +85 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb +70 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb +160 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/snapshot_store.rb +82 -0
- data/lib/legion/extensions/agentic/self/metacognition/runners/metacognition.rb +116 -0
- data/lib/legion/extensions/agentic/self/metacognition/runners/registry.rb +180 -0
- data/lib/legion/extensions/agentic/self/metacognition/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/metacognition.rb +22 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/client.rb +25 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/helpers/calibration_tracker.rb +96 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/helpers/constants.rb +47 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/helpers/monitoring_engine.rb +141 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/helpers/monitoring_judgment.rb +79 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/runners/metacognitive_monitoring.rb +151 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring.rb +20 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/client.rb +29 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb +137 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/helpers/arc_engine.rb +119 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/helpers/beat_event.rb +59 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/helpers/constants.rb +66 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/runners/narrative.rb +101 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/narrative_arc.rb +20 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/actors/narrative_decay.rb +45 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/client.rb +22 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/chapter.rb +48 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/constants.rb +62 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/episode.rb +67 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/narrative_engine.rb +187 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/theme.rb +50 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb +158 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/narrative_identity.rb +21 -0
- data/lib/legion/extensions/agentic/self/narrative_self/client.rb +27 -0
- data/lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb +187 -0
- data/lib/legion/extensions/agentic/self/narrative_self/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb +81 -0
- data/lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb +65 -0
- data/lib/legion/extensions/agentic/self/narrative_self/runners/narrative_self.rb +86 -0
- data/lib/legion/extensions/agentic/self/narrative_self/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/narrative_self.rb +20 -0
- data/lib/legion/extensions/agentic/self/personality/client.rb +21 -0
- data/lib/legion/extensions/agentic/self/personality/helpers/constants.rb +84 -0
- data/lib/legion/extensions/agentic/self/personality/helpers/personality_store.rb +126 -0
- data/lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb +147 -0
- data/lib/legion/extensions/agentic/self/personality/runners/personality.rb +102 -0
- data/lib/legion/extensions/agentic/self/personality/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/personality.rb +19 -0
- data/lib/legion/extensions/agentic/self/reflection/client.rb +27 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/constants.rb +66 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/llm_enhancer.rb +166 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/monitors.rb +186 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/reflection.rb +54 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb +99 -0
- data/lib/legion/extensions/agentic/self/reflection/runners/reflection.rb +199 -0
- data/lib/legion/extensions/agentic/self/reflection/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/reflection.rb +21 -0
- data/lib/legion/extensions/agentic/self/self_model/client.rb +19 -0
- data/lib/legion/extensions/agentic/self/self_model/helpers/capability.rb +93 -0
- data/lib/legion/extensions/agentic/self/self_model/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/self/self_model/helpers/knowledge_domain.rb +82 -0
- data/lib/legion/extensions/agentic/self/self_model/helpers/self_model.rb +150 -0
- data/lib/legion/extensions/agentic/self/self_model/runners/self_model.rb +82 -0
- data/lib/legion/extensions/agentic/self/self_model/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/self_model.rb +21 -0
- data/lib/legion/extensions/agentic/self/self_talk/actors/volume_decay.rb +45 -0
- data/lib/legion/extensions/agentic/self/self_talk/client.rb +30 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/constants.rb +63 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb +114 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/dialogue_turn.rb +43 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb +77 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/llm_enhancer.rb +135 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/self_talk_engine.rb +160 -0
- data/lib/legion/extensions/agentic/self/self_talk/runners/self_talk.rb +172 -0
- data/lib/legion/extensions/agentic/self/self_talk/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/self_talk.rb +22 -0
- data/lib/legion/extensions/agentic/self/version.rb +11 -0
- data/lib/legion/extensions/agentic/self.rb +33 -0
- data/spec/legion/extensions/agentic/self/agency/client_spec.rb +67 -0
- data/spec/legion/extensions/agentic/self/agency/helpers/constants_spec.rb +73 -0
- data/spec/legion/extensions/agentic/self/agency/helpers/efficacy_model_spec.rb +190 -0
- data/spec/legion/extensions/agentic/self/agency/helpers/outcome_event_spec.rb +85 -0
- data/spec/legion/extensions/agentic/self/agency/runners/agency_spec.rb +132 -0
- data/spec/legion/extensions/agentic/self/anchor/client_spec.rb +30 -0
- data/spec/legion/extensions/agentic/self/anchor/helpers/anchor_engine_spec.rb +109 -0
- data/spec/legion/extensions/agentic/self/anchor/helpers/anchor_spec.rb +124 -0
- data/spec/legion/extensions/agentic/self/anchor/helpers/chain_spec.rb +106 -0
- data/spec/legion/extensions/agentic/self/anchor/helpers/constants_spec.rb +53 -0
- data/spec/legion/extensions/agentic/self/anchor/runners/cognitive_anchor_spec.rb +70 -0
- data/spec/legion/extensions/agentic/self/anosognosia/anosognosia_spec.rb +15 -0
- data/spec/legion/extensions/agentic/self/anosognosia/client_spec.rb +50 -0
- data/spec/legion/extensions/agentic/self/anosognosia/helpers/anosognosia_engine_spec.rb +266 -0
- data/spec/legion/extensions/agentic/self/anosognosia/helpers/cognitive_deficit_spec.rb +150 -0
- data/spec/legion/extensions/agentic/self/anosognosia/helpers/constants_spec.rb +58 -0
- data/spec/legion/extensions/agentic/self/anosognosia/runners/anosognosia_spec.rb +225 -0
- data/spec/legion/extensions/agentic/self/architecture/client_spec.rb +51 -0
- data/spec/legion/extensions/agentic/self/architecture/helpers/architecture_engine_spec.rb +321 -0
- data/spec/legion/extensions/agentic/self/architecture/helpers/connection_spec.rb +118 -0
- data/spec/legion/extensions/agentic/self/architecture/helpers/subsystem_spec.rb +189 -0
- data/spec/legion/extensions/agentic/self/architecture/runners/cognitive_architecture_spec.rb +181 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/client_spec.rb +69 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/helpers/constants_spec.rb +76 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/helpers/dmn_engine_spec.rb +321 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/helpers/wandering_thought_spec.rb +145 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network_spec.rb +269 -0
- data/spec/legion/extensions/agentic/self/fingerprint/client_spec.rb +54 -0
- data/spec/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait_spec.rb +180 -0
- data/spec/legion/extensions/agentic/self/fingerprint/helpers/constants_spec.rb +108 -0
- data/spec/legion/extensions/agentic/self/fingerprint/helpers/fingerprint_engine_spec.rb +318 -0
- data/spec/legion/extensions/agentic/self/fingerprint/runners/cognitive_fingerprint_spec.rb +232 -0
- data/spec/legion/extensions/agentic/self/identity/actors/orphan_check_spec.rb +104 -0
- data/spec/legion/extensions/agentic/self/identity/client_spec.rb +32 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/dimensions_spec.rb +51 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/fingerprint_spec.rb +66 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/graph_client_spec.rb +19 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/graph_token_spec.rb +31 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/token_cache_spec.rb +50 -0
- data/spec/legion/extensions/agentic/self/identity/local_persistence_spec.rb +329 -0
- data/spec/legion/extensions/agentic/self/identity/runners/entra_spec.rb +655 -0
- data/spec/legion/extensions/agentic/self/identity/runners/identity_spec.rb +61 -0
- data/spec/legion/extensions/agentic/self/metacognition/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/constants_spec.rb +31 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/narrator_bridge_spec.rb +102 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/registry_store_spec.rb +227 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/self_model_spec.rb +117 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/snapshot_store_spec.rb +128 -0
- data/spec/legion/extensions/agentic/self/metacognition/runners/metacognition_spec.rb +110 -0
- data/spec/legion/extensions/agentic/self/metacognition/runners/registry_spec.rb +281 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/client_spec.rb +59 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/helpers/calibration_tracker_spec.rb +143 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/helpers/constants_spec.rb +91 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/helpers/monitoring_engine_spec.rb +198 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/helpers/monitoring_judgment_spec.rb +172 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/runners/metacognitive_monitoring_spec.rb +244 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/client_spec.rb +22 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/helpers/arc_engine_spec.rb +183 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/helpers/arc_spec.rb +177 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/helpers/beat_event_spec.rb +96 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/helpers/constants_spec.rb +75 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/runners/narrative_spec.rb +142 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/client_spec.rb +69 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/chapter_spec.rb +85 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/constants_spec.rb +83 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/episode_spec.rb +180 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/narrative_engine_spec.rb +307 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/theme_spec.rb +107 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity_spec.rb +240 -0
- data/spec/legion/extensions/agentic/self/narrative_self/client_spec.rb +67 -0
- data/spec/legion/extensions/agentic/self/narrative_self/helpers/autobiography_spec.rb +155 -0
- data/spec/legion/extensions/agentic/self/narrative_self/helpers/constants_spec.rb +28 -0
- data/spec/legion/extensions/agentic/self/narrative_self/helpers/episode_spec.rb +144 -0
- data/spec/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread_spec.rb +87 -0
- data/spec/legion/extensions/agentic/self/narrative_self/runners/narrative_self_spec.rb +118 -0
- data/spec/legion/extensions/agentic/self/personality/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/self/personality/helpers/constants_spec.rb +41 -0
- data/spec/legion/extensions/agentic/self/personality/helpers/personality_store_spec.rb +66 -0
- data/spec/legion/extensions/agentic/self/personality/helpers/trait_model_spec.rb +148 -0
- data/spec/legion/extensions/agentic/self/personality/runners/personality_spec.rb +67 -0
- data/spec/legion/extensions/agentic/self/reflection/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/self/reflection/helpers/llm_enhancer_spec.rb +191 -0
- data/spec/legion/extensions/agentic/self/reflection/helpers/monitors_spec.rb +120 -0
- data/spec/legion/extensions/agentic/self/reflection/helpers/reflection_spec.rb +49 -0
- data/spec/legion/extensions/agentic/self/reflection/helpers/reflection_store_spec.rb +93 -0
- data/spec/legion/extensions/agentic/self/reflection/runners/reflection_spec.rb +204 -0
- data/spec/legion/extensions/agentic/self/self_model/client_spec.rb +55 -0
- data/spec/legion/extensions/agentic/self/self_model/helpers/capability_spec.rb +160 -0
- data/spec/legion/extensions/agentic/self/self_model/helpers/knowledge_domain_spec.rb +128 -0
- data/spec/legion/extensions/agentic/self/self_model/helpers/self_model_spec.rb +238 -0
- data/spec/legion/extensions/agentic/self/self_model/runners/self_model_spec.rb +143 -0
- data/spec/legion/extensions/agentic/self/self_talk/actors/volume_decay_spec.rb +46 -0
- data/spec/legion/extensions/agentic/self/self_talk/client_spec.rb +26 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/constants_spec.rb +110 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/dialogue_spec.rb +191 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/dialogue_turn_spec.rb +78 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/inner_voice_spec.rb +172 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/llm_enhancer_spec.rb +206 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/self_talk_engine_spec.rb +239 -0
- data/spec/legion/extensions/agentic/self/self_talk/runners/self_talk_llm_spec.rb +169 -0
- data/spec/legion/extensions/agentic/self/self_talk/runners/self_talk_spec.rb +196 -0
- data/spec/spec_helper.rb +46 -0
- metadata +347 -0
data/spec/legion/extensions/agentic/self/default_mode_network/helpers/wandering_thought_spec.rb
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Self::DefaultModeNetwork::Helpers::WanderingThought do
|
|
4
|
+
subject(:thought) do
|
|
5
|
+
described_class.new(
|
|
6
|
+
seed: :identity,
|
|
7
|
+
association_chain: %i[identity values purpose],
|
|
8
|
+
domain: :self,
|
|
9
|
+
thought_type: :self_referential,
|
|
10
|
+
salience: 0.6
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '#initialize' do
|
|
15
|
+
it 'assigns all fields' do
|
|
16
|
+
expect(thought.seed).to eq(:identity)
|
|
17
|
+
expect(thought.association_chain).to eq(%i[identity values purpose])
|
|
18
|
+
expect(thought.domain).to eq(:self)
|
|
19
|
+
expect(thought.thought_type).to eq(:self_referential)
|
|
20
|
+
expect(thought.salience).to eq(0.6)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'generates a UUID id' do
|
|
24
|
+
expect(thought.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'records created_at as a Time' do
|
|
28
|
+
expect(thought.created_at).to be_a(Time)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'clamps salience to 0..1' do
|
|
32
|
+
high = described_class.new(seed: :x, association_chain: [], domain: :d, thought_type: :wandering, salience: 5.0)
|
|
33
|
+
low = described_class.new(seed: :x, association_chain: [], domain: :d, thought_type: :wandering, salience: -1.0)
|
|
34
|
+
expect(high.salience).to eq(1.0)
|
|
35
|
+
expect(low.salience).to eq(0.0)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'coerces thought_type to symbol' do
|
|
39
|
+
t = described_class.new(seed: :x, association_chain: [], domain: :d, thought_type: 'wandering')
|
|
40
|
+
expect(t.thought_type).to eq(:wandering)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'wraps non-array association_chain in an array' do
|
|
44
|
+
t = described_class.new(seed: :x, association_chain: :single, domain: :d, thought_type: :wandering)
|
|
45
|
+
expect(t.association_chain).to eq([:single])
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe '#boost_salience' do
|
|
50
|
+
it 'increases salience by SALIENCE_ALPHA by default' do
|
|
51
|
+
before = thought.salience
|
|
52
|
+
thought.boost_salience
|
|
53
|
+
expect(thought.salience).to be_within(0.001).of(before + described_module::SALIENCE_ALPHA)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'accepts a custom amount' do
|
|
57
|
+
before = thought.salience
|
|
58
|
+
thought.boost_salience(0.2)
|
|
59
|
+
expect(thought.salience).to be_within(0.001).of(before + 0.2)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'caps at 1.0' do
|
|
63
|
+
thought.salience = 0.99
|
|
64
|
+
thought.boost_salience(0.5)
|
|
65
|
+
expect(thought.salience).to eq(1.0)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe '#decay' do
|
|
70
|
+
it 'reduces salience by THOUGHT_DECAY' do
|
|
71
|
+
before = thought.salience
|
|
72
|
+
thought.decay
|
|
73
|
+
expect(thought.salience).to be_within(0.001).of(before - described_module::THOUGHT_DECAY)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'does not drop below THOUGHT_SALIENCE_FLOOR' do
|
|
77
|
+
500.times { thought.decay }
|
|
78
|
+
expect(thought.salience).to be >= described_module::THOUGHT_SALIENCE_FLOOR
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe '#faded?' do
|
|
83
|
+
it 'returns false for a strong thought' do
|
|
84
|
+
expect(thought.faded?).to be false
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'returns true at the salience floor' do
|
|
88
|
+
thought.salience = described_module::THOUGHT_SALIENCE_FLOOR
|
|
89
|
+
expect(thought.faded?).to be true
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'returns false just above the floor' do
|
|
93
|
+
thought.salience = described_module::THOUGHT_SALIENCE_FLOOR + 0.01
|
|
94
|
+
expect(thought.faded?).to be false
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '#label' do
|
|
99
|
+
it 'returns :significant for salience 0.7' do
|
|
100
|
+
thought.salience = 0.7
|
|
101
|
+
expect(thought.label).to eq(:significant)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'returns :breakthrough for salience 0.9' do
|
|
105
|
+
thought.salience = 0.9
|
|
106
|
+
expect(thought.label).to eq(:breakthrough)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'returns :fleeting for salience 0.1' do
|
|
110
|
+
thought.salience = 0.1
|
|
111
|
+
expect(thought.label).to eq(:fleeting)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'returns :notable for salience 0.5' do
|
|
115
|
+
thought.salience = 0.5
|
|
116
|
+
expect(thought.label).to eq(:notable)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'returns :passing for salience 0.3' do
|
|
120
|
+
thought.salience = 0.3
|
|
121
|
+
expect(thought.label).to eq(:passing)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe '#to_h' do
|
|
126
|
+
it 'returns a hash with all expected keys' do
|
|
127
|
+
h = thought.to_h
|
|
128
|
+
expect(h).to include(:id, :seed, :association_chain, :domain, :thought_type, :salience, :label, :created_at)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'includes the current label' do
|
|
132
|
+
thought.salience = 0.9
|
|
133
|
+
expect(thought.to_h[:label]).to eq(:breakthrough)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'rounds salience to 4 decimal places' do
|
|
137
|
+
thought.salience = 0.123456789
|
|
138
|
+
expect(thought.to_h[:salience]).to eq(0.1235)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def described_module
|
|
143
|
+
Legion::Extensions::Agentic::Self::DefaultModeNetwork::Helpers::Constants
|
|
144
|
+
end
|
|
145
|
+
end
|
data/spec/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network_spec.rb
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Self::DefaultModeNetwork::Runners::DefaultModeNetwork do
|
|
4
|
+
let(:client) { Legion::Extensions::Agentic::Self::DefaultModeNetwork::Client.new }
|
|
5
|
+
|
|
6
|
+
describe '#register_external_stimulus' do
|
|
7
|
+
it 'returns success' do
|
|
8
|
+
result = client.register_external_stimulus(source: :user_request)
|
|
9
|
+
expect(result[:success]).to be true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'returns mode fields' do
|
|
13
|
+
result = client.register_external_stimulus(source: :test)
|
|
14
|
+
expect(result).to have_key(:previous_mode)
|
|
15
|
+
expect(result).to have_key(:current_mode)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'resets to :active mode' do
|
|
19
|
+
result = client.register_external_stimulus
|
|
20
|
+
expect(result[:current_mode]).to eq(:active)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'includes source in result' do
|
|
24
|
+
result = client.register_external_stimulus(source: :webhook)
|
|
25
|
+
expect(result[:source]).to eq(:webhook)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '#generate_idle_thought' do
|
|
30
|
+
it 'returns success' do
|
|
31
|
+
result = client.generate_idle_thought
|
|
32
|
+
expect(result[:success]).to be true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'returns a thought hash' do
|
|
36
|
+
result = client.generate_idle_thought
|
|
37
|
+
expect(result[:thought]).to be_a(Hash)
|
|
38
|
+
expect(result[:thought]).to include(:id, :seed, :thought_type, :salience)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'thought has a valid type' do
|
|
42
|
+
valid_types = %w[self_referential social_replay spontaneous_plan wandering]
|
|
43
|
+
result = client.generate_idle_thought
|
|
44
|
+
expect(valid_types).to include(result[:thought][:thought_type].to_s)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe '#trigger_self_reflection' do
|
|
49
|
+
it 'returns success' do
|
|
50
|
+
result = client.trigger_self_reflection
|
|
51
|
+
expect(result[:success]).to be true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'returns a self_referential thought' do
|
|
55
|
+
result = client.trigger_self_reflection
|
|
56
|
+
expect(result[:thought][:thought_type]).to eq(:self_referential)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'thought has domain :self' do
|
|
60
|
+
result = client.trigger_self_reflection
|
|
61
|
+
expect(result[:thought][:domain]).to eq(:self)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'includes association chain' do
|
|
65
|
+
result = client.trigger_self_reflection
|
|
66
|
+
expect(result[:thought][:association_chain]).to be_an(Array)
|
|
67
|
+
expect(result[:thought][:association_chain]).not_to be_empty
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '#trigger_social_replay' do
|
|
72
|
+
it 'returns success' do
|
|
73
|
+
result = client.trigger_social_replay(interaction: :standup)
|
|
74
|
+
expect(result[:success]).to be true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'returns a social_replay thought' do
|
|
78
|
+
result = client.trigger_social_replay
|
|
79
|
+
expect(result[:thought][:thought_type]).to eq(:social_replay)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'uses provided interaction as seed' do
|
|
83
|
+
result = client.trigger_social_replay(interaction: :team_meeting)
|
|
84
|
+
expect(result[:thought][:seed]).to eq(:team_meeting)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'uses default seed when interaction is nil' do
|
|
88
|
+
result = client.trigger_social_replay
|
|
89
|
+
expect(result[:thought][:seed]).not_to be_nil
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'thought domain is :social' do
|
|
93
|
+
result = client.trigger_social_replay
|
|
94
|
+
expect(result[:thought][:domain]).to eq(:social)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '#trigger_spontaneous_plan' do
|
|
99
|
+
it 'returns success' do
|
|
100
|
+
result = client.trigger_spontaneous_plan(goal: :reduce_latency)
|
|
101
|
+
expect(result[:success]).to be true
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'returns a spontaneous_plan thought' do
|
|
105
|
+
result = client.trigger_spontaneous_plan
|
|
106
|
+
expect(result[:thought][:thought_type]).to eq(:spontaneous_plan)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'uses provided goal as seed' do
|
|
110
|
+
result = client.trigger_spontaneous_plan(goal: :scale_out)
|
|
111
|
+
expect(result[:thought][:seed]).to eq(:scale_out)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'thought domain is :planning' do
|
|
115
|
+
result = client.trigger_spontaneous_plan
|
|
116
|
+
expect(result[:thought][:domain]).to eq(:planning)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'salience is in range 0..1' do
|
|
120
|
+
result = client.trigger_spontaneous_plan
|
|
121
|
+
expect(result[:thought][:salience]).to be_between(0.0, 1.0)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe '#trigger_wandering' do
|
|
126
|
+
it 'returns success' do
|
|
127
|
+
result = client.trigger_wandering(seed: :curiosity)
|
|
128
|
+
expect(result[:success]).to be true
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'returns a wandering thought' do
|
|
132
|
+
result = client.trigger_wandering
|
|
133
|
+
expect(result[:thought][:thought_type]).to eq(:wandering)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'uses provided seed' do
|
|
137
|
+
result = client.trigger_wandering(seed: :pattern)
|
|
138
|
+
expect(result[:thought][:seed]).to eq(:pattern)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'thought domain is :associative' do
|
|
142
|
+
result = client.trigger_wandering
|
|
143
|
+
expect(result[:thought][:domain]).to eq(:associative)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it 'association chain starts with the seed' do
|
|
147
|
+
result = client.trigger_wandering(seed: :creativity)
|
|
148
|
+
expect(result[:thought][:association_chain].first).to eq(:creativity)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
describe '#salient_thoughts' do
|
|
153
|
+
before do
|
|
154
|
+
3.times { client.generate_idle_thought }
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it 'returns success' do
|
|
158
|
+
result = client.salient_thoughts(count: 2)
|
|
159
|
+
expect(result[:success]).to be true
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'returns up to count thoughts' do
|
|
163
|
+
result = client.salient_thoughts(count: 2)
|
|
164
|
+
expect(result[:thoughts].size).to be <= 2
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'includes count in result' do
|
|
168
|
+
result = client.salient_thoughts(count: 3)
|
|
169
|
+
expect(result[:count]).to eq(result[:thoughts].size)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it 'thoughts are hashes with expected keys' do
|
|
173
|
+
result = client.salient_thoughts(count: 1)
|
|
174
|
+
result[:thoughts].each do |t|
|
|
175
|
+
expect(t).to include(:id, :thought_type, :salience)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'returns empty array when no thoughts exist' do
|
|
180
|
+
fresh_client = Legion::Extensions::Agentic::Self::DefaultModeNetwork::Client.new
|
|
181
|
+
result = fresh_client.salient_thoughts
|
|
182
|
+
expect(result[:thoughts]).to be_empty
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
describe '#dmn_mode_status' do
|
|
187
|
+
it 'returns success' do
|
|
188
|
+
result = client.dmn_mode_status
|
|
189
|
+
expect(result[:success]).to be true
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it 'returns mode as symbol' do
|
|
193
|
+
result = client.dmn_mode_status
|
|
194
|
+
expect(%i[active transitioning idle deep_idle]).to include(result[:mode])
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it 'includes mode_label' do
|
|
198
|
+
result = client.dmn_mode_status
|
|
199
|
+
labels = Legion::Extensions::Agentic::Self::DefaultModeNetwork::Helpers::Constants::ACTIVITY_LABELS.values
|
|
200
|
+
expect(labels).to include(result[:mode_label])
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'includes idle_duration as float' do
|
|
204
|
+
result = client.dmn_mode_status
|
|
205
|
+
expect(result[:idle_duration]).to be_a(Float)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
it 'includes thought_count' do
|
|
209
|
+
result = client.dmn_mode_status
|
|
210
|
+
expect(result).to have_key(:thought_count)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
describe '#update_dmn' do
|
|
215
|
+
it 'returns success' do
|
|
216
|
+
result = client.update_dmn
|
|
217
|
+
expect(result[:success]).to be true
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it 'returns mode after tick' do
|
|
221
|
+
result = client.update_dmn
|
|
222
|
+
expect(%i[active transitioning idle deep_idle]).to include(result[:mode])
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it 'returns previous_mode' do
|
|
226
|
+
result = client.update_dmn
|
|
227
|
+
expect(result).to have_key(:previous_mode)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it 'returns faded_count' do
|
|
231
|
+
result = client.update_dmn
|
|
232
|
+
expect(result[:faded_count]).to be_a(Integer)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it 'returns thought_count after decay' do
|
|
236
|
+
result = client.update_dmn
|
|
237
|
+
expect(result[:thought_count]).to be_a(Integer)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it 'generates a new thought when idle' do
|
|
241
|
+
engine = Legion::Extensions::Agentic::Self::DefaultModeNetwork::Helpers::DmnEngine.new
|
|
242
|
+
allow(engine).to receive(:idle_duration).and_return(60.0)
|
|
243
|
+
engine.tick_mode # force to :idle
|
|
244
|
+
idle_client = Legion::Extensions::Agentic::Self::DefaultModeNetwork::Client.new(dmn_engine: engine)
|
|
245
|
+
result = idle_client.update_dmn
|
|
246
|
+
expect(result[:new_thought]).not_to be_nil
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it 'new_thought is nil when active' do
|
|
250
|
+
result = client.update_dmn
|
|
251
|
+
# When just initialized, mode is active — no thought generated by update_dmn
|
|
252
|
+
# (may be nil or a thought depending on mode after tick)
|
|
253
|
+
expect(result).to have_key(:new_thought)
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
describe '#dmn_stats' do
|
|
258
|
+
it 'returns success' do
|
|
259
|
+
result = client.dmn_stats
|
|
260
|
+
expect(result[:success]).to be true
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it 'includes stats hash' do
|
|
264
|
+
result = client.dmn_stats
|
|
265
|
+
expect(result[:stats]).to be_a(Hash)
|
|
266
|
+
expect(result[:stats]).to include(:mode, :mode_label, :idle_duration, :thought_count)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/self/fingerprint/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Self::Fingerprint::Client do
|
|
6
|
+
let(:client) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'responds to record_observation' do
|
|
9
|
+
expect(client).to respond_to(:record_observation)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'responds to verify_identity' do
|
|
13
|
+
expect(client).to respond_to(:verify_identity)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'responds to anomaly_check' do
|
|
17
|
+
expect(client).to respond_to(:anomaly_check)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'responds to trait_profile' do
|
|
21
|
+
expect(client).to respond_to(:trait_profile)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'responds to strongest_traits' do
|
|
25
|
+
expect(client).to respond_to(:strongest_traits)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'responds to weakest_traits' do
|
|
29
|
+
expect(client).to respond_to(:weakest_traits)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'responds to identity_confidence' do
|
|
33
|
+
expect(client).to respond_to(:identity_confidence)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'responds to fingerprint_hash' do
|
|
37
|
+
expect(client).to respond_to(:fingerprint_hash)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'responds to fingerprint_report' do
|
|
41
|
+
expect(client).to respond_to(:fingerprint_report)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'responds to fingerprint_status' do
|
|
45
|
+
expect(client).to respond_to(:fingerprint_status)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'each instance has independent state' do
|
|
49
|
+
c1 = described_class.new
|
|
50
|
+
c2 = described_class.new
|
|
51
|
+
c1.record_observation(category: :accuracy, value: 0.9)
|
|
52
|
+
expect(c2.fingerprint_status[:trait_count]).to eq(0)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Self::Fingerprint::Helpers::CognitiveTrait do
|
|
4
|
+
let(:trait) { described_class.new(category: :accuracy) }
|
|
5
|
+
|
|
6
|
+
describe '#initialize' do
|
|
7
|
+
it 'assigns a UUID id' do
|
|
8
|
+
expect(trait.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'sets category' do
|
|
12
|
+
expect(trait.category).to eq(:accuracy)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'starts with baseline 0.5' do
|
|
16
|
+
expect(trait.baseline).to eq(0.5)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'starts with zero variance' do
|
|
20
|
+
expect(trait.variance).to eq(0.0)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'starts with zero sample count' do
|
|
24
|
+
expect(trait.sample_count).to eq(0)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'sets last_updated to a Time' do
|
|
28
|
+
expect(trait.last_updated).to be_a(Time)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'raises for unknown category' do
|
|
32
|
+
expect { described_class.new(category: :nonexistent) }.to raise_error(ArgumentError, /unknown category/)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'accepts all valid categories' do
|
|
36
|
+
Legion::Extensions::Agentic::Self::Fingerprint::Helpers::Constants::TRAIT_CATEGORIES.each do |cat|
|
|
37
|
+
expect { described_class.new(category: cat) }.not_to raise_error
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe '#record_sample!' do
|
|
43
|
+
it 'returns self for chaining' do
|
|
44
|
+
expect(trait.record_sample!(0.8)).to eq(trait)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'shifts baseline toward sample (EMA)' do
|
|
48
|
+
original = trait.baseline
|
|
49
|
+
trait.record_sample!(1.0)
|
|
50
|
+
expect(trait.baseline).to be > original
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'shifts baseline down for low samples' do
|
|
54
|
+
original = trait.baseline
|
|
55
|
+
trait.record_sample!(0.0)
|
|
56
|
+
expect(trait.baseline).to be < original
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'increments sample_count' do
|
|
60
|
+
trait.record_sample!(0.7)
|
|
61
|
+
expect(trait.sample_count).to eq(1)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'applies EMA_ALPHA correctly for one update' do
|
|
65
|
+
expected = (0.15 * 0.8) + (0.85 * 0.5)
|
|
66
|
+
trait.record_sample!(0.8)
|
|
67
|
+
expect(trait.baseline).to be_within(0.0000001).of(expected)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'clamps input values above 1.0' do
|
|
71
|
+
trait.record_sample!(5.0)
|
|
72
|
+
expect(trait.baseline).to be <= 1.0
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'clamps input values below 0.0' do
|
|
76
|
+
trait.record_sample!(-2.0)
|
|
77
|
+
expect(trait.baseline).to be >= 0.0
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'updates last_updated' do
|
|
81
|
+
before = trait.last_updated
|
|
82
|
+
trait.record_sample!(0.6)
|
|
83
|
+
expect(trait.last_updated).to be >= before
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'caps sample_count at MAX_SAMPLES' do
|
|
87
|
+
(Legion::Extensions::Agentic::Self::Fingerprint::Helpers::Constants::MAX_SAMPLES + 10).times do
|
|
88
|
+
trait.record_sample!(0.5)
|
|
89
|
+
end
|
|
90
|
+
expect(trait.sample_count).to eq(Legion::Extensions::Agentic::Self::Fingerprint::Helpers::Constants::MAX_SAMPLES)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'accumulates variance over varying samples' do
|
|
94
|
+
trait.record_sample!(0.1)
|
|
95
|
+
trait.record_sample!(0.9)
|
|
96
|
+
expect(trait.variance).to be > 0.0
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'rounds baseline to 10 decimal places' do
|
|
100
|
+
trait.record_sample!(0.333333333)
|
|
101
|
+
expect(trait.baseline.to_s.split('.').last.length).to be <= 10
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe '#deviation_from' do
|
|
106
|
+
it 'returns 0.0 for baseline value' do
|
|
107
|
+
expect(trait.deviation_from(0.5)).to eq(0.0)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'returns positive deviation for values above baseline' do
|
|
111
|
+
expect(trait.deviation_from(0.9)).to be > 0.0
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'returns positive deviation for values below baseline' do
|
|
115
|
+
expect(trait.deviation_from(0.1)).to be > 0.0
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'is always non-negative' do
|
|
119
|
+
expect(trait.deviation_from(0.0)).to be >= 0.0
|
|
120
|
+
expect(trait.deviation_from(1.0)).to be >= 0.0
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'clamps out-of-range inputs' do
|
|
124
|
+
dev_low = trait.deviation_from(-1.0)
|
|
125
|
+
dev_zero = trait.deviation_from(0.0)
|
|
126
|
+
expect(dev_low).to eq(dev_zero)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe '#stable?' do
|
|
131
|
+
it 'is stable with zero variance' do
|
|
132
|
+
expect(trait.stable?).to be true
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'is not stable when variance exceeds 0.1' do
|
|
136
|
+
5.times { trait.record_sample!(0.1) }
|
|
137
|
+
5.times { trait.record_sample!(0.9) }
|
|
138
|
+
# After divergent samples variance should grow beyond threshold
|
|
139
|
+
trait.record_sample!(0.0)
|
|
140
|
+
trait.record_sample!(1.0)
|
|
141
|
+
# variance might still be low from EMA; just check the boundary condition
|
|
142
|
+
low_var_trait = described_class.new(category: :accuracy)
|
|
143
|
+
expect(low_var_trait.stable?).to be true
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe '#volatile?' do
|
|
148
|
+
it 'is not volatile with zero variance' do
|
|
149
|
+
expect(trait.volatile?).to be false
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe '#strength_label' do
|
|
154
|
+
it 'returns a valid label symbol' do
|
|
155
|
+
valid = %i[dominant strong moderate weak absent]
|
|
156
|
+
expect(valid).to include(trait.strength_label)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it 'returns :moderate for default baseline of 0.5' do
|
|
160
|
+
expect(trait.strength_label).to eq(:moderate)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
describe '#to_h' do
|
|
165
|
+
let(:hash) { trait.to_h }
|
|
166
|
+
|
|
167
|
+
it 'includes required keys' do
|
|
168
|
+
%i[id category baseline variance sample_count stable volatile strength last_updated].each do |key|
|
|
169
|
+
expect(hash).to have_key(key)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it 'reflects current state' do
|
|
174
|
+
trait.record_sample!(0.8)
|
|
175
|
+
h = trait.to_h
|
|
176
|
+
expect(h[:sample_count]).to eq(1)
|
|
177
|
+
expect(h[:baseline]).to be > 0.5
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|