Prismatic Core

Prismatic Core

180 files Foundation

Overview

Prismatic Core is the foundational library of the Prismatic Platform -- the single dependency shared by all 141 umbrella applications. Far beyond a simple utilities package, it provides a comprehensive computational and coordination substrate: Monte Carlo simulation with 25 probability distributions, bifurcation analysis for detecting regime changes in complex systems, quantum-inspired optimization for combinatorial problems, bio-inspired mycelial coordination networks, zero-downtime evolution infrastructure, JWT/RBAC authentication, and epistemic reasoning primitives.

A platform comprising 115 OTP applications requires a shared foundation of types, protocols, utilities, and computational engines. Without centralization, each application would define its own entity representations, error types, simulation engines, and coordination mechanisms -- leading to incompatible interfaces, duplicated implementations, and inconsistent behavior. Cross-application communication requires agreed-upon data structures, protocols, and shared computational infrastructure. Prismatic Core provides this foundation, ensuring all applications speak the same language for entities, errors, configuration, mathematical computation, and cross-domain coordination.

The library establishes the platform's type system through entity protocols for consistent data access, serialization protocols for storage adapter compatibility, validation protocols for data integrity, and comparison protocols for ordering. It provides platform-wide configuration management, structured error types following the {:ok, result} | {:error, reason} convention, cryptographic utilities (SHA-256, HMAC-SHA256, AES-256-GCM), string manipulation with Czech diacritics support, date/time handling with timezone awareness, deterministic UUID generation via SHA-256 hashing, and collection utilities.

Architecture

Every Prismatic Application (92 apps)
       |
  depends on
       |
  Prismatic Core
  +-- Protocols (Entity, Serializable, Validatable, Comparable)
  +-- Entities (base definitions, identity management)
  +-- Config (platform-wide configuration access)
  +-- Errors (structured error types)
  +-- Crypto (SHA-256, HMAC, AES-256-GCM)
  +-- Utils (strings, dates, collections, UUID)
  |
  +-- Monte Carlo Engine (25 distributions, GenStage pipeline, streaming)
  +-- Bifurcation Analysis (Hopf, pitchfork, saddle-node, transcritical)
  +-- Quantum Optimizer (annealing, tunneling, superposition search)
  +-- Mycelial Network (cross-domain coordination, signal routing)
  +-- Zero-Downtime Evolution (hot code upgrades, schema migration, rollback)
  |
  +-- Auth (JWT RS256/HS256, RBAC, rate limiting)
  +-- EpRun (epistemic reasoning: claims, evidence, nabla scores)
  +-- Behaviours (Agent, LLM, Storage, UniversalConvergence)
  +-- Schemas (LLM, Agent, Storage, Investigation)
  +-- Integration (Gateway, EventBus, Telemetry)
  +-- Runtime (PubSub topics, safe atoms, feature flags, git trees)

Applications import Core modules and call functions directly. Protocol dispatch is resolved at compile time for known types and at runtime for dynamic dispatch. The computational subsystems (Monte Carlo, Bifurcation, Quantum, Mycelial) are independently usable but designed to compose -- Monte Carlo feeds probability distributions into bifurcation analysis, quantum optimizer uses Monte Carlo for stochastic evaluation, and mycelial networks propagate signals between all subsystems.

Monte Carlo Simulation Engine

The Monte Carlo engine is one of the most substantial subsystems in Prismatic Core, providing probabilistic simulation capabilities used across risk analysis, security assessment, uncertainty quantification, and AI calibration.

25 Probability Distributions

The engine implements a comprehensive distribution library, each conforming to the Distribution behaviour with callbacks for sampling, PDF/CDF computation, moment calculation, and parameter estimation.

Continuous (15): Normal, Log-Normal, Beta, Exponential, Gamma, Uniform, Weibull, Cauchy, Pareto, Triangular, Student-t, Gumbel, Laplace, Von Mises, Chi-Squared

Discrete (7): Poisson, Bernoulli, Binomial, Geometric, Negative Binomial, Hypergeometric, Zipf

Multivariate (3): Multinomial, Dirichlet, F-Distribution

Streaming Architecture

The simulation pipeline uses GenStage for demand-driven backpressure management:

Producer (sampling) --> Processor (simulation) --> Consumer (collection)
                                                        |
                                              PubSub streaming
                                              (live dashboards)

