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,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Mosaic
|
|
8
|
+
module Helpers
|
|
9
|
+
class Mosaic
|
|
10
|
+
attr_reader :id, :name, :pattern_category, :tessera_ids,
|
|
11
|
+
:capacity, :created_at
|
|
12
|
+
attr_accessor :grout_strength
|
|
13
|
+
|
|
14
|
+
def initialize(name:, pattern_category:, capacity: 50, grout_strength: nil)
|
|
15
|
+
validate_pattern!(pattern_category)
|
|
16
|
+
@id = SecureRandom.uuid
|
|
17
|
+
@name = name.to_s
|
|
18
|
+
@pattern_category = pattern_category.to_sym
|
|
19
|
+
@tessera_ids = []
|
|
20
|
+
@capacity = capacity.to_i.clamp(1, 500)
|
|
21
|
+
@grout_strength = (grout_strength || 0.8).to_f.clamp(0.0, 1.0).round(10)
|
|
22
|
+
@created_at = Time.now.utc
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def add_tessera(tessera_id)
|
|
26
|
+
return false if @tessera_ids.include?(tessera_id)
|
|
27
|
+
return false if full?
|
|
28
|
+
|
|
29
|
+
@tessera_ids << tessera_id
|
|
30
|
+
true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def remove_tessera(tessera_id)
|
|
34
|
+
@tessera_ids.delete(tessera_id) ? true : false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def size
|
|
38
|
+
@tessera_ids.size
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def full?
|
|
42
|
+
@tessera_ids.size >= @capacity
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def empty?
|
|
46
|
+
@tessera_ids.empty?
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def completeness
|
|
50
|
+
return 0.0 if @capacity.zero?
|
|
51
|
+
|
|
52
|
+
(@tessera_ids.size.to_f / @capacity).clamp(0.0, 1.0).round(10)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def erode_grout!(rate: Constants::GROUT_DECAY)
|
|
56
|
+
@grout_strength = (@grout_strength - rate.abs).clamp(0.0, 1.0).round(10)
|
|
57
|
+
self
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def reinforce_grout!(boost: 0.1)
|
|
61
|
+
@grout_strength = (@grout_strength + boost.abs).clamp(0.0, 1.0).round(10)
|
|
62
|
+
self
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def crumbling?
|
|
66
|
+
@grout_strength < 0.2
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def completeness_label
|
|
70
|
+
Constants.label_for(Constants::COMPLETENESS_LABELS, completeness)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def gap_count
|
|
74
|
+
@capacity - @tessera_ids.size
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def to_h
|
|
78
|
+
{
|
|
79
|
+
id: @id,
|
|
80
|
+
name: @name,
|
|
81
|
+
pattern_category: @pattern_category,
|
|
82
|
+
tessera_ids: @tessera_ids.dup,
|
|
83
|
+
size: size,
|
|
84
|
+
capacity: @capacity,
|
|
85
|
+
completeness: completeness,
|
|
86
|
+
completeness_label: completeness_label,
|
|
87
|
+
grout_strength: @grout_strength,
|
|
88
|
+
gap_count: gap_count,
|
|
89
|
+
full: full?,
|
|
90
|
+
empty: empty?,
|
|
91
|
+
crumbling: crumbling?,
|
|
92
|
+
created_at: @created_at
|
|
93
|
+
}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
def validate_pattern!(val)
|
|
99
|
+
return if Constants::PATTERN_CATEGORIES.include?(val.to_sym)
|
|
100
|
+
|
|
101
|
+
raise ArgumentError,
|
|
102
|
+
"unknown pattern category: #{val.inspect}; " \
|
|
103
|
+
"must be one of #{Constants::PATTERN_CATEGORIES.inspect}"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Mosaic
|
|
8
|
+
module Helpers
|
|
9
|
+
class MosaicEngine
|
|
10
|
+
def initialize
|
|
11
|
+
@tesserae = {}
|
|
12
|
+
@mosaics = {}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create_tessera(material:, domain:, content:, color: nil, fit_quality: nil)
|
|
16
|
+
raise ArgumentError, 'tessera limit reached' if @tesserae.size >= Constants::MAX_TESSERAE
|
|
17
|
+
|
|
18
|
+
t = Tessera.new(material: material, domain: domain, content: content,
|
|
19
|
+
color: color, fit_quality: fit_quality)
|
|
20
|
+
@tesserae[t.id] = t
|
|
21
|
+
t
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_mosaic(name:, pattern_category:, capacity: 50, grout_strength: nil)
|
|
25
|
+
raise ArgumentError, 'mosaic limit reached' if @mosaics.size >= Constants::MAX_MOSAICS
|
|
26
|
+
|
|
27
|
+
m = Mosaic.new(name: name, pattern_category: pattern_category,
|
|
28
|
+
capacity: capacity, grout_strength: grout_strength)
|
|
29
|
+
@mosaics[m.id] = m
|
|
30
|
+
m
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def place_tessera(tessera_id:, mosaic_id:)
|
|
34
|
+
tessera = fetch_tessera(tessera_id)
|
|
35
|
+
mosaic = fetch_mosaic(mosaic_id)
|
|
36
|
+
|
|
37
|
+
raise ArgumentError, 'tessera already placed' if tessera.placed?
|
|
38
|
+
raise ArgumentError, 'mosaic is full' if mosaic.full?
|
|
39
|
+
|
|
40
|
+
mosaic.add_tessera(tessera_id)
|
|
41
|
+
tessera.place!(mosaic_id)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def erode_all_grout!(rate: Constants::GROUT_DECAY)
|
|
45
|
+
@mosaics.each_value { |m| m.erode_grout!(rate: rate) }
|
|
46
|
+
crumbling = @mosaics.count { |_, m| m.crumbling? }
|
|
47
|
+
{ total: @mosaics.size, crumbling: crumbling }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def most_complete(limit: 5)
|
|
51
|
+
@mosaics.values.sort_by { |m| -m.completeness }.first(limit)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def most_gaps(limit: 5)
|
|
55
|
+
@mosaics.values.sort_by { |m| -m.gap_count }.first(limit)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def loose_tesserae
|
|
59
|
+
@tesserae.values.select(&:loose?)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def tesserae_by_material
|
|
63
|
+
counts = Constants::MATERIAL_TYPES.to_h { |m| [m, 0] }
|
|
64
|
+
@tesserae.each_value { |t| counts[t.material] += 1 }
|
|
65
|
+
counts
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def coherence(mosaic_id:)
|
|
69
|
+
mosaic = fetch_mosaic(mosaic_id)
|
|
70
|
+
return 0.0 if mosaic.empty?
|
|
71
|
+
|
|
72
|
+
placed = mosaic.tessera_ids.filter_map { |id| @tesserae[id] }
|
|
73
|
+
return 0.0 if placed.empty?
|
|
74
|
+
|
|
75
|
+
avg_fit = placed.sum(&:fit_quality) / placed.size
|
|
76
|
+
grout_factor = mosaic.grout_strength
|
|
77
|
+
((avg_fit + grout_factor) / 2.0).clamp(0.0, 1.0).round(10)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def coherence_label(mosaic_id:)
|
|
81
|
+
Constants.label_for(Constants::COHERENCE_LABELS, coherence(mosaic_id: mosaic_id))
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def mosaic_report
|
|
85
|
+
{
|
|
86
|
+
total_tesserae: @tesserae.size,
|
|
87
|
+
total_mosaics: @mosaics.size,
|
|
88
|
+
loose_count: loose_tesserae.size,
|
|
89
|
+
by_material: tesserae_by_material,
|
|
90
|
+
crumbling_count: @mosaics.count { |_, m| m.crumbling? },
|
|
91
|
+
avg_completeness: avg_completeness
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def all_tesserae
|
|
96
|
+
@tesserae.values
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def all_mosaics
|
|
100
|
+
@mosaics.values
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
private
|
|
104
|
+
|
|
105
|
+
def fetch_tessera(id)
|
|
106
|
+
@tesserae.fetch(id) { raise ArgumentError, "tessera not found: #{id}" }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def fetch_mosaic(id)
|
|
110
|
+
@mosaics.fetch(id) { raise ArgumentError, "mosaic not found: #{id}" }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def avg_completeness
|
|
114
|
+
return 0.0 if @mosaics.empty?
|
|
115
|
+
|
|
116
|
+
(@mosaics.values.sum(&:completeness) / @mosaics.size).round(10)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Mosaic
|
|
8
|
+
module Helpers
|
|
9
|
+
class Tessera
|
|
10
|
+
attr_reader :id, :material, :domain, :content,
|
|
11
|
+
:color, :placed_at, :mosaic_id
|
|
12
|
+
attr_accessor :fit_quality
|
|
13
|
+
|
|
14
|
+
def initialize(material:, domain:, content:,
|
|
15
|
+
color: nil, fit_quality: nil)
|
|
16
|
+
validate_material!(material)
|
|
17
|
+
@id = SecureRandom.uuid
|
|
18
|
+
@material = material.to_sym
|
|
19
|
+
@domain = domain.to_sym
|
|
20
|
+
@content = content.to_s
|
|
21
|
+
@color = (color || random_color).to_sym
|
|
22
|
+
@fit_quality = (fit_quality || 0.5).to_f.clamp(0.0, 1.0).round(10)
|
|
23
|
+
@placed_at = nil
|
|
24
|
+
@mosaic_id = nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def place!(mosaic_id)
|
|
28
|
+
@mosaic_id = mosaic_id
|
|
29
|
+
@placed_at = Time.now.utc
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def placed?
|
|
34
|
+
!@mosaic_id.nil?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def loose?
|
|
38
|
+
@mosaic_id.nil?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def perfect_fit?
|
|
42
|
+
@fit_quality >= 0.9
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def poor_fit?
|
|
46
|
+
@fit_quality < 0.3
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def to_h
|
|
50
|
+
{
|
|
51
|
+
id: @id,
|
|
52
|
+
material: @material,
|
|
53
|
+
domain: @domain,
|
|
54
|
+
content: @content,
|
|
55
|
+
color: @color,
|
|
56
|
+
fit_quality: @fit_quality,
|
|
57
|
+
placed: placed?,
|
|
58
|
+
loose: loose?,
|
|
59
|
+
perfect_fit: perfect_fit?,
|
|
60
|
+
poor_fit: poor_fit?,
|
|
61
|
+
mosaic_id: @mosaic_id,
|
|
62
|
+
placed_at: @placed_at
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def random_color
|
|
69
|
+
%i[red blue green gold white black silver amber
|
|
70
|
+
turquoise crimson ivory jade].sample
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def validate_material!(val)
|
|
74
|
+
return if Constants::MATERIAL_TYPES.include?(val.to_sym)
|
|
75
|
+
|
|
76
|
+
raise ArgumentError,
|
|
77
|
+
"unknown material: #{val.inspect}; " \
|
|
78
|
+
"must be one of #{Constants::MATERIAL_TYPES.inspect}"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Mosaic
|
|
8
|
+
module Runners
|
|
9
|
+
module CognitiveMosaic
|
|
10
|
+
extend self
|
|
11
|
+
|
|
12
|
+
def create_tessera(material:, domain:, content:,
|
|
13
|
+
color: nil, fit_quality: nil, engine: nil, **)
|
|
14
|
+
eng = resolve_engine(engine)
|
|
15
|
+
t = eng.create_tessera(material: material, domain: domain,
|
|
16
|
+
content: content, color: color,
|
|
17
|
+
fit_quality: fit_quality)
|
|
18
|
+
{ success: true, tessera: t.to_h }
|
|
19
|
+
rescue ArgumentError => e
|
|
20
|
+
{ success: false, error: e.message }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create_mosaic(name:, pattern_category:, capacity: 50,
|
|
24
|
+
grout_strength: nil, engine: nil, **)
|
|
25
|
+
eng = resolve_engine(engine)
|
|
26
|
+
m = eng.create_mosaic(name: name, pattern_category: pattern_category,
|
|
27
|
+
capacity: capacity, grout_strength: grout_strength)
|
|
28
|
+
{ success: true, mosaic: m.to_h }
|
|
29
|
+
rescue ArgumentError => e
|
|
30
|
+
{ success: false, error: e.message }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def place_tessera(tessera_id:, mosaic_id:, engine: nil, **)
|
|
34
|
+
eng = resolve_engine(engine)
|
|
35
|
+
t = eng.place_tessera(tessera_id: tessera_id, mosaic_id: mosaic_id)
|
|
36
|
+
{ success: true, tessera: t.to_h }
|
|
37
|
+
rescue ArgumentError => e
|
|
38
|
+
{ success: false, error: e.message }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def list_tesserae(engine: nil, material: nil, **)
|
|
42
|
+
eng = resolve_engine(engine)
|
|
43
|
+
results = eng.all_tesserae
|
|
44
|
+
results = results.select { |t| t.material == material.to_sym } if material
|
|
45
|
+
{ success: true, tesserae: results.map(&:to_h), count: results.size }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def list_mosaics(engine: nil, **)
|
|
49
|
+
eng = resolve_engine(engine)
|
|
50
|
+
{ success: true, mosaics: eng.all_mosaics.map(&:to_h),
|
|
51
|
+
count: eng.all_mosaics.size }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def mosaic_status(engine: nil, **)
|
|
55
|
+
eng = resolve_engine(engine)
|
|
56
|
+
{ success: true, report: eng.mosaic_report }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def resolve_engine(engine)
|
|
64
|
+
engine || default_engine
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def default_engine
|
|
68
|
+
@default_engine ||= Helpers::MosaicEngine.new
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
require_relative 'mosaic/version'
|
|
6
|
+
require_relative 'mosaic/helpers/constants'
|
|
7
|
+
require_relative 'mosaic/helpers/tessera'
|
|
8
|
+
require_relative 'mosaic/helpers/mosaic'
|
|
9
|
+
require_relative 'mosaic/helpers/mosaic_engine'
|
|
10
|
+
require_relative 'mosaic/runners/cognitive_mosaic'
|
|
11
|
+
require_relative 'mosaic/client'
|
|
12
|
+
|
|
13
|
+
module Legion
|
|
14
|
+
module Extensions
|
|
15
|
+
module Agentic
|
|
16
|
+
module Integration
|
|
17
|
+
module Mosaic
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Mycelium
|
|
8
|
+
class Client
|
|
9
|
+
include Runners::CognitiveMycelium
|
|
10
|
+
|
|
11
|
+
def initialize(engine: nil)
|
|
12
|
+
@default_engine = engine || Helpers::MyceliumEngine.new
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
module Constants
|
|
10
|
+
MAX_NODES = 200
|
|
11
|
+
MAX_HYPHAE = 500
|
|
12
|
+
MAX_FRUITING_BODIES = 100
|
|
13
|
+
NUTRIENT_DECAY = 0.03
|
|
14
|
+
TRANSFER_EFFICIENCY = 0.8
|
|
15
|
+
FRUITING_THRESHOLD = 0.7
|
|
16
|
+
|
|
17
|
+
NODE_TYPES = %i[
|
|
18
|
+
knowledge_cluster insight_node memory_node
|
|
19
|
+
skill_node pattern_node creative_node
|
|
20
|
+
].freeze
|
|
21
|
+
|
|
22
|
+
NUTRIENT_TYPES = %i[
|
|
23
|
+
information experience emotional_energy
|
|
24
|
+
novelty pattern_recognition creative_potential
|
|
25
|
+
].freeze
|
|
26
|
+
|
|
27
|
+
HYPHA_STATES = %i[growing mature dormant decaying].freeze
|
|
28
|
+
|
|
29
|
+
FRUITING_TYPES = %i[
|
|
30
|
+
insight breakthrough connection analogy
|
|
31
|
+
synthesis innovation
|
|
32
|
+
].freeze
|
|
33
|
+
|
|
34
|
+
NETWORK_HEALTH_LABELS = [
|
|
35
|
+
[0.8..1.0, :thriving],
|
|
36
|
+
[0.6..0.8, :healthy],
|
|
37
|
+
[0.4..0.6, :stable],
|
|
38
|
+
[0.2..0.4, :stressed],
|
|
39
|
+
[0.0..0.2, :depleted]
|
|
40
|
+
].freeze
|
|
41
|
+
|
|
42
|
+
def self.label_for(table, value)
|
|
43
|
+
table.each { |range, label| return label if range.cover?(value) }
|
|
44
|
+
table.last.last
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
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 FruitingBody
|
|
10
|
+
attr_reader :id, :fruiting_type, :source_node_id,
|
|
11
|
+
:content, :potency, :emerged_at
|
|
12
|
+
|
|
13
|
+
def initialize(fruiting_type:, source_node_id:,
|
|
14
|
+
content:, potency: 0.5)
|
|
15
|
+
validate_type!(fruiting_type)
|
|
16
|
+
@id = SecureRandom.uuid
|
|
17
|
+
@fruiting_type = fruiting_type.to_sym
|
|
18
|
+
@source_node_id = source_node_id
|
|
19
|
+
@content = content.to_s
|
|
20
|
+
@potency = potency.to_f.clamp(0.0, 1.0).round(10)
|
|
21
|
+
@emerged_at = Time.now.utc
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_h
|
|
25
|
+
{
|
|
26
|
+
id: @id,
|
|
27
|
+
fruiting_type: @fruiting_type,
|
|
28
|
+
source_node_id: @source_node_id,
|
|
29
|
+
content: @content,
|
|
30
|
+
potency: @potency,
|
|
31
|
+
emerged_at: @emerged_at
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def validate_type!(val)
|
|
38
|
+
return if Constants::FRUITING_TYPES.include?(val.to_sym)
|
|
39
|
+
|
|
40
|
+
raise ArgumentError,
|
|
41
|
+
"unknown fruiting type: #{val.inspect}; " \
|
|
42
|
+
"must be one of #{Constants::FRUITING_TYPES.inspect}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
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 Hypha
|
|
10
|
+
attr_reader :id, :source_id, :target_id, :nutrient_type,
|
|
11
|
+
:created_at
|
|
12
|
+
attr_accessor :strength, :state
|
|
13
|
+
|
|
14
|
+
def initialize(source_id:, target_id:, nutrient_type:,
|
|
15
|
+
strength: 0.5)
|
|
16
|
+
validate_nutrient!(nutrient_type)
|
|
17
|
+
@id = SecureRandom.uuid
|
|
18
|
+
@source_id = source_id
|
|
19
|
+
@target_id = target_id
|
|
20
|
+
@nutrient_type = nutrient_type.to_sym
|
|
21
|
+
@strength = strength.to_f.clamp(0.0, 1.0).round(10)
|
|
22
|
+
@state = :growing
|
|
23
|
+
@created_at = Time.now.utc
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def reinforce!(amount: 0.1)
|
|
27
|
+
@strength = (@strength + amount.abs).clamp(0.0, 1.0).round(10)
|
|
28
|
+
@state = :mature if @strength >= 0.6
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def decay!(rate: Constants::NUTRIENT_DECAY)
|
|
33
|
+
@strength = (@strength - rate.abs).clamp(0.0, 1.0).round(10)
|
|
34
|
+
@state = :decaying if @strength < 0.2
|
|
35
|
+
@state = :dormant if @strength < 0.4 && @state == :mature
|
|
36
|
+
self
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def transfer_capacity
|
|
40
|
+
(@strength * Constants::TRANSFER_EFFICIENCY).round(10)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def active?
|
|
44
|
+
%i[growing mature].include?(@state)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_h
|
|
48
|
+
{
|
|
49
|
+
id: @id,
|
|
50
|
+
source_id: @source_id,
|
|
51
|
+
target_id: @target_id,
|
|
52
|
+
nutrient_type: @nutrient_type,
|
|
53
|
+
strength: @strength,
|
|
54
|
+
state: @state,
|
|
55
|
+
transfer_capacity: transfer_capacity,
|
|
56
|
+
active: active?,
|
|
57
|
+
created_at: @created_at
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def validate_nutrient!(val)
|
|
64
|
+
return if Constants::NUTRIENT_TYPES.include?(val.to_sym)
|
|
65
|
+
|
|
66
|
+
raise ArgumentError,
|
|
67
|
+
"unknown nutrient type: #{val.inspect}; " \
|
|
68
|
+
"must be one of #{Constants::NUTRIENT_TYPES.inspect}"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|