lex-metacognition 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c984662679c22c1a58fd67caafc9005a36a795351e0a211a9dbe53289cb353b1
4
+ data.tar.gz: 98904ccd15eaa3dbfe7f0749c01b69e3478f679a681555d7547f0aa1ae6a51a3
5
+ SHA512:
6
+ metadata.gz: 311b72e0870ff6435ef2e2c01b00d83b9b939b5a73f351553fcaabb443bc9aa7b59497e51e8576438552e4438e4611074c5a1f38340537d3af038576a8f15127
7
+ data.tar.gz: 00dfc990066f0a0a3c808369933e6baebd0f623b87b78e6887987ff4d6b84d9ec95c6ac6860cf4e0f51a1f8988f155127024d4f366467b0abac9f2c32271a9e6
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development, :test do
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rubocop', '~> 1.21'
11
+ gem 'rubocop-rspec', require: false
12
+ gem 'simplecov', require: false
13
+ end
14
+
15
+ gem 'legion-gaia', path: '../../legion-gaia'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LegionIO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # lex-metacognition
2
+
3
+ Second-order self-model assembly for LegionIO agents. Part of the LegionIO cognitive architecture extension ecosystem (LEX).
4
+
5
+ ## What It Does
6
+
7
+ `lex-metacognition` enables an agent to build an explicit model of its own architecture, capabilities, and current cognitive state. Unlike performance monitoring, metacognition assembles a structured self-representation from live runtime introspection — the agent knowing what it is, what it can do, and what it is doing right now. Maintains a rolling snapshot history for health trending and architecture change detection.
8
+
9
+ Key capabilities:
10
+
11
+ - **Runtime introspection**: discovers loaded extensions, maps capabilities, captures tick state
12
+ - **Capability map**: groups 200+ known extensions into 8 categories (perception, cognition, memory, etc.)
13
+ - **Health trending**: cognitive health score over rolling snapshot history
14
+ - **Architecture change detection**: tracks when extensions are loaded or unloaded
15
+ - **Natural language self-description**: generates prose narrative from the self-model
16
+
17
+ ## Installation
18
+
19
+ Add to your Gemfile:
20
+
21
+ ```ruby
22
+ gem 'lex-metacognition'
23
+ ```
24
+
25
+ Or install directly:
26
+
27
+ ```
28
+ gem install lex-metacognition
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```ruby
34
+ require 'legion/extensions/metacognition'
35
+
36
+ client = Legion::Extensions::Metacognition::Client.new
37
+
38
+ # Build and cache a self-model
39
+ model = client.introspect(tick_results: tick_output)
40
+ # => { loaded_extensions: [...], capability_map: { cognition: [...], ... },
41
+ # cognitive_health: 0.92, tick_mode: :full_active }
42
+
43
+ # Natural language self-description
44
+ narrative = client.self_narrative(tick_results: tick_output)
45
+ puts narrative[:prose]
46
+ # => "I am a brain_modeled cognitive_agent built on LegionIO with 24 extension slots.
47
+ # 18 of 24 extensions are active. Operating in full_active mode.
48
+ # Running 12 phases per tick. Cognitive health: excellent (92%)."
49
+
50
+ # Explain a specific subsystem
51
+ info = client.explain_subsystem(subsystem: :memory)
52
+
53
+ # Architecture summary
54
+ client.architecture_overview
55
+
56
+ # Health trend over time
57
+ trend = client.health_trend(limit: 20)
58
+
59
+ # Detect when extensions changed
60
+ client.architecture_changes
61
+ ```
62
+
63
+ ## Runner Methods
64
+
65
+ | Method | Description |
66
+ |---|---|
67
+ | `introspect` | Build and cache a self-model snapshot |
68
+ | `self_narrative` | Build model and generate prose narrative |
69
+ | `explain_subsystem` | Description and current state of a specific subsystem |
70
+ | `architecture_overview` | Capability map with extension counts per category |
71
+ | `health_trend` | Cognitive health scores over last N snapshots |
72
+ | `architecture_changes` | Snapshots where extension set changed |
73
+ | `metacognition_stats` | Snapshot count, latest health, stale flag |
74
+
75
+ ## Development
76
+
77
+ ```bash
78
+ bundle install
79
+ bundle exec rspec
80
+ bundle exec rubocop
81
+ ```
82
+
83
+ ## License
84
+
85
+ MIT
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/metacognition/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-metacognition'
7
+ spec.version = Legion::Extensions::Metacognition::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX Metacognition'
12
+ spec.description = 'Second-order self-model assembly for brain-modeled agentic AI'
13
+ spec.homepage = 'https://github.com/LegionIO/lex-metacognition'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-metacognition'
19
+ spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-metacognition'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-metacognition'
21
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-metacognition/issues'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ Dir.glob('{lib,spec}/**/*') + %w[lex-metacognition.gemspec Gemfile LICENSE README.md]
26
+ end
27
+ spec.require_paths = ['lib']
28
+ spec.add_development_dependency 'legion-gaia'
29
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/metacognition/helpers/constants'
4
+ require 'legion/extensions/metacognition/helpers/self_model'
5
+ require 'legion/extensions/metacognition/helpers/snapshot_store'
6
+ require 'legion/extensions/metacognition/helpers/narrator_bridge'
7
+ require 'legion/extensions/metacognition/runners/metacognition'
8
+
9
+ module Legion
10
+ module Extensions
11
+ module Metacognition
12
+ class Client
13
+ include Runners::Metacognition
14
+
15
+ attr_reader :snapshot_store
16
+
17
+ def initialize(snapshot_store: nil, **)
18
+ @snapshot_store = snapshot_store || Helpers::SnapshotStore.new
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,373 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Metacognition
6
+ module Helpers
7
+ module Constants
8
+ # Maximum cached self-model snapshots
9
+ MAX_SNAPSHOTS = 50
10
+
11
+ # How long a self-model snapshot is considered fresh (seconds)
12
+ SNAPSHOT_TTL = 30
13
+
14
+ # Subsystems the self-model introspects
15
+ SUBSYSTEMS = %i[
16
+ tick cortex memory emotion prediction identity
17
+ curiosity attention reflection volition language
18
+ trust consent coldstart mesh dream
19
+ narrator metacognition homeostasis empathy
20
+ imagination mood salience habit temporal
21
+ fatigue personality flow reward
22
+ conscience resilience social creativity
23
+ theory_of_mind planning inhibition schema
24
+ working_memory motivation agency surprise
25
+ priming dissonance gestalt bias
26
+ arousal context anchoring
27
+ narrative_self cognitive_load
28
+ learning_rate emotional_regulation
29
+ mentalizing prospection
30
+ interoception mirror joint_attention
31
+ semantic_memory default_mode_network
32
+ predictive_coding attention_schema
33
+ global_workspace hebbian_assembly
34
+ cognitive_map error_monitoring
35
+ neuromodulation feature_binding
36
+ executive_function neural_oscillation
37
+ source_monitoring somatic_marker
38
+ affordance episodic_buffer
39
+ cognitive_flexibility embodied_simulation
40
+ predictive_processing belief_revision
41
+ mental_time_travel cognitive_control
42
+ perceptual_inference inner_speech
43
+ self_model cognitive_rhythm
44
+ cognitive_empathy attention_regulation
45
+ intuition free_energy
46
+ counterfactual moral_reasoning
47
+ analogical_reasoning causal_reasoning
48
+ cognitive_reserve appraisal
49
+ cognitive_coherence conceptual_blending
50
+ dual_process abductive_reasoning
51
+ social_learning conceptual_metaphor
52
+ procedural_learning signal_detection
53
+ bayesian_belief cognitive_scaffolding
54
+ enactive_cognition distributed_cognition
55
+ cognitive_entrainment narrative_reasoning
56
+ causal_attribution cognitive_apprenticeship
57
+ pragmatic_inference
58
+ cognitive_momentum relevance_theory
59
+ situation_model cognitive_disengagement
60
+ epistemic_vigilance frame_semantics
61
+ expectation_violation
62
+ argument_mapping mental_simulation
63
+ cognitive_grammar cognitive_architecture
64
+ cognitive_fatigue_model uncertainty_tolerance
65
+ preference_learning
66
+ temporal_discounting cognitive_immunology
67
+ phenomenal_binding meta_learning
68
+ cognitive_homeostasis attentional_blink
69
+ cognitive_contagion prospective_memory
70
+ cognitive_dissonance_resolution attention_economy
71
+ cognitive_load_balancing semantic_satiation
72
+ cognitive_debt reality_testing cognitive_friction
73
+ epistemic_curiosity cognitive_boundary decision_fatigue
74
+ cognitive_resonance latent_inhibition cognitive_surplus
75
+ transfer_learning cognitive_compression cognitive_plasticity
76
+ anosognosia confabulation cognitive_tempo
77
+ hypothesis_testing cognitive_inertia sensory_gating
78
+ cognitive_synthesis metacognitive_monitoring
79
+ cognitive_defusion cognitive_reappraisal
80
+ semantic_priming cognitive_integration
81
+ cognitive_flexibility_training perspective_shifting
82
+ cognitive_offloading cognitive_chunking
83
+ attention_switching cognitive_dwell
84
+ goal_management cognitive_debugging
85
+ attention_spotlight cognitive_immune_response
86
+ narrative_identity cognitive_triage
87
+ cognitive_horizon cognitive_autopilot self_talk
88
+ cognitive_weathering cognitive_fingerprint cognitive_echo
89
+ cognitive_mirror cognitive_blindspot cognitive_gravity
90
+ cognitive_immune_memory cognitive_narrative_arc subliminal
91
+ cognitive_palimpsest cognitive_chrysalis qualia
92
+ cognitive_liminal cognitive_synesthesia cognitive_nostalgia
93
+ cognitive_zeitgeist cognitive_archaeology cognitive_aurora
94
+ cognitive_genesis cognitive_tessellation cognitive_fermentation
95
+ cognitive_metabolism cognitive_phantom cognitive_tectonics
96
+ cognitive_lucidity cognitive_paleontology cognitive_mycelium
97
+ cognitive_symbiosis cognitive_hologram cognitive_tide
98
+ cognitive_origami cognitive_alchemy cognitive_constellation
99
+ cognitive_pendulum cognitive_erosion cognitive_prism
100
+ cognitive_cocoon cognitive_compass cognitive_mosaic
101
+ cognitive_whirlpool cognitive_greenhouse cognitive_fossil_fuel
102
+ cognitive_lens cognitive_echo_chamber cognitive_labyrinth
103
+ cognitive_kaleidoscope cognitive_quicksand cognitive_volcano
104
+ cognitive_tapestry cognitive_lighthouse cognitive_avalanche
105
+ cognitive_hourglass cognitive_magnet cognitive_weather
106
+ cognitive_furnace cognitive_anchor cognitive_garden
107
+ codegen exec mind_growth
108
+ ].freeze
109
+
110
+ # Capability categories for self-description
111
+ CAPABILITY_CATEGORIES = %i[
112
+ perception cognition memory motivation safety
113
+ communication introspection coordination
114
+ ].freeze
115
+
116
+ # Maps extensions to capability categories
117
+ EXTENSION_CAPABILITIES = {
118
+ Tick: :cognition,
119
+ Cortex: :cognition,
120
+ Memory: :memory,
121
+ Emotion: :perception,
122
+ Prediction: :cognition,
123
+ Identity: :safety,
124
+ Curiosity: :motivation,
125
+ Attention: :perception,
126
+ Reflection: :introspection,
127
+ Volition: :motivation,
128
+ Language: :introspection,
129
+ Trust: :safety,
130
+ Consent: :safety,
131
+ Codegen: :coordination,
132
+ Coldstart: :cognition,
133
+ Mesh: :communication,
134
+ Dream: :cognition,
135
+ Narrator: :introspection,
136
+ Metacognition: :introspection,
137
+ Conflict: :safety,
138
+ Governance: :safety,
139
+ Extinction: :safety,
140
+ Privatecore: :safety,
141
+ Swarm: :coordination,
142
+ SwarmGithub: :coordination,
143
+ Homeostasis: :cognition,
144
+ Empathy: :communication,
145
+ Imagination: :cognition,
146
+ Mood: :perception,
147
+ Salience: :perception,
148
+ Habit: :cognition,
149
+ Temporal: :perception,
150
+ Fatigue: :cognition,
151
+ Personality: :introspection,
152
+ Flow: :cognition,
153
+ Reward: :motivation,
154
+ Conscience: :safety,
155
+ Resilience: :cognition,
156
+ Social: :communication,
157
+ Creativity: :cognition,
158
+ TheoryOfMind: :communication,
159
+ Planning: :cognition,
160
+ Inhibition: :safety,
161
+ Schema: :cognition,
162
+ WorkingMemory: :memory,
163
+ Motivation: :motivation,
164
+ Agency: :motivation,
165
+ Surprise: :perception,
166
+ Priming: :cognition,
167
+ Dissonance: :cognition,
168
+ Gestalt: :perception,
169
+ Bias: :introspection,
170
+ Arousal: :cognition,
171
+ Context: :cognition,
172
+ Anchoring: :cognition,
173
+ NarrativeSelf: :introspection,
174
+ CognitiveLoad: :cognition,
175
+ LearningRate: :cognition,
176
+ EmotionalRegulation: :introspection,
177
+ Mentalizing: :communication,
178
+ MindGrowth: :introspection,
179
+ Prospection: :cognition,
180
+ Interoception: :perception,
181
+ Mirror: :communication,
182
+ JointAttention: :communication,
183
+ SemanticMemory: :memory,
184
+ DefaultModeNetwork: :cognition,
185
+ PredictiveCoding: :cognition,
186
+ AttentionSchema: :introspection,
187
+ GlobalWorkspace: :cognition,
188
+ HebbianAssembly: :cognition,
189
+ CognitiveMap: :cognition,
190
+ ErrorMonitoring: :safety,
191
+ Neuromodulation: :cognition,
192
+ FeatureBinding: :perception,
193
+ ExecutiveFunction: :cognition,
194
+ NeuralOscillation: :cognition,
195
+ SourceMonitoring: :introspection,
196
+ SomaticMarker: :perception,
197
+ Affordance: :perception,
198
+ EpisodicBuffer: :memory,
199
+ Exec: :coordination,
200
+ CognitiveFlexibility: :cognition,
201
+ EmbodiedSimulation: :cognition,
202
+ PredictiveProcessing: :cognition,
203
+ BeliefRevision: :cognition,
204
+ MentalTimeTravel: :cognition,
205
+ CognitiveControl: :cognition,
206
+ PerceptualInference: :perception,
207
+ InnerSpeech: :introspection,
208
+ SelfModel: :introspection,
209
+ CognitiveRhythm: :cognition,
210
+ CognitiveEmpathy: :communication,
211
+ AttentionRegulation: :perception,
212
+ Intuition: :cognition,
213
+ FreeEnergy: :cognition,
214
+ Counterfactual: :cognition,
215
+ MoralReasoning: :safety,
216
+ AnalogicalReasoning: :cognition,
217
+ CausalReasoning: :cognition,
218
+ CognitiveReserve: :cognition,
219
+ Appraisal: :cognition,
220
+ CognitiveCoherence: :cognition,
221
+ ConceptualBlending: :cognition,
222
+ DualProcess: :cognition,
223
+ AbductiveReasoning: :cognition,
224
+ SocialLearning: :communication,
225
+ ConceptualMetaphor: :cognition,
226
+ ProceduralLearning: :cognition,
227
+ SignalDetection: :perception,
228
+ BayesianBelief: :cognition,
229
+ CognitiveScaffolding: :cognition,
230
+ EnactiveCognition: :cognition,
231
+ DistributedCognition: :coordination,
232
+ CognitiveEntrainment: :coordination,
233
+ NarrativeReasoning: :cognition,
234
+ CausalAttribution: :cognition,
235
+ CognitiveApprenticeship: :cognition,
236
+ PragmaticInference: :communication,
237
+ CognitiveMomentum: :cognition,
238
+ RelevanceTheory: :cognition,
239
+ SituationModel: :cognition,
240
+ CognitiveDisengagement: :cognition,
241
+ EpistemicVigilance: :safety,
242
+ FrameSemantics: :cognition,
243
+ ExpectationViolation: :perception,
244
+ ArgumentMapping: :cognition,
245
+ MentalSimulation: :cognition,
246
+ CognitiveGrammar: :cognition,
247
+ CognitiveArchitecture: :introspection,
248
+ CognitiveFatigueModel: :cognition,
249
+ UncertaintyTolerance: :cognition,
250
+ PreferenceLearning: :cognition,
251
+ TemporalDiscounting: :cognition,
252
+ CognitiveImmunology: :safety,
253
+ PhenomenalBinding: :perception,
254
+ MetaLearning: :cognition,
255
+ CognitiveHomeostasis: :cognition,
256
+ AttentionalBlink: :perception,
257
+ CognitiveContagion: :communication,
258
+ ProspectiveMemory: :memory,
259
+ CognitiveDissonanceResolution: :cognition,
260
+ AttentionEconomy: :cognition,
261
+ CognitiveLoadBalancing: :cognition,
262
+ SemanticSatiation: :perception,
263
+ CognitiveDebt: :cognition,
264
+ RealityTesting: :cognition,
265
+ CognitiveFriction: :cognition,
266
+ EpistemicCuriosity: :motivation,
267
+ CognitiveBoundary: :safety,
268
+ DecisionFatigue: :cognition,
269
+ CognitiveResonance: :perception,
270
+ LatentInhibition: :cognition,
271
+ CognitiveSurplus: :cognition,
272
+ TransferLearning: :cognition,
273
+ CognitiveCompression: :memory,
274
+ CognitivePlasticity: :cognition,
275
+ Anosognosia: :safety,
276
+ Confabulation: :safety,
277
+ CognitiveTempo: :cognition,
278
+ HypothesisTesting: :cognition,
279
+ CognitiveInertia: :cognition,
280
+ SensoryGating: :perception,
281
+ CognitiveSynthesis: :cognition,
282
+ MetacognitiveMonitoring: :introspection,
283
+ CognitiveDefusion: :introspection,
284
+ CognitiveReappraisal: :introspection,
285
+ SemanticPriming: :cognition,
286
+ CognitiveIntegration: :cognition,
287
+ CognitiveFlexibilityTraining: :cognition,
288
+ PerspectiveShifting: :communication,
289
+ CognitiveOffloading: :memory,
290
+ CognitiveChunking: :memory,
291
+ AttentionSwitching: :cognition,
292
+ CognitiveDwell: :cognition,
293
+ GoalManagement: :motivation,
294
+ CognitiveDebugging: :introspection,
295
+ AttentionSpotlight: :perception,
296
+ CognitiveImmuneResponse: :safety,
297
+ NarrativeIdentity: :introspection,
298
+ CognitiveTriage: :cognition,
299
+ CognitiveHorizon: :cognition,
300
+ CognitiveAutopilot: :cognition,
301
+ SelfTalk: :introspection,
302
+ CognitiveWeathering: :cognition,
303
+ CognitiveFingerprint: :introspection,
304
+ CognitiveEcho: :cognition,
305
+ CognitiveMirror: :communication,
306
+ CognitiveBlindspot: :introspection,
307
+ CognitiveGravity: :cognition,
308
+ CognitiveImmuneMemory: :safety,
309
+ CognitiveNarrativeArc: :introspection,
310
+ Subliminal: :cognition,
311
+ CognitivePalimpsest: :memory,
312
+ CognitiveChrysalis: :cognition,
313
+ Qualia: :perception,
314
+ CognitiveLiminal: :cognition,
315
+ CognitiveSynesthesia: :perception,
316
+ CognitiveNostalgia: :perception,
317
+ CognitiveZeitgeist: :cognition,
318
+ CognitiveArchaeology: :memory,
319
+ CognitiveAurora: :perception,
320
+ CognitiveGenesis: :cognition,
321
+ CognitiveTessellation: :cognition,
322
+ CognitiveFermentation: :cognition,
323
+ CognitiveMetabolism: :cognition,
324
+ CognitivePhantom: :cognition,
325
+ CognitiveTectonics: :cognition,
326
+ CognitiveLucidity: :perception,
327
+ CognitivePaleontology: :memory,
328
+ CognitiveMycelium: :cognition,
329
+ CognitiveSymbiosis: :cognition,
330
+ CognitiveHologram: :memory,
331
+ CognitiveTide: :cognition,
332
+ CognitiveOrigami: :cognition,
333
+ CognitiveAlchemy: :cognition,
334
+ CognitiveConstellation: :cognition,
335
+ CognitivePendulum: :cognition,
336
+ CognitiveErosion: :cognition,
337
+ CognitivePrism: :perception,
338
+ CognitiveCocoon: :cognition,
339
+ CognitiveCompass: :introspection,
340
+ CognitiveMosaic: :cognition,
341
+ CognitiveWhirlpool: :cognition,
342
+ CognitiveGreenhouse: :cognition,
343
+ CognitiveFossilFuel: :cognition,
344
+ CognitiveLens: :perception,
345
+ CognitiveEchoChamber: :cognition,
346
+ CognitiveLabyrinth: :cognition,
347
+ CognitiveKaleidoscope: :perception,
348
+ CognitiveQuicksand: :cognition,
349
+ CognitiveVolcano: :cognition,
350
+ CognitiveTapestry: :cognition,
351
+ CognitiveLighthouse: :perception,
352
+ CognitiveAvalanche: :cognition,
353
+ CognitiveHourglass: :cognition,
354
+ CognitiveMagnet: :cognition,
355
+ CognitiveWeather: :cognition,
356
+ CognitiveFurnace: :cognition,
357
+ CognitiveAnchor: :cognition,
358
+ CognitiveGarden: :cognition
359
+ }.freeze
360
+
361
+ # Subsystem health labels
362
+ HEALTH_LABELS = {
363
+ (0.8..) => :excellent,
364
+ (0.6...0.8) => :good,
365
+ (0.4...0.6) => :fair,
366
+ (0.2...0.4) => :degraded,
367
+ (..0.2) => :critical
368
+ }.freeze
369
+ end
370
+ end
371
+ end
372
+ end
373
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Metacognition
6
+ module Helpers
7
+ module NarratorBridge
8
+ module_function
9
+
10
+ def narrate_self_model(model)
11
+ parts = []
12
+ parts << narrate_identity(model[:identity])
13
+ parts << narrate_architecture(model[:architecture])
14
+ parts << narrate_cognitive(model[:cognitive])
15
+ parts << narrate_capabilities(model[:capabilities])
16
+ parts.compact.join(' ')
17
+ end
18
+
19
+ def narrate_identity(identity)
20
+ return nil unless identity.is_a?(Hash)
21
+
22
+ "I am a #{identity[:model]} #{identity[:role]} built on #{identity[:framework]} " \
23
+ "with #{identity[:extensions]} extension slots."
24
+ end
25
+
26
+ def narrate_architecture(arch)
27
+ return nil unless arch.is_a?(Hash)
28
+
29
+ loaded = arch[:loaded_count] || 0
30
+ total = arch[:total_extensions] || 0
31
+ unloaded = arch[:unloaded] || []
32
+
33
+ base = "#{loaded} of #{total} extensions are active."
34
+ if unloaded.empty?
35
+ base
36
+ else
37
+ "#{base} Missing: #{unloaded.first(3).join(', ')}#{'...' if unloaded.size > 3}."
38
+ end
39
+ end
40
+
41
+ def narrate_cognitive(cognitive)
42
+ return nil unless cognitive.is_a?(Hash)
43
+ return 'No tick data available.' if cognitive[:status] == :no_tick_data
44
+
45
+ parts = []
46
+ parts << "Operating in #{cognitive[:mode]} mode." if cognitive[:mode] && cognitive[:mode] != :unknown
47
+ parts << "Running #{cognitive[:phases_run]} phases per tick." if cognitive[:phases_run]
48
+
49
+ if cognitive[:health]
50
+ label = SelfModel.health_label(cognitive[:health])
51
+ parts << "Cognitive health: #{label} (#{(cognitive[:health] * 100).round}%)."
52
+ end
53
+
54
+ parts << "Active drives: #{cognitive[:active_drives].join(', ')}." if cognitive[:active_drives]&.any?
55
+
56
+ if cognitive[:attention]
57
+ att = cognitive[:attention]
58
+ parts << "#{att[:spotlight] || 0} signals in spotlight focus." if att[:spotlight]
59
+ end
60
+
61
+ if cognitive[:curiosity]
62
+ cur = cognitive[:curiosity]
63
+ parts << "#{cur[:open_wonders] || 0} open questions." if cur[:open_wonders]
64
+ end
65
+
66
+ parts.join(' ')
67
+ end
68
+
69
+ def narrate_capabilities(capabilities)
70
+ return nil unless capabilities.is_a?(Hash)
71
+
72
+ active_cats = capabilities.select { |_, v| v[:active] }.keys
73
+ return nil if active_cats.empty?
74
+
75
+ "Active capabilities: #{active_cats.join(', ')}."
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end