Early convergence detection monitors result stability and terminates runs once statistical significance thresholds are met. Flow-based parallel execution distributes iterations across all available CPU cores. Windowed simulation provides periodic statistics for real-time monitoring.

DSL for Simulation Workflows

The Monte Carlo DSL provides a declarative interface for defining complex simulation scenarios:

alias PrismaticCore.MonteCarlo

# Risk simulation with multiple uncertain parameters
{:ok, result} = MonteCarlo.simulate(%{
  model: :breach_probability,
  parameters: %{
    vuln_count: {:normal, 12, 3},
    patch_time: {:lognormal, 30, 10},
    attack_frequency: {:poisson, 0.1}
  },
  iterations: 100_000
})

# Sensitivity analysis identifying key risk drivers
{:ok, sensitivity} = MonteCarlo.sensitivity(result)
# => %{patch_time: 0.62, vuln_count: 0.31, attack_frequency: 0.07}

# Value at Risk and Expected Shortfall
var_99 = MonteCarlo.value_at_risk(samples, 0.99)
cvar_95 = MonteCarlo.expected_shortfall(samples, 0.95)

Applications

DomainMonte Carlo Use Case
Security RatingsConfidence intervals on A-F grades via breach probability modeling
OSINT AnalysisSource reliability estimation through repeated assessment
Risk AssessmentPortfolio-level risk aggregation with correlated scenarios
AI CalibrationBootstrap confidence intervals on model performance metrics
Investment ROISecurity investment return modeling under uncertainty

Bifurcation Analysis

The bifurcation subsystem provides mathematical framework for analyzing critical transitions in complex systems -- detecting when systems shift qualitatively from one behavioral regime to another. This is particularly relevant for AI drift detection, market phase transitions, and risk tipping points.

Bifurcation Types

TypePhysical MeaningDetection Signature
HopfSystem starts oscillating (fixed point to limit cycle)Complex eigenvalues cross imaginary axis
PitchforkSymmetry breaks, two new stable states emergeEigenvalue passes through zero with cubic nonlinearity
Saddle-NodeEquilibrium suddenly appears or disappears (sudden jumps)Two eigenvalues collide and annihilate
TranscriticalStable and unstable equilibria exchange rolesEigenvalue passes through zero with stability exchange

Stability Analysis

The stability.ex module provides Lyapunov stability analysis, eigenvalue computation, and basin of attraction estimation. These mathematical tools determine whether a system near an equilibrium point will return to it (stable), diverge away (unstable), or remain at the boundary (marginally stable).

# Detect regime change in AI system behavior
{:ok, result} = PrismaticCore.Bifurcation.detect_bifurcation(system_data, opts)
# => %{type: :hopf, parameter_value: 3.14, confidence: 0.92}

# Parameter sweep across a range to find transition points
{:ok, sweep} = PrismaticCore.Bifurcation.parameter_sweep(
  system_fn, {0.0, 10.0}, steps: 100
)

Applications

DomainBifurcation Use Case
AI Drift DetectionMonitoring when AI system behavior undergoes qualitative regime change
Market AnalysisDetecting phase transitions in economic indicators (boom-bust cycles)
Risk AssessmentIdentifying tipping points in risk profiles (gradual accumulation to crisis)
Agent EcosystemDetecting emergent collective behavior shifts in 530+ agent populations
Security MonitoringIdentifying when attack surface complexity crosses critical thresholds

The key insight: many real-world systems do not degrade linearly. They remain stable until a parameter crosses a critical threshold, then shift abruptly to a qualitatively different regime. Bifurcation analysis mathematically characterizes these transitions, enabling early warning before the tipping point is reached.

Quantum-Inspired Optimization

The quantum optimizer implements optimization algorithms inspired by quantum mechanical principles -- simulated quantum annealing, quantum tunneling, superposition search, and entangled coordination -- applied to combinatorial and continuous optimization problems.

Conceptual Model

Problem --> Hamiltonian --> Quantum Annealing --> Measurement --> Solution
                 |                  |
                 +-- Tunneling      +-- Superposition Search
                 +-- Entanglement   +-- Temperature Schedule

No quantum hardware required. These are classical algorithms that leverage quantum-mechanical heuristics to escape local optima more effectively than traditional approaches.

