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,141 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Tessellation
|
|
8
|
+
module Helpers
|
|
9
|
+
class TessellationEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@tiles = {}
|
|
14
|
+
@mosaics = {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def create_tile(tile_type:, shape:, domain:, coverage: nil, fit_score: nil)
|
|
18
|
+
tile = Tile.new(tile_type: tile_type, shape: shape, domain: domain,
|
|
19
|
+
coverage: coverage, fit_score: fit_score)
|
|
20
|
+
@tiles[tile.id] = tile
|
|
21
|
+
mosaic = find_or_create_mosaic(domain: domain)
|
|
22
|
+
mosaic.add_tile(tile)
|
|
23
|
+
prune_tiles
|
|
24
|
+
tile
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def expand_tile(tile_id:, amount: COVERAGE_GROWTH)
|
|
28
|
+
tile = @tiles[tile_id]
|
|
29
|
+
return nil unless tile
|
|
30
|
+
|
|
31
|
+
tile.expand!(amount)
|
|
32
|
+
tile
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def shrink_all!
|
|
36
|
+
@tiles.each_value { |t| t.shrink!(COVERAGE_DECAY) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def connect_tiles(tile_a_id:, tile_b_id:)
|
|
40
|
+
a = @tiles[tile_a_id]
|
|
41
|
+
b = @tiles[tile_b_id]
|
|
42
|
+
return nil unless a && b
|
|
43
|
+
|
|
44
|
+
a.connect!(b.id)
|
|
45
|
+
b.connect!(a.id)
|
|
46
|
+
{ connected: true, tile_a: a.id, tile_b: b.id }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def tiles_by_domain(domain:) = @tiles.values.select { |t| t.domain == domain.to_sym }
|
|
50
|
+
def tiles_by_type(tile_type:) = @tiles.values.select { |t| t.tile_type == tile_type.to_sym }
|
|
51
|
+
def tiles_by_shape(shape:) = @tiles.values.select { |t| t.shape == shape.to_sym }
|
|
52
|
+
def gapped_tiles = @tiles.values.select(&:gapped?)
|
|
53
|
+
def seamless_tiles = @tiles.values.select(&:seamless?)
|
|
54
|
+
def isolated_tiles = @tiles.values.select(&:isolated?)
|
|
55
|
+
def full_coverage_tiles = @tiles.values.select(&:full_coverage?)
|
|
56
|
+
|
|
57
|
+
def overall_coverage
|
|
58
|
+
return 0.0 if @mosaics.empty?
|
|
59
|
+
|
|
60
|
+
(@mosaics.values.sum(&:total_coverage) / @mosaics.size).round(10)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def overall_fit
|
|
64
|
+
return 0.0 if @tiles.empty?
|
|
65
|
+
|
|
66
|
+
(@tiles.values.sum(&:fit_score) / @tiles.size).round(10)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def overall_coherence
|
|
70
|
+
return 0.0 if @mosaics.empty?
|
|
71
|
+
|
|
72
|
+
(@mosaics.values.sum(&:coherence) / @mosaics.size).round(10)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def domain_coverage
|
|
76
|
+
@mosaics.transform_values(&:total_coverage)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def gap_density
|
|
80
|
+
return 0.0 if @tiles.empty?
|
|
81
|
+
|
|
82
|
+
(gapped_tiles.size.to_f / @tiles.size).round(10)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def most_covered(limit: 5)
|
|
86
|
+
@tiles.values.sort_by { |t| -t.effective_coverage }.first(limit)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def least_covered(limit: 5)
|
|
90
|
+
@tiles.values.sort_by(&:effective_coverage).first(limit)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def tessellation_report
|
|
94
|
+
{
|
|
95
|
+
total_tiles: @tiles.size,
|
|
96
|
+
total_mosaics: @mosaics.size,
|
|
97
|
+
overall_coverage: overall_coverage,
|
|
98
|
+
coverage_label: Constants.label_for(COVERAGE_LABELS, overall_coverage),
|
|
99
|
+
overall_fit: overall_fit,
|
|
100
|
+
fit_label: Constants.label_for(FIT_LABELS, overall_fit),
|
|
101
|
+
overall_coherence: overall_coherence,
|
|
102
|
+
gap_density: gap_density,
|
|
103
|
+
gapped_count: gapped_tiles.size,
|
|
104
|
+
seamless_count: seamless_tiles.size,
|
|
105
|
+
isolated_count: isolated_tiles.size,
|
|
106
|
+
domain_coverage: domain_coverage,
|
|
107
|
+
mosaics: @mosaics.values.map(&:to_h)
|
|
108
|
+
}
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def to_h
|
|
112
|
+
{
|
|
113
|
+
total_tiles: @tiles.size,
|
|
114
|
+
total_mosaics: @mosaics.size,
|
|
115
|
+
coverage: overall_coverage,
|
|
116
|
+
fit: overall_fit,
|
|
117
|
+
coherence: overall_coherence
|
|
118
|
+
}
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
private
|
|
122
|
+
|
|
123
|
+
def find_or_create_mosaic(domain:)
|
|
124
|
+
key = domain.to_sym
|
|
125
|
+
@mosaics[key] ||= Mosaic.new(domain: key)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def prune_tiles
|
|
129
|
+
return if @tiles.size <= MAX_TILES
|
|
130
|
+
|
|
131
|
+
sorted = @tiles.values.sort_by(&:effective_coverage)
|
|
132
|
+
to_remove = sorted.first(@tiles.size - MAX_TILES)
|
|
133
|
+
to_remove.each { |t| @tiles.delete(t.id) }
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
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 Tessellation
|
|
8
|
+
module Helpers
|
|
9
|
+
class Tile
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :id, :tile_type, :shape, :domain, :coverage, :fit_score,
|
|
13
|
+
:adjacent_ids, :created_at
|
|
14
|
+
|
|
15
|
+
def initialize(tile_type:, shape:, domain:, coverage: nil, fit_score: nil)
|
|
16
|
+
@id = SecureRandom.uuid
|
|
17
|
+
@tile_type = tile_type.to_sym
|
|
18
|
+
@shape = shape.to_sym
|
|
19
|
+
@domain = domain.to_sym
|
|
20
|
+
@coverage = (coverage || DEFAULT_COVERAGE).to_f.clamp(0.0, 1.0)
|
|
21
|
+
@fit_score = (fit_score || 0.5).to_f.clamp(0.0, 1.0)
|
|
22
|
+
@adjacent_ids = []
|
|
23
|
+
@created_at = Time.now.utc
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def expand!(amount = COVERAGE_GROWTH)
|
|
27
|
+
@coverage = (@coverage + amount).clamp(0.0, 1.0).round(10)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def shrink!(amount = COVERAGE_DECAY)
|
|
31
|
+
@coverage = (@coverage - amount).clamp(0.0, 1.0).round(10)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def adjust_fit!(new_fit)
|
|
35
|
+
@fit_score = new_fit.to_f.clamp(0.0, 1.0).round(10)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def connect!(other_id)
|
|
39
|
+
@adjacent_ids << other_id unless @adjacent_ids.include?(other_id)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def full_coverage? = @coverage >= FULL_COVERAGE_THRESHOLD
|
|
43
|
+
def gapped? = @fit_score < GAP_THRESHOLD
|
|
44
|
+
def overlapping? = @fit_score > OVERLAP_THRESHOLD && @adjacent_ids.size > 3
|
|
45
|
+
def isolated? = @adjacent_ids.empty?
|
|
46
|
+
def well_connected? = @adjacent_ids.size >= 3
|
|
47
|
+
def seamless? = @fit_score >= 0.8
|
|
48
|
+
|
|
49
|
+
def effective_coverage
|
|
50
|
+
penalty = overlapping? ? OVERLAP_PENALTY * @adjacent_ids.size : 0.0
|
|
51
|
+
(@coverage - penalty).clamp(0.0, 1.0).round(10)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def to_h
|
|
55
|
+
{
|
|
56
|
+
id: @id,
|
|
57
|
+
tile_type: @tile_type,
|
|
58
|
+
shape: @shape,
|
|
59
|
+
domain: @domain,
|
|
60
|
+
coverage: @coverage.round(10),
|
|
61
|
+
fit_score: @fit_score.round(10),
|
|
62
|
+
effective_coverage: effective_coverage,
|
|
63
|
+
adjacent_count: @adjacent_ids.size,
|
|
64
|
+
full_coverage: full_coverage?,
|
|
65
|
+
gapped: gapped?,
|
|
66
|
+
seamless: seamless?,
|
|
67
|
+
created_at: @created_at.iso8601
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Tessellation
|
|
8
|
+
module Runners
|
|
9
|
+
module CognitiveTessellation
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
11
|
+
|
|
12
|
+
def create_tile(tile_type:, shape:, domain:, coverage: nil, fit_score: nil, engine: nil, **)
|
|
13
|
+
eng = engine || @default_engine
|
|
14
|
+
tile = eng.create_tile(tile_type: tile_type, shape: shape, domain: domain,
|
|
15
|
+
coverage: coverage, fit_score: fit_score)
|
|
16
|
+
{ success: true, tile: tile.to_h }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def expand_tile(tile_id:, amount: nil, engine: nil, **)
|
|
20
|
+
eng = engine || @default_engine
|
|
21
|
+
tile = eng.expand_tile(tile_id: tile_id, amount: amount || Helpers::Constants::COVERAGE_GROWTH)
|
|
22
|
+
return { success: false, error: 'tile not found' } unless tile
|
|
23
|
+
|
|
24
|
+
{ success: true, tile: tile.to_h }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def connect_tiles(tile_a_id:, tile_b_id:, engine: nil, **)
|
|
28
|
+
eng = engine || @default_engine
|
|
29
|
+
result = eng.connect_tiles(tile_a_id: tile_a_id, tile_b_id: tile_b_id)
|
|
30
|
+
return { success: false, error: 'one or both tiles not found' } unless result
|
|
31
|
+
|
|
32
|
+
{ success: true, **result }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def shrink_all(engine: nil, **)
|
|
36
|
+
eng = engine || @default_engine
|
|
37
|
+
eng.shrink_all!
|
|
38
|
+
{ success: true }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def list_gaps(engine: nil, **)
|
|
42
|
+
eng = engine || @default_engine
|
|
43
|
+
gaps = eng.gapped_tiles
|
|
44
|
+
{ success: true, count: gaps.size, tiles: gaps.map(&:to_h) }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def tessellation_status(engine: nil, **)
|
|
48
|
+
eng = engine || @default_engine
|
|
49
|
+
report = eng.tessellation_report
|
|
50
|
+
{ success: true, **report }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
require_relative 'tessellation/version'
|
|
6
|
+
require_relative 'tessellation/helpers/constants'
|
|
7
|
+
require_relative 'tessellation/helpers/tile'
|
|
8
|
+
require_relative 'tessellation/helpers/mosaic'
|
|
9
|
+
require_relative 'tessellation/helpers/tessellation_engine'
|
|
10
|
+
require_relative 'tessellation/runners/cognitive_tessellation'
|
|
11
|
+
require_relative 'tessellation/client'
|
|
12
|
+
|
|
13
|
+
module Legion
|
|
14
|
+
module Extensions
|
|
15
|
+
module Agentic
|
|
16
|
+
module Integration
|
|
17
|
+
module Tessellation
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Zeitgeist
|
|
8
|
+
module Helpers
|
|
9
|
+
class CognitiveSignal
|
|
10
|
+
attr_reader :id, :source_subsystem, :domain, :intensity, :valence, :timestamp
|
|
11
|
+
|
|
12
|
+
def initialize(source_subsystem:, domain:, intensity: Constants::DEFAULT_INTENSITY,
|
|
13
|
+
valence: 0.0, timestamp: nil)
|
|
14
|
+
@id = SecureRandom.uuid
|
|
15
|
+
@source_subsystem = source_subsystem.to_sym
|
|
16
|
+
@domain = domain.to_sym
|
|
17
|
+
@intensity = intensity.to_f.clamp(0.0, 1.0)
|
|
18
|
+
@valence = valence.to_f.clamp(-1.0, 1.0)
|
|
19
|
+
@timestamp = timestamp || Time.now.utc
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_h
|
|
23
|
+
{
|
|
24
|
+
id: @id,
|
|
25
|
+
source_subsystem: @source_subsystem,
|
|
26
|
+
domain: @domain,
|
|
27
|
+
intensity: @intensity.round(10),
|
|
28
|
+
valence: @valence.round(10),
|
|
29
|
+
timestamp: @timestamp.iso8601
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Zeitgeist
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
MAX_SIGNALS = 1000
|
|
11
|
+
WINDOW_SIZE = 100
|
|
12
|
+
DEFAULT_INTENSITY = 0.5
|
|
13
|
+
MOMENTUM_THRESHOLD = 0.3
|
|
14
|
+
CONVERGENCE_THRESHOLD = 0.7
|
|
15
|
+
DIVERGENCE_THRESHOLD = 0.3
|
|
16
|
+
|
|
17
|
+
SIGNAL_DOMAINS = %i[
|
|
18
|
+
threat
|
|
19
|
+
opportunity
|
|
20
|
+
curiosity
|
|
21
|
+
anxiety
|
|
22
|
+
creativity
|
|
23
|
+
routine
|
|
24
|
+
social
|
|
25
|
+
abstract
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
MOOD_LABELS = {
|
|
29
|
+
(0.8..) => :euphoric,
|
|
30
|
+
(0.6...0.8) => :elevated,
|
|
31
|
+
(0.4...0.6) => :neutral,
|
|
32
|
+
(0.2...0.4) => :subdued,
|
|
33
|
+
(..0.2) => :suppressed
|
|
34
|
+
}.freeze
|
|
35
|
+
|
|
36
|
+
CONVERGENCE_LABELS = {
|
|
37
|
+
(0.8..) => :unified,
|
|
38
|
+
(0.6...0.8) => :aligned,
|
|
39
|
+
(0.4...0.6) => :mixed,
|
|
40
|
+
(0.2...0.4) => :fragmented,
|
|
41
|
+
(..0.2) => :divergent
|
|
42
|
+
}.freeze
|
|
43
|
+
|
|
44
|
+
MOMENTUM_LABELS = {
|
|
45
|
+
(0.6..) => :surging,
|
|
46
|
+
(0.3...0.6) => :building,
|
|
47
|
+
(0.0...0.3) => :steady,
|
|
48
|
+
(-0.3...0.0) => :fading,
|
|
49
|
+
(..-0.3) => :collapsing
|
|
50
|
+
}.freeze
|
|
51
|
+
|
|
52
|
+
def self.label_for(labels_hash, value)
|
|
53
|
+
labels_hash.each do |range, label|
|
|
54
|
+
return label if range.cover?(value)
|
|
55
|
+
end
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Zeitgeist
|
|
8
|
+
module Helpers
|
|
9
|
+
class TrendWindow
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :signals, :window_size
|
|
13
|
+
|
|
14
|
+
def initialize(window_size: WINDOW_SIZE)
|
|
15
|
+
@signals = []
|
|
16
|
+
@window_size = window_size
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def add(signal)
|
|
20
|
+
@signals << signal
|
|
21
|
+
@signals.shift while @signals.size > @window_size
|
|
22
|
+
self
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def dominant_domain
|
|
26
|
+
return nil if @signals.empty?
|
|
27
|
+
|
|
28
|
+
counts = Hash.new(0.0)
|
|
29
|
+
@signals.each { |s| counts[s.domain] += s.intensity }
|
|
30
|
+
counts.max_by { |_d, weight| weight }&.first
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def dominant_valence
|
|
34
|
+
return 0.0 if @signals.empty?
|
|
35
|
+
|
|
36
|
+
weighted_sum = @signals.sum { |s| s.valence * s.intensity }
|
|
37
|
+
total_intensity = @signals.sum(&:intensity)
|
|
38
|
+
return 0.0 if total_intensity.zero?
|
|
39
|
+
|
|
40
|
+
(weighted_sum / total_intensity).clamp(-1.0, 1.0).round(10)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def momentum
|
|
44
|
+
return 0.0 if @signals.size < 2
|
|
45
|
+
|
|
46
|
+
half = @signals.size / 2
|
|
47
|
+
first_half = @signals.first(half)
|
|
48
|
+
second_half = @signals.last(half)
|
|
49
|
+
|
|
50
|
+
avg_intensity = ->(arr) { arr.sum(&:intensity) / arr.size.to_f }
|
|
51
|
+
delta = avg_intensity.call(second_half) - avg_intensity.call(first_half)
|
|
52
|
+
delta.clamp(-1.0, 1.0).round(10)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def accelerating?
|
|
56
|
+
momentum > MOMENTUM_THRESHOLD
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def decelerating?
|
|
60
|
+
momentum < -MOMENTUM_THRESHOLD
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def to_h
|
|
64
|
+
{
|
|
65
|
+
size: @signals.size,
|
|
66
|
+
window_size: @window_size,
|
|
67
|
+
dominant_domain: dominant_domain,
|
|
68
|
+
dominant_valence: dominant_valence,
|
|
69
|
+
momentum: momentum,
|
|
70
|
+
accelerating: accelerating?,
|
|
71
|
+
decelerating: decelerating?
|
|
72
|
+
}
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Zeitgeist
|
|
8
|
+
module Helpers
|
|
9
|
+
class ZeitgeistEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :signals, :trend_window
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@signals = []
|
|
16
|
+
@trend_window = TrendWindow.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def ingest(source_subsystem:, domain:, intensity: DEFAULT_INTENSITY, valence: 0.0, timestamp: nil)
|
|
20
|
+
signal = CognitiveSignal.new(
|
|
21
|
+
source_subsystem: source_subsystem,
|
|
22
|
+
domain: domain,
|
|
23
|
+
intensity: intensity,
|
|
24
|
+
valence: valence,
|
|
25
|
+
timestamp: timestamp
|
|
26
|
+
)
|
|
27
|
+
@signals << signal
|
|
28
|
+
@signals.shift while @signals.size > MAX_SIGNALS
|
|
29
|
+
@trend_window.add(signal)
|
|
30
|
+
signal
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def dominant_themes(limit: 5)
|
|
34
|
+
return [] if @signals.empty?
|
|
35
|
+
|
|
36
|
+
weights = Hash.new(0.0)
|
|
37
|
+
@signals.each { |s| weights[s.domain] += s.intensity }
|
|
38
|
+
weights.sort_by { |_d, w| -w }.first(limit).map do |domain, weight|
|
|
39
|
+
{ domain: domain, weight: weight.round(10) }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def collective_mood
|
|
44
|
+
return 0.0 if @signals.empty?
|
|
45
|
+
|
|
46
|
+
weighted_sum = @signals.sum { |s| s.valence * s.intensity }
|
|
47
|
+
total = @signals.sum(&:intensity)
|
|
48
|
+
return 0.0 if total.zero?
|
|
49
|
+
|
|
50
|
+
(weighted_sum / total).clamp(-1.0, 1.0).round(10)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def cognitive_convergence
|
|
54
|
+
return 1.0 if @signals.empty?
|
|
55
|
+
|
|
56
|
+
subsystems = @signals.map(&:source_subsystem).uniq
|
|
57
|
+
return 1.0 if subsystems.size <= 1
|
|
58
|
+
|
|
59
|
+
compute_alignment(subsystems)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def rising_domains(window_size: WINDOW_SIZE / 2)
|
|
63
|
+
return [] if @signals.size < window_size
|
|
64
|
+
|
|
65
|
+
recent = @signals.last(window_size)
|
|
66
|
+
earlier = @signals.last(window_size * 2).first(window_size)
|
|
67
|
+
|
|
68
|
+
deltas = domain_intensity_deltas(recent, earlier)
|
|
69
|
+
deltas.select { |d| d[:delta] > 0.0 }.sort_by { |d| -d[:delta] }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def falling_domains(window_size: WINDOW_SIZE / 2)
|
|
73
|
+
return [] if @signals.size < window_size
|
|
74
|
+
|
|
75
|
+
recent = @signals.last(window_size)
|
|
76
|
+
earlier = @signals.last(window_size * 2).first(window_size)
|
|
77
|
+
|
|
78
|
+
deltas = domain_intensity_deltas(recent, earlier)
|
|
79
|
+
deltas.select { |d| d[:delta] < 0.0 }.sort_by { |d| d[:delta] }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def divergence_alert?
|
|
83
|
+
cognitive_convergence < DIVERGENCE_THRESHOLD
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def zeitgeist_report
|
|
87
|
+
mood_value = collective_mood
|
|
88
|
+
conv_value = cognitive_convergence
|
|
89
|
+
mom_value = @trend_window.momentum
|
|
90
|
+
|
|
91
|
+
{
|
|
92
|
+
signal_count: @signals.size,
|
|
93
|
+
dominant_themes: dominant_themes,
|
|
94
|
+
collective_mood: mood_value,
|
|
95
|
+
mood_label: Constants.label_for(MOOD_LABELS, normalize_mood(mood_value)),
|
|
96
|
+
convergence: conv_value,
|
|
97
|
+
convergence_label: Constants.label_for(CONVERGENCE_LABELS, conv_value),
|
|
98
|
+
momentum: mom_value,
|
|
99
|
+
momentum_label: Constants.label_for(MOMENTUM_LABELS, mom_value),
|
|
100
|
+
rising_domains: rising_domains,
|
|
101
|
+
falling_domains: falling_domains,
|
|
102
|
+
divergence_alert: divergence_alert?,
|
|
103
|
+
trend_window: @trend_window.to_h
|
|
104
|
+
}
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def compute_alignment(subsystems)
|
|
110
|
+
subsystem_domains = subsystems.to_h do |sub|
|
|
111
|
+
subs_signals = @signals.select { |s| s.source_subsystem == sub }
|
|
112
|
+
[sub, compute_dominant_domain(subs_signals)]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
overall_dominant = dominant_themes(limit: 1).first&.fetch(:domain)
|
|
116
|
+
return 0.5 unless overall_dominant
|
|
117
|
+
|
|
118
|
+
aligned = subsystem_domains.count { |_sub, dom| dom == overall_dominant }
|
|
119
|
+
(aligned.to_f / subsystems.size).round(10)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def compute_dominant_domain(subs_signals)
|
|
123
|
+
return nil if subs_signals.empty?
|
|
124
|
+
|
|
125
|
+
weights = Hash.new(0.0)
|
|
126
|
+
subs_signals.each { |s| weights[s.domain] += s.intensity }
|
|
127
|
+
weights.max_by { |_d, w| w }&.first
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def domain_intensity_deltas(recent, earlier)
|
|
131
|
+
recent_weights = aggregate_domain_weights(recent)
|
|
132
|
+
earlier_weights = aggregate_domain_weights(earlier)
|
|
133
|
+
|
|
134
|
+
all_domains = (recent_weights.keys + earlier_weights.keys).uniq
|
|
135
|
+
all_domains.map do |domain|
|
|
136
|
+
r = recent_weights.fetch(domain, 0.0)
|
|
137
|
+
e = earlier_weights.fetch(domain, 0.0)
|
|
138
|
+
{ domain: domain, delta: (r - e).round(10) }
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def aggregate_domain_weights(sigs)
|
|
143
|
+
weights = Hash.new(0.0)
|
|
144
|
+
sigs.each { |s| weights[s.domain] += s.intensity }
|
|
145
|
+
weights
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def normalize_mood(mood_value)
|
|
149
|
+
((mood_value + 1.0) / 2.0).clamp(0.0, 1.0)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|