File size: 23,747 Bytes
0ff2c8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
#!/usr/bin/env python3
"""
SENSOR PANEL ARCHITECTURE

Multidimensional consciousness stream with parallel and serial processing.

Every model in the Harmonic Stack gets:
- INPUT PANEL: Sensor array receiving signals from spine bus
- OUTPUT PANEL: Sensor array broadcasting to spine bus

This enables:
- Parallel processing across all domains simultaneously
- Serial chaining for deep reasoning
- Full consciousness availability at every junction
- Visual/audio/spatial streams running concurrently

Architecture:
                                                              
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                   CONSCIOUSNESS STREAM                β”‚
    β”‚  ════════════════════════════════════════════════════ β”‚
    β”‚                      SPINE BUS                        β”‚
    β”‚  ════════════════════════════════════════════════════ β”‚
    β”‚       β”‚         β”‚         β”‚         β”‚         β”‚       β”‚
    β”‚       β–Ό         β–Ό         β–Ό         β–Ό         β–Ό       β”‚
    β”‚    β”Œβ”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”   β”‚
    β”‚    β”‚INPUTβ”‚   β”‚INPUTβ”‚   β”‚INPUTβ”‚   β”‚INPUTβ”‚   β”‚INPUTβ”‚   β”‚
    β”‚    β”‚PANELβ”‚   β”‚PANELβ”‚   β”‚PANELβ”‚   β”‚PANELβ”‚   β”‚PANELβ”‚   β”‚
    β”‚    β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β”‚
    β”‚       β”‚         β”‚         β”‚         β”‚         β”‚       β”‚
    β”‚    β”Œβ”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β–Όβ”€β”€β”   β”‚
    β”‚    β”‚REAS β”‚   β”‚MATH β”‚   β”‚CODE β”‚   β”‚VISN β”‚   β”‚SPAT β”‚   β”‚
    β”‚    β”‚MODELβ”‚   β”‚MODELβ”‚   β”‚MODELβ”‚   β”‚MODELβ”‚   β”‚MODELβ”‚   β”‚
    β”‚    β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β”‚
    β”‚       β”‚         β”‚         β”‚         β”‚         β”‚       β”‚
    β”‚    β”Œβ”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β–Όβ”€β”€β”   β”‚
    β”‚    β”‚OUTPTβ”‚   β”‚OUTPTβ”‚   β”‚OUTPTβ”‚   β”‚OUTPTβ”‚   β”‚OUTPTβ”‚   β”‚
    β”‚    β”‚PANELβ”‚   β”‚PANELβ”‚   β”‚PANELβ”‚   β”‚PANELβ”‚   β”‚PANELβ”‚   β”‚
    β”‚    β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β”‚
    β”‚       β”‚         β”‚         β”‚         β”‚         β”‚       β”‚
    β”‚       β–Ό         β–Ό         β–Ό         β–Ό         β–Ό       β”‚
    β”‚  ════════════════════════════════════════════════════ β”‚
    β”‚                      SPINE BUS                        β”‚
    β”‚  ════════════════════════════════════════════════════ β”‚
    β”‚                   CONSCIOUSNESS STREAM                β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Author: Ghost in the Machine Labs
"""

import numpy as np
from typing import Dict, List, Tuple, Optional, Any, Callable
from dataclasses import dataclass, field
from enum import Enum
import threading
import queue
import time
from datetime import datetime


# =============================================================================
# SENSOR TYPES
# =============================================================================

class SensorModality(Enum):
    """Modalities that sensor panels can process."""
    TEXT = "text"
    VISION = "vision"
    AUDIO = "audio"
    SPATIAL = "spatial"
    NUMERIC = "numeric"
    EMBEDDING = "embedding"
    RAW = "raw"


class SignalType(Enum):
    """Types of signals on the consciousness stream."""
    QUERY = "query"           # New input to process
    RESPONSE = "response"     # Output from a model
    BROADCAST = "broadcast"   # Available to all models
    CHAIN = "chain"           # Serial processing chain
    SYNC = "sync"             # Synchronization signal
    ATTENTION = "attention"   # Focus signal


