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,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Mycelium
|
|
8
|
+
module Helpers
|
|
9
|
+
class MycelialNode
|
|
10
|
+
attr_reader :id, :node_type, :domain, :content, :created_at
|
|
11
|
+
attr_accessor :nutrient_level, :connections_count
|
|
12
|
+
|
|
13
|
+
def initialize(node_type:, domain:, content:,
|
|
14
|
+
nutrient_level: 0.5)
|
|
15
|
+
validate_type!(node_type)
|
|
16
|
+
@id = SecureRandom.uuid
|
|
17
|
+
@node_type = node_type.to_sym
|
|
18
|
+
@domain = domain.to_sym
|
|
19
|
+
@content = content.to_s
|
|
20
|
+
@nutrient_level = nutrient_level.to_f.clamp(0.0, 1.0).round(10)
|
|
21
|
+
@connections_count = 0
|
|
22
|
+
@created_at = Time.now.utc
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def absorb!(amount)
|
|
26
|
+
@nutrient_level = (@nutrient_level + amount.abs).clamp(0.0, 1.0).round(10)
|
|
27
|
+
self
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def deplete!(amount)
|
|
31
|
+
@nutrient_level = (@nutrient_level - amount.abs).clamp(0.0, 1.0).round(10)
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def fruiting_ready?
|
|
36
|
+
@nutrient_level >= Constants::FRUITING_THRESHOLD
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def starving?
|
|
40
|
+
@nutrient_level < 0.1
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_h
|
|
44
|
+
{
|
|
45
|
+
id: @id,
|
|
46
|
+
node_type: @node_type,
|
|
47
|
+
domain: @domain,
|
|
48
|
+
content: @content,
|
|
49
|
+
nutrient_level: @nutrient_level,
|
|
50
|
+
connections_count: @connections_count,
|
|
51
|
+
fruiting_ready: fruiting_ready?,
|
|
52
|
+
starving: starving?,
|
|
53
|
+
created_at: @created_at
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def validate_type!(val)
|
|
60
|
+
return if Constants::NODE_TYPES.include?(val.to_sym)
|
|
61
|
+
|
|
62
|
+
raise ArgumentError,
|
|
63
|
+
"unknown node type: #{val.inspect}; " \
|
|
64
|
+
"must be one of #{Constants::NODE_TYPES.inspect}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Mycelium
|
|
8
|
+
module Helpers
|
|
9
|
+
class MyceliumEngine
|
|
10
|
+
def initialize
|
|
11
|
+
@nodes = {}
|
|
12
|
+
@hyphae = {}
|
|
13
|
+
@fruiting_bodies = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create_node(node_type:, domain:, content:,
|
|
17
|
+
nutrient_level: 0.5)
|
|
18
|
+
validate_capacity!(@nodes, Constants::MAX_NODES, 'nodes')
|
|
19
|
+
node = MycelialNode.new(
|
|
20
|
+
node_type: node_type, domain: domain,
|
|
21
|
+
content: content, nutrient_level: nutrient_level
|
|
22
|
+
)
|
|
23
|
+
@nodes[node.id] = node
|
|
24
|
+
node
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def connect(source_id:, target_id:, nutrient_type:,
|
|
28
|
+
strength: 0.5)
|
|
29
|
+
validate_capacity!(@hyphae, Constants::MAX_HYPHAE, 'hyphae')
|
|
30
|
+
fetch_node!(source_id)
|
|
31
|
+
fetch_node!(target_id)
|
|
32
|
+
hypha = Hypha.new(
|
|
33
|
+
source_id: source_id, target_id: target_id,
|
|
34
|
+
nutrient_type: nutrient_type, strength: strength
|
|
35
|
+
)
|
|
36
|
+
@hyphae[hypha.id] = hypha
|
|
37
|
+
increment_connections(source_id, target_id)
|
|
38
|
+
hypha
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def transfer_nutrients(hypha_id:)
|
|
42
|
+
hypha = fetch_hypha!(hypha_id)
|
|
43
|
+
source = fetch_node!(hypha.source_id)
|
|
44
|
+
target = fetch_node!(hypha.target_id)
|
|
45
|
+
amount = [hypha.transfer_capacity, source.nutrient_level].min
|
|
46
|
+
source.deplete!(amount)
|
|
47
|
+
target.absorb!(amount)
|
|
48
|
+
{ transferred: amount, source: source.to_h, target: target.to_h }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def fruit!(node_id:, fruiting_type:, content:)
|
|
52
|
+
validate_capacity!(@fruiting_bodies,
|
|
53
|
+
Constants::MAX_FRUITING_BODIES, 'fruiting bodies')
|
|
54
|
+
node = fetch_node!(node_id)
|
|
55
|
+
raise ArgumentError, 'node not ready for fruiting' unless node.fruiting_ready?
|
|
56
|
+
|
|
57
|
+
body = FruitingBody.new(
|
|
58
|
+
fruiting_type: fruiting_type, source_node_id: node_id,
|
|
59
|
+
content: content, potency: node.nutrient_level
|
|
60
|
+
)
|
|
61
|
+
node.deplete!(0.3)
|
|
62
|
+
@fruiting_bodies[body.id] = body
|
|
63
|
+
body
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def decay_network!(rate: Constants::NUTRIENT_DECAY)
|
|
67
|
+
@hyphae.each_value { |h| h.decay!(rate: rate) }
|
|
68
|
+
@nodes.each_value { |n| n.deplete!(rate * 0.5) }
|
|
69
|
+
prune_dead!
|
|
70
|
+
{ nodes: @nodes.size, hyphae: @hyphae.size }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def all_nodes
|
|
74
|
+
@nodes.values
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def all_hyphae
|
|
78
|
+
@hyphae.values
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def all_fruiting_bodies
|
|
82
|
+
@fruiting_bodies.values
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def connections_for(node_id)
|
|
86
|
+
@hyphae.values.select do |h|
|
|
87
|
+
h.source_id == node_id || h.target_id == node_id
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def network_report
|
|
92
|
+
{
|
|
93
|
+
total_nodes: @nodes.size,
|
|
94
|
+
total_hyphae: @hyphae.size,
|
|
95
|
+
total_fruiting: @fruiting_bodies.size,
|
|
96
|
+
active_hyphae: @hyphae.values.count(&:active?),
|
|
97
|
+
avg_nutrient: avg_field(@nodes, :nutrient_level),
|
|
98
|
+
avg_strength: avg_field(@hyphae, :strength),
|
|
99
|
+
fruiting_ready: @nodes.values.count(&:fruiting_ready?),
|
|
100
|
+
starving_nodes: @nodes.values.count(&:starving?),
|
|
101
|
+
network_health: network_health_label
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
private
|
|
106
|
+
|
|
107
|
+
def fetch_node!(id)
|
|
108
|
+
@nodes.fetch(id) do
|
|
109
|
+
raise ArgumentError, "node not found: #{id.inspect}"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def fetch_hypha!(id)
|
|
114
|
+
@hyphae.fetch(id) do
|
|
115
|
+
raise ArgumentError, "hypha not found: #{id.inspect}"
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def validate_capacity!(coll, max, name)
|
|
120
|
+
return if coll.size < max
|
|
121
|
+
|
|
122
|
+
raise ArgumentError,
|
|
123
|
+
"#{name} capacity reached (max #{max})"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def increment_connections(source_id, target_id)
|
|
127
|
+
@nodes[source_id].connections_count += 1
|
|
128
|
+
@nodes[target_id].connections_count += 1
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def prune_dead!
|
|
132
|
+
@hyphae.delete_if { |_, h| h.strength <= 0.0 }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def avg_field(coll, field)
|
|
136
|
+
return 0.0 if coll.empty?
|
|
137
|
+
|
|
138
|
+
(coll.values.sum(&field) / coll.size).round(10)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def network_health_label
|
|
142
|
+
avg = avg_field(@nodes, :nutrient_level)
|
|
143
|
+
Constants.label_for(Constants::NETWORK_HEALTH_LABELS, avg)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Mycelium
|
|
8
|
+
module Runners
|
|
9
|
+
module CognitiveMycelium
|
|
10
|
+
extend self
|
|
11
|
+
|
|
12
|
+
def create_node(node_type:, domain:, content:,
|
|
13
|
+
nutrient_level: 0.5, engine: nil, **)
|
|
14
|
+
eng = resolve_engine(engine)
|
|
15
|
+
node = eng.create_node(node_type: node_type, domain: domain,
|
|
16
|
+
content: content,
|
|
17
|
+
nutrient_level: nutrient_level)
|
|
18
|
+
{ success: true, node: node.to_h }
|
|
19
|
+
rescue ArgumentError => e
|
|
20
|
+
{ success: false, error: e.message }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def connect(source_id:, target_id:, nutrient_type:,
|
|
24
|
+
strength: 0.5, engine: nil, **)
|
|
25
|
+
eng = resolve_engine(engine)
|
|
26
|
+
hypha = eng.connect(source_id: source_id, target_id: target_id,
|
|
27
|
+
nutrient_type: nutrient_type,
|
|
28
|
+
strength: strength)
|
|
29
|
+
{ success: true, hypha: hypha.to_h }
|
|
30
|
+
rescue ArgumentError => e
|
|
31
|
+
{ success: false, error: e.message }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def transfer_nutrients(hypha_id:, engine: nil, **)
|
|
35
|
+
eng = resolve_engine(engine)
|
|
36
|
+
result = eng.transfer_nutrients(hypha_id: hypha_id)
|
|
37
|
+
{ success: true }.merge(result)
|
|
38
|
+
rescue ArgumentError => e
|
|
39
|
+
{ success: false, error: e.message }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def fruit(node_id:, fruiting_type:, content:, engine: nil, **)
|
|
43
|
+
eng = resolve_engine(engine)
|
|
44
|
+
body = eng.fruit!(node_id: node_id, fruiting_type: fruiting_type,
|
|
45
|
+
content: content)
|
|
46
|
+
{ success: true, fruiting_body: body.to_h }
|
|
47
|
+
rescue ArgumentError => e
|
|
48
|
+
{ success: false, error: e.message }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def network_status(engine: nil, **)
|
|
52
|
+
eng = resolve_engine(engine)
|
|
53
|
+
{ success: true, report: eng.network_report }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def resolve_engine(engine)
|
|
61
|
+
engine || default_engine
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def default_engine
|
|
65
|
+
@default_engine ||= Helpers::MyceliumEngine.new
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
require_relative 'mycelium/version'
|
|
6
|
+
require_relative 'mycelium/helpers/constants'
|
|
7
|
+
require_relative 'mycelium/helpers/mycelial_node'
|
|
8
|
+
require_relative 'mycelium/helpers/hypha'
|
|
9
|
+
require_relative 'mycelium/helpers/fruiting_body'
|
|
10
|
+
require_relative 'mycelium/helpers/mycelium_engine'
|
|
11
|
+
require_relative 'mycelium/runners/cognitive_mycelium'
|
|
12
|
+
require_relative 'mycelium/client'
|
|
13
|
+
|
|
14
|
+
module Legion
|
|
15
|
+
module Extensions
|
|
16
|
+
module Agentic
|
|
17
|
+
module Integration
|
|
18
|
+
module Mycelium
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/integration/phenomenal_binding/runners/phenomenal_binding'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Integration
|
|
9
|
+
module PhenomenalBinding
|
|
10
|
+
class Client
|
|
11
|
+
include Runners::PhenomenalBinding
|
|
12
|
+
|
|
13
|
+
def initialize(**)
|
|
14
|
+
@engine = Helpers::BindingEngine.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
attr_reader :engine
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module PhenomenalBinding
|
|
8
|
+
module Helpers
|
|
9
|
+
class BindingEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@streams = {}
|
|
14
|
+
@bindings = {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def register_stream(stream_type:, content:, salience: DEFAULT_SALIENCE, domain: nil)
|
|
18
|
+
prune_streams_if_full
|
|
19
|
+
stream = Stream.new(
|
|
20
|
+
stream_type: stream_type,
|
|
21
|
+
content: content,
|
|
22
|
+
salience: salience,
|
|
23
|
+
domain: domain
|
|
24
|
+
)
|
|
25
|
+
@streams[stream.id] = stream
|
|
26
|
+
stream
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create_binding(stream_ids:, binding_type:, attention_weight: 0.5)
|
|
30
|
+
prune_bindings_if_full
|
|
31
|
+
valid_ids = stream_ids.select { |id| @streams.key?(id) }
|
|
32
|
+
coherence = compute_initial_coherence(valid_ids)
|
|
33
|
+
binding = BindingUnit.new(
|
|
34
|
+
stream_ids: valid_ids,
|
|
35
|
+
binding_type: binding_type,
|
|
36
|
+
coherence: coherence,
|
|
37
|
+
attention_weight: attention_weight
|
|
38
|
+
)
|
|
39
|
+
@bindings[binding.id] = binding
|
|
40
|
+
binding
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def reinforce_binding(binding_id:)
|
|
44
|
+
binding = @bindings[binding_id]
|
|
45
|
+
return { status: :not_found, binding_id: binding_id } unless binding
|
|
46
|
+
|
|
47
|
+
binding.reinforce!
|
|
48
|
+
{ status: :reinforced, binding_id: binding_id, coherence: binding.coherence }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def dissolve_binding(binding_id:)
|
|
52
|
+
return { status: :not_found, binding_id: binding_id } unless @bindings.key?(binding_id)
|
|
53
|
+
|
|
54
|
+
@bindings.delete(binding_id)
|
|
55
|
+
{ status: :dissolved, binding_id: binding_id }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def unified_experience
|
|
59
|
+
coherent = @bindings.values.select(&:coherent?)
|
|
60
|
+
return nil if coherent.empty?
|
|
61
|
+
|
|
62
|
+
coherent.max_by { |b| b.coherence * b.attention_weight }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def fragmentation_index
|
|
66
|
+
total = @streams.size
|
|
67
|
+
return 0.0 if total.zero?
|
|
68
|
+
|
|
69
|
+
(unbound_streams.size.to_f / total).round(10)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def binding_by_type(binding_type:)
|
|
73
|
+
@bindings.values.select { |b| b.binding_type == binding_type }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def streams_for_binding(binding_id:)
|
|
77
|
+
binding = @bindings[binding_id]
|
|
78
|
+
return [] unless binding
|
|
79
|
+
|
|
80
|
+
binding.stream_ids.filter_map { |id| @streams[id] }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def unbound_streams
|
|
84
|
+
bound_ids = @bindings.values.flat_map(&:stream_ids).to_set
|
|
85
|
+
@streams.values.reject { |s| bound_ids.include?(s.id) }
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def decay_all
|
|
89
|
+
@bindings.each_value(&:decay!)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def prune_incoherent
|
|
93
|
+
@bindings.delete_if { |_, b| !b.coherent? }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def consciousness_report
|
|
97
|
+
experience = unified_experience
|
|
98
|
+
distribution = coherence_distribution
|
|
99
|
+
|
|
100
|
+
{
|
|
101
|
+
unified_experience: experience&.to_h,
|
|
102
|
+
fragmentation_index: fragmentation_index,
|
|
103
|
+
coherence_distribution: distribution,
|
|
104
|
+
stream_count: @streams.size,
|
|
105
|
+
binding_count: @bindings.size,
|
|
106
|
+
unbound_count: unbound_streams.size
|
|
107
|
+
}
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def to_h
|
|
111
|
+
{
|
|
112
|
+
stream_count: @streams.size,
|
|
113
|
+
binding_count: @bindings.size,
|
|
114
|
+
unbound_count: unbound_streams.size,
|
|
115
|
+
fragmentation: fragmentation_index
|
|
116
|
+
}
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
private
|
|
120
|
+
|
|
121
|
+
def compute_initial_coherence(stream_ids)
|
|
122
|
+
return 0.0 if stream_ids.empty?
|
|
123
|
+
|
|
124
|
+
saliences = stream_ids.filter_map { |id| @streams[id]&.salience }
|
|
125
|
+
return 0.0 if saliences.empty?
|
|
126
|
+
|
|
127
|
+
(saliences.sum / saliences.size).round(10)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def coherence_distribution
|
|
131
|
+
Constants::COHERENCE_LABELS.to_h do |_range, label|
|
|
132
|
+
count = @bindings.values.count { |b| b.coherence_label == label }
|
|
133
|
+
[label, count]
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def prune_streams_if_full
|
|
138
|
+
return if @streams.size < MAX_STREAMS
|
|
139
|
+
|
|
140
|
+
oldest = @streams.values.min_by(&:created_at)
|
|
141
|
+
@streams.delete(oldest.id) if oldest
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def prune_bindings_if_full
|
|
145
|
+
return if @bindings.size < MAX_BINDINGS
|
|
146
|
+
|
|
147
|
+
oldest = @bindings.values.min_by(&:created_at)
|
|
148
|
+
@bindings.delete(oldest.id) if oldest
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Integration
|
|
9
|
+
module PhenomenalBinding
|
|
10
|
+
module Helpers
|
|
11
|
+
class BindingUnit
|
|
12
|
+
include Constants
|
|
13
|
+
|
|
14
|
+
attr_reader :id, :stream_ids, :binding_type, :coherence, :attention_weight, :created_at
|
|
15
|
+
|
|
16
|
+
def initialize(stream_ids:, binding_type:, coherence:, attention_weight: 0.5)
|
|
17
|
+
@id = ::SecureRandom.uuid
|
|
18
|
+
@stream_ids = stream_ids.dup
|
|
19
|
+
@binding_type = binding_type
|
|
20
|
+
@coherence = coherence.clamp(0.0, 1.0)
|
|
21
|
+
@attention_weight = attention_weight.clamp(0.0, 1.0)
|
|
22
|
+
@created_at = Time.now.utc
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def add_stream(stream_id:)
|
|
26
|
+
@stream_ids << stream_id unless @stream_ids.include?(stream_id)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def remove_stream(stream_id:)
|
|
30
|
+
@stream_ids.delete(stream_id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def reinforce!
|
|
34
|
+
@coherence = (@coherence + BINDING_BOOST).clamp(0.0, 1.0)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def decay!
|
|
38
|
+
@coherence = (@coherence - BINDING_DECAY).clamp(0.0, 1.0)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def coherent?
|
|
42
|
+
@coherence >= COHERENCE_THRESHOLD
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def coherence_label
|
|
46
|
+
COHERENCE_LABELS.find { |range, _| range.cover?(@coherence) }&.last || :unbound
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def stream_count
|
|
50
|
+
@stream_ids.size
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def to_h
|
|
54
|
+
{
|
|
55
|
+
id: @id,
|
|
56
|
+
stream_ids: @stream_ids.dup,
|
|
57
|
+
binding_type: @binding_type,
|
|
58
|
+
coherence: @coherence.round(10),
|
|
59
|
+
attention_weight: @attention_weight.round(10),
|
|
60
|
+
coherent: coherent?,
|
|
61
|
+
coherence_label: coherence_label,
|
|
62
|
+
stream_count: stream_count,
|
|
63
|
+
created_at: @created_at
|
|
64
|
+
}
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module PhenomenalBinding
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
MAX_STREAMS = 100
|
|
11
|
+
MAX_BINDINGS = 200
|
|
12
|
+
|
|
13
|
+
COHERENCE_THRESHOLD = 0.6
|
|
14
|
+
BINDING_DECAY = 0.03
|
|
15
|
+
BINDING_BOOST = 0.08
|
|
16
|
+
DEFAULT_SALIENCE = 0.5
|
|
17
|
+
|
|
18
|
+
BINDING_TYPES = %i[perceptual conceptual temporal narrative emotional].freeze
|
|
19
|
+
|
|
20
|
+
COHERENCE_LABELS = {
|
|
21
|
+
(0.8..) => :unified,
|
|
22
|
+
(0.6...0.8) => :coherent,
|
|
23
|
+
(0.4...0.6) => :fragmented,
|
|
24
|
+
(0.2...0.4) => :dissociated,
|
|
25
|
+
(..0.2) => :unbound
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
STREAM_TYPES = %i[perception thought emotion memory intention prediction].freeze
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Integration
|
|
9
|
+
module PhenomenalBinding
|
|
10
|
+
module Helpers
|
|
11
|
+
class Stream
|
|
12
|
+
include Constants
|
|
13
|
+
|
|
14
|
+
attr_reader :id, :stream_type, :content, :salience, :timestamp, :domain, :created_at
|
|
15
|
+
|
|
16
|
+
def initialize(stream_type:, content:, salience: DEFAULT_SALIENCE, domain: nil, timestamp: nil)
|
|
17
|
+
@id = ::SecureRandom.uuid
|
|
18
|
+
@stream_type = stream_type
|
|
19
|
+
@content = content
|
|
20
|
+
@salience = salience.clamp(0.0, 1.0)
|
|
21
|
+
@domain = domain
|
|
22
|
+
@timestamp = timestamp || Time.now.utc
|
|
23
|
+
@created_at = Time.now.utc
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def salient?
|
|
27
|
+
@salience >= DEFAULT_SALIENCE
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def fresh?(window: 30)
|
|
31
|
+
(Time.now.utc - created_at) <= window
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def to_h
|
|
35
|
+
{
|
|
36
|
+
id: @id,
|
|
37
|
+
stream_type: @stream_type,
|
|
38
|
+
content: @content,
|
|
39
|
+
salience: @salience.round(10),
|
|
40
|
+
domain: @domain,
|
|
41
|
+
timestamp: @timestamp,
|
|
42
|
+
created_at: @created_at
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|