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,213 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Synthesis
|
|
8
|
+
module Helpers
|
|
9
|
+
class SynthesisEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :streams, :syntheses
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@streams = {}
|
|
16
|
+
@syntheses = []
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def add_stream(stream_type:, content:, weight: DEFAULT_WEIGHT, confidence: DEFAULT_WEIGHT, **)
|
|
20
|
+
return { success: false, error: :invalid_stream_type, valid_types: STREAM_TYPES } unless STREAM_TYPES.include?(stream_type)
|
|
21
|
+
|
|
22
|
+
stream = SynthesisStream.new(
|
|
23
|
+
stream_type: stream_type,
|
|
24
|
+
content: content,
|
|
25
|
+
weight: weight,
|
|
26
|
+
confidence: confidence
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
@streams[stream.id] = stream
|
|
30
|
+
prune_streams! if @streams.size > MAX_STREAMS
|
|
31
|
+
|
|
32
|
+
Legion::Logging.debug "[cognitive_synthesis] stream added id=#{stream.id[0..7]} " \
|
|
33
|
+
"type=#{stream_type} weight=#{weight.round(2)}"
|
|
34
|
+
|
|
35
|
+
{ success: true, stream_id: stream.id, stream_type: stream_type }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def remove_stream(stream_id:, **)
|
|
39
|
+
removed = @streams.delete(stream_id)
|
|
40
|
+
if removed
|
|
41
|
+
Legion::Logging.debug "[cognitive_synthesis] stream removed id=#{stream_id[0..7]}"
|
|
42
|
+
{ success: true, stream_id: stream_id }
|
|
43
|
+
else
|
|
44
|
+
{ success: false, error: :not_found }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def synthesize!(**)
|
|
49
|
+
active = @streams.values.reject(&:stale?)
|
|
50
|
+
|
|
51
|
+
if active.size < MIN_STREAMS_FOR_SYNTHESIS
|
|
52
|
+
Legion::Logging.debug "[cognitive_synthesis] synthesize! skipped: only #{active.size} active streams"
|
|
53
|
+
return { success: false, error: :insufficient_streams, active_count: active.size, required: MIN_STREAMS_FOR_SYNTHESIS }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
coherence = compute_coherence(active)
|
|
57
|
+
novelty = compute_novelty(active)
|
|
58
|
+
confidence = compute_weighted_confidence(active)
|
|
59
|
+
content = merge_content(active)
|
|
60
|
+
|
|
61
|
+
synthesis = Synthesis.new(
|
|
62
|
+
streams: active.map(&:id),
|
|
63
|
+
coherence: coherence,
|
|
64
|
+
novelty: novelty,
|
|
65
|
+
confidence: confidence,
|
|
66
|
+
content: content
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@syntheses << synthesis
|
|
70
|
+
@syntheses.shift while @syntheses.size > MAX_SYNTHESES
|
|
71
|
+
|
|
72
|
+
Legion::Logging.info "[cognitive_synthesis] synthesis id=#{synthesis.id[0..7]} " \
|
|
73
|
+
"coherence=#{coherence.round(2)} novelty=#{novelty.round(2)} " \
|
|
74
|
+
"streams=#{active.size} label=#{synthesis.coherence_label}"
|
|
75
|
+
|
|
76
|
+
{ success: true, synthesis: synthesis.to_h }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def decay_all!(**)
|
|
80
|
+
before = @streams.size
|
|
81
|
+
@streams.each_value(&:decay_freshness!)
|
|
82
|
+
@streams.reject! { |_, s| s.stale? }
|
|
83
|
+
removed = before - @streams.size
|
|
84
|
+
|
|
85
|
+
Legion::Logging.debug "[cognitive_synthesis] decay_all! removed=#{removed} remaining=#{@streams.size}"
|
|
86
|
+
{ success: true, streams_removed: removed, streams_remaining: @streams.size }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def stream_conflict?(stream_id_a:, stream_id_b:, **)
|
|
90
|
+
a = @streams[stream_id_a]
|
|
91
|
+
b = @streams[stream_id_b]
|
|
92
|
+
|
|
93
|
+
return { success: false, error: :stream_not_found } unless a && b
|
|
94
|
+
|
|
95
|
+
weight_opposition = opposing_weights?(a, b)
|
|
96
|
+
content_conflict = conflicting_content?(a, b)
|
|
97
|
+
conflict = weight_opposition || content_conflict
|
|
98
|
+
|
|
99
|
+
Legion::Logging.debug "[cognitive_synthesis] conflict check #{stream_id_a[0..7]}<>#{stream_id_b[0..7]} " \
|
|
100
|
+
"result=#{conflict}"
|
|
101
|
+
|
|
102
|
+
{
|
|
103
|
+
success: true,
|
|
104
|
+
conflict: conflict,
|
|
105
|
+
weight_opposition: weight_opposition,
|
|
106
|
+
content_conflict: content_conflict
|
|
107
|
+
}
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def dominant_stream(**)
|
|
111
|
+
return { success: false, error: :no_streams } if @streams.empty?
|
|
112
|
+
|
|
113
|
+
stream = @streams.values.max_by(&:effective_weight)
|
|
114
|
+
Legion::Logging.debug "[cognitive_synthesis] dominant stream id=#{stream.id[0..7]} " \
|
|
115
|
+
"effective_weight=#{stream.effective_weight.round(4)}"
|
|
116
|
+
{ success: true, stream: stream.to_h }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def synthesis_history(limit: 10, **)
|
|
120
|
+
recent = @syntheses.last(limit)
|
|
121
|
+
{ success: true, syntheses: recent.map(&:to_h), count: recent.size }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def average_coherence(window: 10, **)
|
|
125
|
+
recent = @syntheses.last(window)
|
|
126
|
+
return { success: true, average_coherence: 0.0, sample_size: 0 } if recent.empty?
|
|
127
|
+
|
|
128
|
+
avg = recent.sum(&:coherence).round(10) / recent.size
|
|
129
|
+
{ success: true, average_coherence: avg.round(10), sample_size: recent.size }
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def to_h
|
|
133
|
+
{
|
|
134
|
+
stream_count: @streams.size,
|
|
135
|
+
synthesis_count: @syntheses.size,
|
|
136
|
+
active_streams: @streams.values.reject(&:stale?).size,
|
|
137
|
+
stale_streams: @streams.values.count(&:stale?),
|
|
138
|
+
average_coherence: @syntheses.empty? ? 0.0 : (@syntheses.sum(&:coherence).round(10) / @syntheses.size).round(6)
|
|
139
|
+
}
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
private
|
|
143
|
+
|
|
144
|
+
def prune_streams!
|
|
145
|
+
overflow = @streams.size - MAX_STREAMS
|
|
146
|
+
return if overflow <= 0
|
|
147
|
+
|
|
148
|
+
ids_to_prune = @streams.min_by(overflow) { |_, s| s.effective_weight }.map(&:first)
|
|
149
|
+
ids_to_prune.each { |id| @streams.delete(id) }
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def compute_coherence(active)
|
|
153
|
+
return 1.0 if active.size == 1
|
|
154
|
+
|
|
155
|
+
weights = active.map(&:effective_weight)
|
|
156
|
+
mean = weights.sum.round(10) / weights.size
|
|
157
|
+
variance = weights.sum { |w| ((w - mean)**2).round(10) }.round(10) / weights.size
|
|
158
|
+
std_dev = Math.sqrt(variance)
|
|
159
|
+
|
|
160
|
+
(1.0 - [std_dev, 1.0].min).round(10)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def compute_novelty(active)
|
|
164
|
+
return 1.0 if @syntheses.empty?
|
|
165
|
+
|
|
166
|
+
last_syn = @syntheses.last
|
|
167
|
+
last_ids = Set.new(last_syn.streams)
|
|
168
|
+
current_ids = Set.new(active.map(&:id))
|
|
169
|
+
|
|
170
|
+
overlap = (last_ids & current_ids).size.to_f
|
|
171
|
+
union = (last_ids | current_ids).size.to_f
|
|
172
|
+
|
|
173
|
+
return 1.0 if union.zero?
|
|
174
|
+
|
|
175
|
+
jaccard_similarity = overlap / union
|
|
176
|
+
(1.0 - jaccard_similarity).round(10)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def compute_weighted_confidence(active)
|
|
180
|
+
total_weight = active.sum(&:effective_weight).round(10)
|
|
181
|
+
return 0.0 if total_weight.zero?
|
|
182
|
+
|
|
183
|
+
weighted_sum = active.sum { |s| (s.confidence * s.effective_weight).round(10) }.round(10)
|
|
184
|
+
(weighted_sum / total_weight).round(10)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def merge_content(active)
|
|
188
|
+
dominant = active.max_by(&:effective_weight)
|
|
189
|
+
{
|
|
190
|
+
dominant_type: dominant.stream_type,
|
|
191
|
+
dominant_weight: dominant.effective_weight.round(6),
|
|
192
|
+
stream_types: active.map(&:stream_type).uniq,
|
|
193
|
+
stream_count: active.size,
|
|
194
|
+
payload_snapshot: dominant.content
|
|
195
|
+
}
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def opposing_weights?(str_a, str_b)
|
|
199
|
+
(str_a.weight - str_b.weight).abs > 0.5
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def conflicting_content?(str_a, str_b)
|
|
203
|
+
keys_a = str_a.content.is_a?(Hash) ? str_a.content.keys : []
|
|
204
|
+
keys_b = str_b.content.is_a?(Hash) ? str_b.content.keys : []
|
|
205
|
+
(keys_a & keys_b).any? { |k| str_a.content[k] != str_b.content[k] }
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Integration
|
|
9
|
+
module Synthesis
|
|
10
|
+
module Helpers
|
|
11
|
+
class SynthesisStream
|
|
12
|
+
include Constants
|
|
13
|
+
|
|
14
|
+
attr_reader :id, :stream_type, :content, :weight, :confidence, :freshness, :created_at
|
|
15
|
+
|
|
16
|
+
def initialize(stream_type:, content:, weight: DEFAULT_WEIGHT, confidence: DEFAULT_WEIGHT)
|
|
17
|
+
@id = SecureRandom.uuid
|
|
18
|
+
@stream_type = stream_type
|
|
19
|
+
@content = content
|
|
20
|
+
@weight = weight.clamp(0.0, 1.0)
|
|
21
|
+
@confidence = confidence.clamp(0.0, 1.0)
|
|
22
|
+
@freshness = 1.0
|
|
23
|
+
@created_at = Time.now.utc
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def decay_freshness!
|
|
27
|
+
@freshness = (@freshness - FRESHNESS_DECAY).clamp(0.0, 1.0)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def stale?
|
|
31
|
+
@freshness < 0.1
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def effective_weight
|
|
35
|
+
(@weight * @freshness * @confidence).round(10)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def coherence_label
|
|
39
|
+
COHERENCE_LABELS.find { |range, _| range.cover?(@weight) }&.last || :chaotic
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def confidence_label
|
|
43
|
+
CONFIDENCE_LABELS.find { |range, _| range.cover?(@confidence) }&.last || :guessing
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def to_h
|
|
47
|
+
{
|
|
48
|
+
id: @id,
|
|
49
|
+
stream_type: @stream_type,
|
|
50
|
+
content: @content,
|
|
51
|
+
weight: @weight,
|
|
52
|
+
confidence: @confidence,
|
|
53
|
+
freshness: @freshness,
|
|
54
|
+
effective_weight: effective_weight,
|
|
55
|
+
stale: stale?,
|
|
56
|
+
coherence_label: coherence_label,
|
|
57
|
+
confidence_label: confidence_label,
|
|
58
|
+
created_at: @created_at
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Synthesis
|
|
8
|
+
module Runners
|
|
9
|
+
module CognitiveSynthesis
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
12
|
+
|
|
13
|
+
def add_stream(stream_type:, content:, weight: Helpers::Constants::DEFAULT_WEIGHT,
|
|
14
|
+
confidence: Helpers::Constants::DEFAULT_WEIGHT, engine: nil, **)
|
|
15
|
+
target = engine || synthesis_engine
|
|
16
|
+
result = target.add_stream(stream_type: stream_type, content: content,
|
|
17
|
+
weight: weight, confidence: confidence)
|
|
18
|
+
Legion::Logging.debug "[cognitive_synthesis] runner add_stream type=#{stream_type}"
|
|
19
|
+
result
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def remove_stream(stream_id:, engine: nil, **)
|
|
23
|
+
target = engine || synthesis_engine
|
|
24
|
+
Legion::Logging.debug "[cognitive_synthesis] runner remove_stream id=#{stream_id[0..7]}"
|
|
25
|
+
target.remove_stream(stream_id: stream_id)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def synthesize(engine: nil, **)
|
|
29
|
+
target = engine || synthesis_engine
|
|
30
|
+
Legion::Logging.debug '[cognitive_synthesis] runner synthesize'
|
|
31
|
+
target.synthesize!
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def decay_streams(engine: nil, **)
|
|
35
|
+
target = engine || synthesis_engine
|
|
36
|
+
Legion::Logging.debug '[cognitive_synthesis] runner decay_streams'
|
|
37
|
+
target.decay_all!
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def check_conflict(stream_id_a:, stream_id_b:, engine: nil, **)
|
|
41
|
+
target = engine || synthesis_engine
|
|
42
|
+
Legion::Logging.debug "[cognitive_synthesis] runner check_conflict #{stream_id_a[0..7]}<>#{stream_id_b[0..7]}"
|
|
43
|
+
target.stream_conflict?(stream_id_a: stream_id_a, stream_id_b: stream_id_b)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def dominant_stream(engine: nil, **)
|
|
47
|
+
target = engine || synthesis_engine
|
|
48
|
+
Legion::Logging.debug '[cognitive_synthesis] runner dominant_stream'
|
|
49
|
+
target.dominant_stream
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def synthesis_history(limit: 10, engine: nil, **)
|
|
53
|
+
target = engine || synthesis_engine
|
|
54
|
+
Legion::Logging.debug "[cognitive_synthesis] runner synthesis_history limit=#{limit}"
|
|
55
|
+
target.synthesis_history(limit: limit)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def average_coherence(window: 10, engine: nil, **)
|
|
59
|
+
target = engine || synthesis_engine
|
|
60
|
+
Legion::Logging.debug "[cognitive_synthesis] runner average_coherence window=#{window}"
|
|
61
|
+
target.average_coherence(window: window)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def status(engine: nil, **)
|
|
65
|
+
target = engine || synthesis_engine
|
|
66
|
+
stats = target.to_h
|
|
67
|
+
Legion::Logging.debug "[cognitive_synthesis] runner status streams=#{stats[:stream_count]}"
|
|
68
|
+
{ success: true }.merge(stats)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def synthesis_engine
|
|
74
|
+
@synthesis_engine ||= Helpers::SynthesisEngine.new
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/integration/synthesis/version'
|
|
4
|
+
require 'legion/extensions/agentic/integration/synthesis/helpers/constants'
|
|
5
|
+
require 'legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream'
|
|
6
|
+
require 'legion/extensions/agentic/integration/synthesis/helpers/synthesis'
|
|
7
|
+
require 'legion/extensions/agentic/integration/synthesis/helpers/synthesis_engine'
|
|
8
|
+
require 'legion/extensions/agentic/integration/synthesis/runners/cognitive_synthesis'
|
|
9
|
+
require 'legion/extensions/agentic/integration/synthesis/client'
|
|
10
|
+
|
|
11
|
+
module Legion
|
|
12
|
+
module Extensions
|
|
13
|
+
module Agentic
|
|
14
|
+
module Integration
|
|
15
|
+
module Synthesis
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Tapestry
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
THREAD_TYPES = %i[experience belief memory emotion narrative].freeze
|
|
11
|
+
|
|
12
|
+
WEAVE_PATTERNS = %i[plain twill satin brocade].freeze
|
|
13
|
+
|
|
14
|
+
MAX_THREADS = 500
|
|
15
|
+
MAX_TAPESTRIES = 50
|
|
16
|
+
TENSION_RATE = 0.05
|
|
17
|
+
FRAY_RATE = 0.03
|
|
18
|
+
|
|
19
|
+
INTEGRITY_LABELS = [
|
|
20
|
+
[(0.9..), :masterwork],
|
|
21
|
+
[(0.7...0.9), :sturdy],
|
|
22
|
+
[(0.5...0.7), :woven],
|
|
23
|
+
[(0.3...0.5), :fraying],
|
|
24
|
+
[(0.1...0.3), :tattered],
|
|
25
|
+
[(..0.1), :rags]
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
COMPLEXITY_LABELS = [
|
|
29
|
+
[(0.85..), :baroque],
|
|
30
|
+
[(0.65...0.85), :elaborate],
|
|
31
|
+
[(0.45...0.65), :patterned],
|
|
32
|
+
[(0.25...0.45), :plain_woven],
|
|
33
|
+
[(..0.25), :simple]
|
|
34
|
+
].freeze
|
|
35
|
+
|
|
36
|
+
def self.label_for(table, value)
|
|
37
|
+
table.each { |range, label| return label if range.cover?(value) }
|
|
38
|
+
table.last.last
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Tapestry
|
|
8
|
+
module Helpers
|
|
9
|
+
class LoomEngine
|
|
10
|
+
def initialize
|
|
11
|
+
@threads = {}
|
|
12
|
+
@tapestries = {}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def spin_thread(thread_type:, domain:, content:,
|
|
16
|
+
strength: nil, color: nil)
|
|
17
|
+
raise ArgumentError, 'thread limit reached' if @threads.size >= Constants::MAX_THREADS
|
|
18
|
+
|
|
19
|
+
t = Helpers::Thread.new(
|
|
20
|
+
thread_type: thread_type,
|
|
21
|
+
domain: domain,
|
|
22
|
+
content: content,
|
|
23
|
+
strength: strength,
|
|
24
|
+
color: color
|
|
25
|
+
)
|
|
26
|
+
@threads[t.id] = t
|
|
27
|
+
t
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def create_tapestry(name:, pattern:, capacity: 50)
|
|
31
|
+
raise ArgumentError, 'tapestry limit reached' if @tapestries.size >= Constants::MAX_TAPESTRIES
|
|
32
|
+
|
|
33
|
+
tap = Tapestry.new(name: name, pattern: pattern, capacity: capacity)
|
|
34
|
+
@tapestries[tap.id] = tap
|
|
35
|
+
tap
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def weave(thread_id:, tapestry_id:)
|
|
39
|
+
thread = fetch_thread(thread_id)
|
|
40
|
+
tapestry = fetch_tapestry(tapestry_id)
|
|
41
|
+
|
|
42
|
+
raise ArgumentError, 'thread already woven' if thread.woven?
|
|
43
|
+
raise ArgumentError, 'tapestry is full' if tapestry.full?
|
|
44
|
+
|
|
45
|
+
tapestry.weave_thread(thread_id)
|
|
46
|
+
thread.woven_into!(tapestry_id)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def unravel(thread_id:, tapestry_id:)
|
|
50
|
+
thread = fetch_thread(thread_id)
|
|
51
|
+
tapestry = fetch_tapestry(tapestry_id)
|
|
52
|
+
|
|
53
|
+
tapestry.unravel_thread(thread_id)
|
|
54
|
+
thread.unwoven!
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def fray_all!(rate: Constants::FRAY_RATE)
|
|
58
|
+
@threads.each_value { |t| t.fray!(rate: rate) }
|
|
59
|
+
snapped = @threads.count { |_, t| t.snap? }
|
|
60
|
+
{ total: @threads.size, snapped: snapped }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def most_complete(limit: 5)
|
|
64
|
+
@tapestries.values.sort_by { |tap| -tap.completeness }.first(limit)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def most_coherent(limit: 5)
|
|
68
|
+
threads_arr = @threads.values
|
|
69
|
+
@tapestries.values
|
|
70
|
+
.sort_by { |tap| -tap.coherence_score(threads_arr) }
|
|
71
|
+
.first(limit)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def thread_inventory
|
|
75
|
+
counts = Constants::THREAD_TYPES.to_h { |type| [type, 0] }
|
|
76
|
+
@threads.each_value { |t| counts[t.thread_type] += 1 }
|
|
77
|
+
counts
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def tapestry_report
|
|
81
|
+
threads_arr = @threads.values
|
|
82
|
+
{
|
|
83
|
+
total_threads: @threads.size,
|
|
84
|
+
total_tapestries: @tapestries.size,
|
|
85
|
+
loose_count: loose_threads.size,
|
|
86
|
+
by_type: thread_inventory,
|
|
87
|
+
fraying_count: @tapestries.count { |_, tap| tap.fraying?(threads_arr) },
|
|
88
|
+
avg_completeness: avg_completeness
|
|
89
|
+
}
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def all_threads
|
|
93
|
+
@threads.values
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def all_tapestries
|
|
97
|
+
@tapestries.values
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def loose_threads
|
|
101
|
+
@threads.values.select(&:loose?)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
private
|
|
105
|
+
|
|
106
|
+
def fetch_thread(id)
|
|
107
|
+
@threads.fetch(id) { raise ArgumentError, "thread not found: #{id}" }
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def fetch_tapestry(id)
|
|
111
|
+
@tapestries.fetch(id) { raise ArgumentError, "tapestry not found: #{id}" }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def avg_completeness
|
|
115
|
+
return 0.0 if @tapestries.empty?
|
|
116
|
+
|
|
117
|
+
(@tapestries.values.sum(&:completeness) / @tapestries.size).round(10)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|