Architectureยถ

        flowchart TB
    %% --- STYLING ---
    classDef hardware fill:#000,stroke:#fff,stroke-width:2px;
    classDef bus fill:#b82e2e,stroke:#fff,stroke-width:4px,color:#fff;
    classDef reflex fill:#2d5a27,stroke:#fff,stroke-width:2px,color:#fff;
    classDef engine fill:#5e2a84,stroke:#a855f7,stroke-width:3px,color:#fff;
    classDef abi fill:#0f766e,stroke:#2dd4bf,stroke-width:2px,color:#fff,stroke-dasharray: 5 5;
    classDef mind fill:#1c3a6e,stroke:#fff,stroke-width:2px,color:#fff;
    classDef memory fill:#444,stroke:#888,stroke-width:1px,stroke-dasharray: 2 2;
    classDef highlight fill:#BB2528,stroke:#fff,stroke-width:3px,color:#fff;
    classDef sandbox fill:#222,stroke:#BB2528,stroke-width:2px,color:#fff,stroke-dasharray:5 3;
    classDef cloud fill:#333,stroke:#fff,stroke-width:1px,stroke-dasharray:2 2;
    classDef quarantine fill:#1a1a2e,stroke:#BB2528,stroke-width:3px,color:#fff;
    classDef darkstore fill:#2d2d42,stroke:#666,stroke-width:2px,color:#fff;

    %% --- REALITY LAYER ---
    subgraph Reality ["Reality (Physical Layer)"]
        Sensors:::hardware
        Actuators[("๐Ÿšฆ Actuators")]:::hardware
        NewsFeeds[("๐Ÿ“ก News/Audio Streams")]:::hardware
        DarkWeb[("๐Ÿ•ธ๏ธ Legacy Govt Portals")]:::hardware
    end

    %% --- QUARANTINE & VALIDATION ZONE ---
    subgraph Quarantine ["๐Ÿ›ก๏ธ QUARANTINE ZONE (Dark Data Gateway)"]
        direction TB
        Validator["๐Ÿ” Validator Engine"]:::quarantine
        
        subgraph Checks ["Validation Stack"]
            C1["๐Ÿ›ก๏ธ Adv. Detect"]
            C2["๐Ÿ“Š Fact Grounding"]
            C3["๐Ÿง  LLM-as-Judge"]
            C4["๐Ÿ“ˆ Drift Monitor"]
        end

        DarkStore[("๐Ÿ“‚ Dark Data Store<br/>(Scored & Flagged)")]:::darkstore
    end

    %% --- THE SOURCE OF TRUTH ---
    subgraph Truth
        Redpanda{{"๐Ÿ”ด Event Log<br/>(Redpanda)"}}:::bus
    end

    %% --- SYSTEM 1: REFLEX ---
    subgraph System1 ["System 1: Reflex (Fast)"]
        Flink:::reflex
        CBF["Safety Barrier<br/>(CBF / Rust)"]:::reflex
    end

    %% --- SYSTEM 2: COGNITION ---
    subgraph System2 ["System 2: Cognition (Slow)"]
        direction TB
        
        subgraph Sandbox ["๐Ÿณ Docker Sandbox"]
            subgraph Ingest ["Refinery (Metabolism)"]
                Refinery["๐Ÿ—๏ธ RefineryEngine"]:::engine
                Crawl4AI[("๐Ÿ•ท๏ธ Scrapers & Crawlers (+ LaVague for Dark Data)")]:::mind
            end
            subgraph Protect ["Sentinel (Immunity)"]
                Sentinel["๐Ÿ›ก๏ธ SentinelEngine"]:::engine
            end
            subgraph Solve ["Solver (Cognition)"]
                Solver["โš–๏ธ SolverEngine"]:::engine
            end
            subgraph Mind ["Reasoning Core"]
                Gemini(("โœจ Gemini 3")):::highlight
                Warp["โšก NVIDIA Warp"]:::mind
                LATS["๐ŸŒฒ LATS"]:::mind
            end
        end
        subgraph Cloud ["Google Cloud"]
            GeminiLive["๐ŸŽฅ๐Ÿ”Š Gemini Live API"]:::highlight
        end
        subgraph ABI_Layer ["Cognitive ABI"]
            PydanticAI["๐Ÿงฉ Pydantic-AI"]:::abi
        end
    end

    %% --- MEMORY ---
    subgraph Memory ["Semantic Working Memory"]
        Postgres:::memory
        Vector[("pgvector")]:::memory
        Graph[("NetworkX")]:::memory
    end

    %% ================== DATA FLOWS ==================

    %% 1. REFLEX LOOP (Unchanged, Pure)
    Sensors ==> Redpanda ==> Flink ==> CBF ==> Actuators

    %% 2. DARK DATA INGESTION โ†’ QUARANTINE
    DarkWeb -.->|Raw HTML/PDF| Validator
    NewsFeeds -.->|Raw Streams| Validator

    %% 3. VALIDATION PROCESS
    Validator --> Checks
    Checks --> Validator

    %% 4. QUARANTINE OUTPUT โ†’ CONTEXT, NOT CORE LOG
    Validator -->|"Flagged & Scored Data"| DarkStore

    %% 5. SANDBOX ENGINES QUERY QUARANTINE (READ-ONLY)
    Solver -.->|"Query: Context Only"| DarkStore
    Refinery -.->|"Query: Entity Check"| DarkStore

    %% 6. CORE SANDBOX PROCESSES (Now Protected)
    Refinery -- "Spawn" --> Crawl4AI
    Crawl4AI -- "Screenshot" --> Gemini
    Sentinel <==>|Stream| GeminiLive

    %% 7. CORE REASONING & OUTPUT
    Redpanda -.->|Drift Detected| Solver
    Solver -- "Plan" --> PydanticAI <==> Gemini
    Solver ==>|"Control Signal"| Redpanda ==> CBF

    %% ================== KEY ANNOTATIONS ==================
    
    linkStyle 1,2 stroke:#BB2528,stroke-width:2px,stroke-dasharray:5 5
    linkStyle 8,9 stroke:#2dd4bf,stroke-width:2px,stroke-dasharray:5 5
    linkStyle 0,6,7,10,11 stroke:#666,stroke-width:2px

    note1["โš ๏ธ All Dark Data MUST Route Through Quarantine"]:::quarantine
    note2["๐Ÿ”’ Core Log Integrity Preserved<br/>No direct writes from untrusted data"]:::bus
    note3["๐Ÿ“ Solver can query for context,<br/>but actions are grounded in core telemetry"]:::quarantine

    Quarantine -.-> note1
    Redpanda -.-> note2
    Solver -.-> note3

    %% --- STYLING ---
    classDef budget fill:#2b1d1d,stroke:#BB2528,stroke-width:2px,color:#fff,stroke-dasharray:3 3;

    %% --- GPU EXECUTION CONTROL ---
    subgraph GPUControl ["๐Ÿงฎ GPU Execution Control Plane"]
        BudgetGate["๐Ÿ“ Budget Gate<br/>(VRAM / Grid / Time)"]:::budget
        
        subgraph DomainPrimary ["GPU Domain: PRIMARY"]
            WarpPrimary["โšก Warp Kernels<br/>(Trusted)"]:::mind
        end

        subgraph DomainExperimental ["GPU Domain: EXPERIMENTAL"]
            WarpSandbox["โšก Warp Kernels<br/>(Constrained)"]:::mind
        end
    end

    %% --- EXISTING CONNECTIONS (EXTENDED) ---

    PydanticAI -- "Validated Plan + Budget" --> Solver
    Solver -- "Pre-flight Check" --> BudgetGate

    BudgetGate -- "Approved (Primary)" --> WarpPrimary
    BudgetGate -- "Approved (Sandboxed)" --> WarpSandbox

    WarpPrimary --> Solver
    WarpSandbox -.->|Timeout / Abort| Solver

    %% --- VISUAL ANCHOR ---
    noteBudget["๐Ÿ›‘ No kernel launches without passing the Budget Gate"]:::budget
    BudgetGate -.-> noteBudget

        %% --- REFINERY INTERNAL SANITATION LAYER ---
    subgraph RefineryInternals ["๐Ÿงช Refinery Internal Pipeline"]
        direction TB

        GeminiFlash["โšก Gemini Flash<br/>(Schema + SQL Proposer)"]:::highlight
        DuckDB["๐Ÿฆ† DuckDB<br/>(Ephemeral Sanitation Engine)"]:::engine

        RawArtifacts[("๐Ÿ“„ Raw Artifacts<br/>(HTML / PDF / OCR)")]:::quarantine
        CleanViews[("โœ… Clean Views<br/>(Typed Tables)")]:::memory
    end

    %% --- INTERNAL FLOWS ---
    Crawl4AI -->|"Raw Capture"| RawArtifacts
    RawArtifacts --> DuckDB

    DuckDB -->|"Sample + Stats"| GeminiFlash
    GeminiFlash -->|"Proposed Schema + SQL"| DuckDB

    DuckDB -->|"Validated Tables"| CleanViews

    %% --- EMISSION TO EXISTING MEMORY ---
    CleanViews -.->|Entities| Graph
    CleanViews -.->|Facts| Postgres
    CleanViews -.->|Embeddings| Vector

    %% --- SAFETY ANNOTATION ---
    noteFlash["๐Ÿง  Gemini Flash proposes structure only<br/>โŒ No direct writes beyond DuckDB"]:::abi
    GeminiFlash -.-> noteFlash
    

Unsprawl Architectureยถ