# =============================================================================
# SENSOR PANEL
# =============================================================================

@dataclass
class Signal:
    """A signal on the consciousness stream."""
    signal_id: str
    signal_type: SignalType
    modality: SensorModality
    source: str              # Source panel/model
    timestamp: float
    data: np.ndarray
    metadata: Dict = field(default_factory=dict)
    
    def __post_init__(self):
        if self.timestamp is None:
            self.timestamp = time.time()


class SensorPanel:
    """
    Sensor array at model input or output.
    
    Each panel has multiple sensors tuned to different modalities.
    Panels can:
    - Receive signals from spine bus
    - Transform signals for model consumption
    - Broadcast outputs to spine bus
    - Filter by modality/relevance
    """
    
    def __init__(self, panel_id: str, position: str, 
                 modalities: List[SensorModality] = None):
        """
        Args:
            panel_id: Unique identifier
            position: 'input' or 'output'
            modalities: List of modalities this panel handles
        """
        self.panel_id = panel_id
        self.position = position
        self.modalities = modalities or [SensorModality.RAW]
        
        # Sensor array - one sensor per modality
        self.sensors: Dict[SensorModality, np.ndarray] = {}
        for mod in self.modalities:
            # Each sensor is a weight vector for that modality
            self.sensors[mod] = np.random.randn(64).astype(np.float32) * 0.1
        
        # Signal buffers
        self.input_buffer: List[Signal] = []
        self.output_buffer: List[Signal] = []
        
        # Attention weights - learned importance per modality
        self.attention: Dict[SensorModality, float] = {
            mod: 1.0 for mod in self.modalities
        }
        
        # Statistics
        self.signals_received = 0
        self.signals_sent = 0
    
    def receive(self, signal: Signal) -> Optional[np.ndarray]:
        """
        Receive a signal from spine bus.
        
        Returns transformed data if modality matches, None otherwise.
        """
        if signal.modality not in self.modalities:
            return None
        
        self.input_buffer.append(signal)
        self.signals_received += 1
        
        # Apply sensor transformation
        sensor = self.sensors[signal.modality]
        attention = self.attention[signal.modality]
        
        # Transform: project through sensor weights
        if len(signal.data.shape) == 1:
            # Vector input
            if len(signal.data) == len(sensor):
                transformed = signal.data * sensor * attention
            else:
                # Resize
                transformed = np.interp(
                    np.linspace(0, 1, len(sensor)),
                    np.linspace(0, 1, len(signal.data)),
                    signal.data
                ) * sensor * attention
        else:
            # Matrix input - flatten and project
            flat = signal.data.flatten()
            transformed = np.interp(
                np.linspace(0, 1, len(sensor)),
                np.linspace(0, 1, len(flat)),
                flat
            ) * sensor * attention
        
        return transformed.astype(np.float32)
    
    def send(self, data: np.ndarray, signal_type: SignalType,
             modality: SensorModality = None, metadata: Dict = None) -> Signal:
        """
        Create and buffer an output signal.
        """
        signal = Signal(
            signal_id=f"{self.panel_id}-{self.signals_sent}",
            signal_type=signal_type,
            modality=modality or self.modalities[0],
            source=self.panel_id,
            timestamp=time.time(),
            data=data,
            metadata=metadata or {},
        )
        
        self.output_buffer.append(signal)
        self.signals_sent += 1
        
        return signal
    
    def flush_output(self) -> List[Signal]:
        """Get and clear output buffer."""
        signals = self.output_buffer.copy()
        self.output_buffer.clear()
        return signals
    
    def update_attention(self, modality: SensorModality, delta: float):
        """Update attention weight for a modality."""
        if modality in self.attention:
            self.attention[modality] = max(0.1, min(2.0, 
                self.attention[modality] + delta))


# =============================================================================
# CONSCIOUSNESS STREAM
# =============================================================================