Modules

ModulePurpose
quantum_state.exSuperposition of candidate solutions with amplitudes
quantum_annealing.exThermal + quantum fluctuations to escape local minima
quantum_tunneling.exProbabilistic barrier penetration for escaping energy wells
superposition_search.exParallel evaluation of multiple candidates simultaneously
hamiltonian.exEncodes optimization problems as energy minimization
entangled_coordination.exEntanglement-inspired coordination for dependent variables

Applications

ProblemHow Quantum Optimizer Helps
Agent Task AssignmentOptimal allocation of 530+ agents to concurrent tasks (combinatorial)
OSINT Source SelectionBest combination of 157 OSINT tools for a given query (subset selection)
Risk Portfolio OptimizationOptimal risk-return tradeoffs in multi-objective space
Decision Threshold CalibrationEscaping local optima in FPR/TPR optimization landscape
Security Rating CompositionOptimal weighting of security factors for rating computation

The quantum optimizer integrates naturally with Monte Carlo for stochastic objective function evaluation and with the mycelial network for distributing optimization across domains.

Mycelial Coordination Network

Bio-inspired coordination network modeled after mycelial (fungal) networks in nature. In biology, mycelial networks connect trees across forests, sharing nutrients and warning signals. In Prismatic Core, the mycelial network connects platform domains, propagating patterns and sharing resources.

Architecture

Monte Carlo --+
NABLA --------+-- Mycelial Hub --+-- Signal Router --> Subscribers
Bifurcation --+                  |
Agents -------+                  +-- Pattern Store

Signal Types

Every signal carries typed metadata enabling intelligent routing:

PropertyPurpose
TypeWhat kind of information (convergence, anomaly, resource_request)
Source domainWhere it originated (monte_carlo, nabla, agents)
ConfidenceNumeric confidence level (0.0 - 1.0)
DecayTime-based decay function for signal relevance
ProvenanceFull chain of transformations since signal creation

Applications

  • Cross-domain anomaly propagation: Drift detected in one domain automatically alerts all related domains
  • Resource coordination: Monte Carlo engine shares idle CPU capacity with other computational subsystems
  • Emergent pattern detection: Independent subsystems collaboratively identify patterns none could detect alone
  • Convergence signal sharing: NABLA epistemic engine and Monte Carlo simulation share convergence data

The mycelial network enables the platform to behave as an integrated organism rather than a collection of isolated services -- exactly the kind of cross-cutting coordination that makes 115-app ecosystems manageable.

Zero-Downtime Evolution

Infrastructure for evolving the running system without downtime -- hot code upgrades, schema migrations, architecture transformations, and multi-level rollback capabilities. Essential for production deployment on Fly.io where service interruption is unacceptable.

Evolution Pipeline

Pre-Check --> Checkpoint --> Evolution --> Health Check --> Commit
    |              |             |              |
    +-- Abort      +-- Restore   +-- Rollback   +-- Rollback

Modules

ModulePurpose
architecture_evolution.exHigh-level architecture transformation orchestration
checkpoint_manager.exSystem state capture and restore -- bulletproof rollback
health_monitor.exContinuous health monitoring during evolution operations
module_evolution.exIndividual module hot-swap and code reloading
rollback_system.exMulti-level rollback: module, schema, architecture
safety_system.exSafety gates and invariant enforcement during evolution
schema_evolution.exDatabase schema migration during live operation

Checkpoint Types

TypeScopeStorage
SystemFull application state, supervision trees, configsETS (dev) / Disk (prod)
OperationSingle operation with params and rollback instructionsIn-memory
SchemaDatabase schema state with migration trackingPersistent

Safety System

Pre-evolution invariant checks, continuous health monitoring during transformation, automatic rollback on health degradation, post-evolution verification with configurable thresholds, and immutable checkpoint history for forensic analysis. The system ensures that any evolution step can be reversed atomically if the running system shows degradation.

Authentication & Authorization

Production-ready security infrastructure providing three complementary mechanisms:

JWT Token System

RS256 (asymmetric) and HS256 (symmetric) JWT issuance and verification with configurable claims, expiration, and audience validation. The system supports key rotation for zero-downtime secret migration.

Role-Based Access Control (RBAC)