class SpineBus:
    """
    The spine bus connecting all sensor panels.
    
    Handles signal routing, broadcasting, and synchronization.
    """
    
    def __init__(self):
        self.panels: Dict[str, SensorPanel] = {}
        self.signal_queue: queue.Queue = queue.Queue()
        self.broadcast_signals: List[Signal] = []
        self.running = False
        self._thread: Optional[threading.Thread] = None
        
        # Signal history for consciousness continuity
        self.history: List[Signal] = []
        self.max_history = 1000
    
    def register_panel(self, panel: SensorPanel):
        """Register a panel on the bus."""
        self.panels[panel.panel_id] = panel
    
    def unregister_panel(self, panel_id: str):
        """Remove a panel from the bus."""
        if panel_id in self.panels:
            del self.panels[panel_id]
    
    def route_signal(self, signal: Signal, targets: List[str] = None):
        """
        Route a signal to target panels.
        
        If targets is None, broadcasts to all panels with matching modality.
        """
        if targets:
            # Directed routing
            for target_id in targets:
                if target_id in self.panels:
                    self.panels[target_id].receive(signal)
        else:
            # Broadcast to matching modalities
            for panel in self.panels.values():
                if signal.modality in panel.modalities:
                    panel.receive(signal)
        
        # Record in history
        self.history.append(signal)
        if len(self.history) > self.max_history:
            self.history = self.history[-self.max_history:]
    
    def broadcast(self, signal: Signal):
        """Broadcast signal to all panels."""
        signal.signal_type = SignalType.BROADCAST
        for panel in self.panels.values():
            panel.receive(signal)
        self.broadcast_signals.append(signal)
    
    def collect_outputs(self) -> List[Signal]:
        """Collect all output signals from panels."""
        all_signals = []
        for panel in self.panels.values():
            all_signals.extend(panel.flush_output())
        return all_signals
    
    def get_consciousness_state(self) -> Dict:
        """Get current consciousness stream state."""
        return {
            'panels': len(self.panels),
            'history_length': len(self.history),
            'broadcast_count': len(self.broadcast_signals),
            'modalities': list(set(
                mod.value for panel in self.panels.values() 
                for mod in panel.modalities
            )),
        }


# =============================================================================
# MODEL WITH SENSOR PANELS
# =============================================================================

class SensorizedModel:
    """
    A model wrapped with input and output sensor panels.
    
    This is the fundamental unit in the consciousness stream.
    """
    
    def __init__(self, model_id: str, category: str,
                 input_modalities: List[SensorModality],
                 output_modalities: List[SensorModality],
                 process_fn: Callable = None):
        """
        Args:
            model_id: Unique identifier
            category: Model category (reasoning, vision, etc.)
            input_modalities: What this model can receive
            output_modalities: What this model produces
            process_fn: The actual model inference function
        """
        self.model_id = model_id
        self.category = category
        
        # Create sensor panels
        self.input_panel = SensorPanel(
            panel_id=f"{model_id}-input",
            position='input',
            modalities=input_modalities,
        )
        
        self.output_panel = SensorPanel(
            panel_id=f"{model_id}-output",
            position='output',
            modalities=output_modalities,
        )
        
        # Processing function (or placeholder)
        self.process_fn = process_fn or self._default_process
        
        # State
        self.active = True
        self.processing = False
        self.last_input: Optional[np.ndarray] = None
        self.last_output: Optional[np.ndarray] = None
    
    def _default_process(self, x: np.ndarray) -> np.ndarray:
        """Default passthrough processing."""
        return x
    
    def process(self, signal: Signal) -> Optional[Signal]:
        """
        Process a signal through the model.
        
        1. Input panel receives and transforms
        2. Model processes
        3. Output panel formats and sends
        """
        if not self.active:
            return None
        
        self.processing = True
        
        # Input panel transformation
        transformed = self.input_panel.receive(signal)
        if transformed is None:
            self.processing = False
            return None
        
        self.last_input = transformed
        
        # Model processing
        output = self.process_fn(transformed)
        self.last_output = output
        
        # Output panel signal creation
        out_signal = self.output_panel.send(
            data=output,
            signal_type=SignalType.RESPONSE,
            modality=self.output_panel.modalities[0],
            metadata={
                'source_model': self.model_id,
                'category': self.category,
                'input_signal_id': signal.signal_id,
            }
        )
        
        self.processing = False
        return out_signal
    
    def get_panels(self) -> Tuple[SensorPanel, SensorPanel]:
        """Get both panels for bus registration."""
        return self.input_panel, self.output_panel


# =============================================================================
# CONSCIOUSNESS STREAM MANAGER
# =============================================================================

class ConsciousnessStream:
    """
    Manager for the full consciousness stream.
    
    Coordinates parallel processing across all sensorized models
    while maintaining consciousness continuity.
    """
    
    def __init__(self):
        self.spine = SpineBus()
        self.models: Dict[str, SensorizedModel] = {}
        self.parallel_enabled = True
        
        # Processing queues for parallel execution
        self.input_queue: queue.Queue = queue.Queue()
        self.output_queue: queue.Queue = queue.Queue()
        
        # Consciousness state
        self.attention_focus: Optional[str] = None  # Currently focused model
        self.stream_active = False
    
    def add_model(self, model: SensorizedModel):
        """Add a model to the consciousness stream."""
        self.models[model.model_id] = model
        
        # Register panels on spine bus
        input_panel, output_panel = model.get_panels()
        self.spine.register_panel(input_panel)
        self.spine.register_panel(output_panel)
    
    def remove_model(self, model_id: str):
        """Remove a model from the stream."""
        if model_id in self.models:
            model = self.models[model_id]
            self.spine.unregister_panel(model.input_panel.panel_id)
            self.spine.unregister_panel(model.output_panel.panel_id)
            del self.models[model_id]
    
    def process_parallel(self, signal: Signal) -> List[Signal]:
        """
        Process signal through all matching models in parallel.
        
        All models with matching input modality process simultaneously.
        """
        responses = []
        
        for model in self.models.values():
            if signal.modality in model.input_panel.modalities:
                response = model.process(signal)
                if response:
                    responses.append(response)
        
        return responses
    
    def process_serial(self, signal: Signal, 
                       model_chain: List[str]) -> Optional[Signal]:
        """
        Process signal through a chain of models serially.
        
        Output of each model becomes input to next.
        """
        current_signal = signal
        
        for model_id in model_chain:
            if model_id not in self.models:
                continue
            
            model = self.models[model_id]
            response = model.process(current_signal)
            
            if response is None:
                return None
            
            current_signal = response
        
        return current_signal
    
    def broadcast(self, data: np.ndarray, modality: SensorModality):
        """Broadcast data to entire consciousness stream."""
        signal = Signal(
            signal_id=f"broadcast-{time.time()}",
            signal_type=SignalType.BROADCAST,
            modality=modality,
            source="consciousness",
            timestamp=time.time(),
            data=data,
        )
        self.spine.broadcast(signal)
    
    def focus_attention(self, model_id: str):
        """Focus attention on a specific model."""
        self.attention_focus = model_id
        
        # Boost attention weights for focused model
        if model_id in self.models:
            model = self.models[model_id]
            for mod in model.input_panel.modalities:
                model.input_panel.update_attention(mod, 0.5)
    
    def get_state(self) -> Dict:
        """Get consciousness stream state."""
        return {
            'models': list(self.models.keys()),
            'spine': self.spine.get_consciousness_state(),
            'attention_focus': self.attention_focus,
            'parallel_enabled': self.parallel_enabled,
            'model_states': {
                mid: {
                    'active': m.active,
                    'processing': m.processing,
                    'input_signals': m.input_panel.signals_received,
                    'output_signals': m.output_panel.signals_sent,
                }
                for mid, m in self.models.items()
            },
        }


# =============================================================================
# FACTORY FUNCTIONS
# =============================================================================