GenServer-based hierarchical RBAC with ETS-backed permission storage:

admin
  +-- manager
       +-- operator
            +-- viewer (read-only)

Permissions are stored as {role, resource, action} tuples with role hierarchy enabling implicit permission inheritance. ETS storage provides sub-microsecond permission lookups suitable for per-request authorization.

Rate Limiting

Sliding window rate limiter with configurable windows, limits, and granularity. Supports per-user, per-IP, and per-endpoint limiting with ETS-backed token buckets.

# JWT issuance
{:ok, token} = PrismaticCore.Auth.JWT.sign(%{user_id: "123", role: :admin})

# RBAC check
:ok = PrismaticCore.Auth.RBAC.authorize(:manager, :reports, :read)

# Rate limiting
case PrismaticCore.Auth.RateLimiter.check("user:123", :api_calls) do
  :ok -> proceed()
  {:error, :rate_limited} -> reject()
end

Epistemic Reasoning (EpRun)

The EpRun subsystem provides data structures for epistemic reasoning -- versioned claims with smart constructors, evidence chains, and NABLA-compatible scoring. This is the foundation for the platform's approach to treating beliefs as first-class versioned entities rather than bare boolean flags.

Core Concepts

ConceptImplementation
Claim.V1Versioned claim with immutable fields and smart constructor guards
Evidence chainLinked list of supporting/contradicting evidence with provenance
NABLA scoreComposite epistemic confidence respecting NABLA axioms
IR BridgeIntermediate Representation / PVM bridge for cross-system reasoning

Smart Constructors

Claims cannot be created with invalid state. The Claim.V1 module enforces invariants at construction time through guard functions:

# Smart constructor ensures valid claim
{:ok, claim} = EpRun.Claim.V1.new(%{
  statement: "Target system shows drift",
  confidence: 0.87,
  evidence: evidence_chain,
  source: :monte_carlo_simulation
})

This approach prevents the "magic constants everywhere" problem by making epistemic state explicit, versioned, and constrained.

Protocols & Type System

The protocol layer establishes the platform's type system, ensuring consistent data handling across all 115 applications:

ProtocolPurposeCallbacks
EntityIdentity, type resolution, metadata accessid/1, type/1, metadata/1
SerializableStorage-compatible serialization/deserializationserialize/1, deserialize/2
ValidatableData validation with structured error reportingvalidate/1, validate!/1
ComparableOrdering and equality comparisoncompare/2, equal?/2
defprotocol PrismaticCore.Entity do
  @spec id(t()) :: String.t()
  def id(entity)

  @spec type(t()) :: atom()
  def type(entity)

  @spec metadata(t()) :: map()
  def metadata(entity)
end

Czech diacritics normalization provides bidirectional conversion between accented Czech characters and their ASCII equivalents, enabling fuzzy matching in entity resolution.

Behaviours

Core behaviours define standard contracts for platform component implementations:

Primary Behaviours

BehaviourContractImplementations
Agentstart_link, handle_task, get_capabilities, health_check530+ agents
LLMchat, stream, embed, health_check, list_modelsOpenAI, Ollama, Anthropic
Storageget, put, delete, exists?, get_batch, health_checkETS, Ecto, Meilisearch, KuzuDB

Extended Behaviours

BehaviourPurpose
UniversalConvergenceCross-domain convergence detection across Monte Carlo, NABLA, Mendel
BlackboardFrameProtocolFrame-based communication standard for multi-agent coordination
HealthCircuitBridgeHealth monitoring bridge with circuit breaker integration

Schemas

Domain-specific Ecto schemas organized by concern:

LLM Domain: Agent configurations (provider, model, system prompt), Memory types (short-term, long-term, vector, episodic), Prompt templates with variable interpolation

Agent Domain: Registry (agent registration and discovery), Execution (task tracking with timestamps)

Storage Domain: Adapter configurations (backend type, connection params)

Investigation Domain: OSINT investigation schemas with evidence linking

Runtime & Integration

PubSub Topic Registry

Compile-time constants for all platform PubSub channels:

prismatic:heartbeat          -- Global system pulse (1Hz)
prismatic:run:*              -- Orchestration lifecycle
prismatic:step:*             -- Step execution events
prismatic:commands           -- UI --> System commands
prismatic:mendel:policy      -- Meta-agent optimization