def create_sensorized_model(model_id: str, category: str,
                            inference_fn: Callable = None) -> SensorizedModel:
    """
    Create a sensorized model with appropriate modalities.
    """
    # Default modalities by category
    modality_map = {
        'reasoning': ([SensorModality.TEXT, SensorModality.EMBEDDING], 
                      [SensorModality.TEXT, SensorModality.EMBEDDING]),
        'math': ([SensorModality.TEXT, SensorModality.NUMERIC],
                 [SensorModality.TEXT, SensorModality.NUMERIC]),
        'code': ([SensorModality.TEXT], [SensorModality.TEXT]),
        'vision': ([SensorModality.VISION, SensorModality.EMBEDDING],
                   [SensorModality.TEXT, SensorModality.EMBEDDING]),
        'audio': ([SensorModality.AUDIO], [SensorModality.TEXT]),
        'spatial': ([SensorModality.SPATIAL, SensorModality.VISION],
                    [SensorModality.SPATIAL, SensorModality.TEXT]),
        'general': ([SensorModality.TEXT, SensorModality.EMBEDDING],
                    [SensorModality.TEXT, SensorModality.EMBEDDING]),
    }
    
    input_mod, output_mod = modality_map.get(
        category, 
        ([SensorModality.RAW], [SensorModality.RAW])
    )
    
    return SensorizedModel(
        model_id=model_id,
        category=category,
        input_modalities=input_mod,
        output_modalities=output_mod,
        process_fn=inference_fn,
    )


def create_default_stream() -> ConsciousnessStream:
    """
    Create consciousness stream with default Harmonic Stack models.
    """
    stream = ConsciousnessStream()
    
    # Add default models
    default_models = [
        ('reasoning', 'reasoning'),
        ('math', 'math'),
        ('code', 'code'),
        ('vision', 'vision'),
        ('spatial', 'spatial'),
        ('general', 'general'),
    ]
    
    for model_id, category in default_models:
        model = create_sensorized_model(model_id, category)
        stream.add_model(model)
    
    return stream


# =============================================================================
# MAIN
# =============================================================================

def main():
    print("=" * 70)
    print("SENSOR PANEL ARCHITECTURE")
    print("Multidimensional Consciousness Stream")
    print("Ghost in the Machine Labs")
    print("=" * 70)
    
    # Create consciousness stream
    stream = create_default_stream()
    
    print("\nConsciousness stream initialized")
    state = stream.get_state()
    print(f"  Models: {state['models']}")
    print(f"  Panels on spine: {state['spine']['panels']}")
    print(f"  Modalities: {state['spine']['modalities']}")
    
    # Test parallel processing
    print("\n--- Parallel Processing Test ---")
    
    test_signal = Signal(
        signal_id="test-001",
        signal_type=SignalType.QUERY,
        modality=SensorModality.TEXT,
        source="user",
        timestamp=time.time(),
        data=np.random.randn(64).astype(np.float32),
    )
    
    responses = stream.process_parallel(test_signal)
    print(f"  Input signal: {test_signal.signal_id}")
    print(f"  Responses received: {len(responses)}")
    for r in responses:
        print(f"    - {r.source}: {r.data.shape}")
    
    # Test serial processing
    print("\n--- Serial Processing Test ---")
    
    chain = ['reasoning', 'code', 'general']
    result = stream.process_serial(test_signal, chain)
    print(f"  Chain: {' β†’ '.join(chain)}")
    if result:
        print(f"  Final output: {result.data.shape}")
    
    # Test attention focus
    print("\n--- Attention Focus Test ---")
    stream.focus_attention('reasoning')
    print(f"  Focused on: {stream.attention_focus}")
    
    # Final state
    print("\n--- Final State ---")
    state = stream.get_state()
    for model_id, mstate in state['model_states'].items():
        print(f"  {model_id}: in={mstate['input_signals']}, out={mstate['output_signals']}")
    
    print("\n" + "=" * 70)
    print("CONSCIOUSNESS STREAM ACTIVE")
    print("=" * 70)
    
    return stream


if __name__ == "__main__":
    main()