Event Payload Contract

All events include version, ISO8601 timestamp, agent identity, and event-specific data -- ensuring cross-system interoperability.

Git Trees (~100x faster file operations)

The git_trees module provides file system operations using git ls-tree instead of find/ls -R, achieving ~100x speedup on large repositories (80ms vs 500ms+ for 48,000 files).

Integration Gateway

The integration layer provides Gateway (external service routing), EventBus (internal event distribution), and UnifiedTelemetry (standardized metrics emission).

Configuration

config :prismatic_core,
  environment: :prod,
  timezone: "Europe/Prague",
  locale: :cs,
  crypto_key_env: "PRISMATIC_CRYPTO_KEY"

Minimal by design. Environment determines runtime behavior. Timezone defaults to Prague for Czech-centric operations. Crypto key sourced from environment variables, never committed to source code.

Performance

OperationLatencyNotes
Protocol dispatch< 1 usCompiled dispatch for known types
SHA-256 hash< 10 usNIF-backed Erlang crypto
String normalization< 50 usUnicode character mapping
Config lookup< 1 usApplication env read
Monte Carlo (10K)< 100 msSingle parameter, single core
Monte Carlo (100K)1-5 sMulti-parameter, parallel
Bifurcation detection< 500 msEigenvalue computation
Quantum annealing step< 1 msPer iteration
RBAC permission check< 1 usETS lookup
JWT verification< 100 usRS256 signature check

Pure functions with no shared state for the utility layer. Infinitely concurrent. Computational subsystems (Monte Carlo, Bifurcation, Quantum) use supervised processes for resource management.

Testing

Protocol implementation tests verify correct dispatch for all supported types. Error type tests verify pattern matching and message formatting. Crypto tests verify hash computation against known test vectors. Cross-application integration tests verify that entities serialized by one application can be deserialized by another through shared protocols.

Property-based tests use StreamData generators to produce random strings, dates, and entity data, verifying that serialization roundtrips preserve data integrity and that Czech normalization is idempotent. Monte Carlo distribution tests verify statistical moments against theoretical values. Bifurcation tests verify detection against known dynamical systems with analytically computed transition points.

NABLA Compliance

As the foundational library, Prismatic Core provides the building blocks that other modules use to implement NABLA compliance:

NABLA AxiomCore ContributionImplementation
Provenance MandatoryEntity protocol includes metadata with creation timestampsProtocol enforces provenance fields on all entity types
Signal PluralityMonte Carlo produces probabilistic signals requiring corroborationSimulation results are one signal among many, never sole basis
Contradiction PreservationBifurcation analysis preserves multi-modal distributionsBimodal and conflicting scenarios explicitly surfaced
Unknown ValidEpRun claims have explicit uncertainty representationStructured errors and claims distinguish "not found" from "unknown"
Time DecayMycelial signals carry time-based decay functionsSignal relevance decreases as input conditions age

The AI Drift Calibration Pipeline

One of the most powerful demonstrations of Prismatic Core's subsystem composition is the AI Drift calibration pipeline, where multiple core subsystems work together:

1. Monte Carlo     --> Bootstrap confidence intervals on FPR/TPR
2. Bifurcation     --> Detect regime changes in detection behavior
3. Quantum Optimizer --> Find optimal threshold minimizing expected cost
4. Mycelial        --> Propagate calibration signals across detection domains
5. EpRun           --> Track calibration claims with versioned evidence

This pipeline replaces ad-hoc "pinata-style" threshold tuning with a principled, reproducible, and monitorable calibration system where every decision is:

  • Derived from cost function optimization (not magic constants)
  • Versioned as an epistemic claim with full provenance
  • Monitored for regime changes via bifurcation analysis
  • Distributed across domains via mycelial coordination

Integration Points

RelationshipDescription
DependentsAll 115 Prismatic applications
DependenciesNone (Elixir stdlib + OTP only)
Prismatic AlgorithmsNx-based implementations consuming Core's Monte Carlo engine
Prismatic Monte CarloFull-featured Monte Carlo app built on Core's simulation primitives
Prismatic NablaEpistemic framework using Core's EpRun claims and mycelial signals
Prismatic PerimeterSecurity ratings using Core's Monte Carlo for confidence intervals

Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL