Architecture
How the safety gate, chaos sandbox, passive detectors, evidence scrubber, AI brain, and CodeHealer fit together.
Overview
LOKI System Architecture
02Chaos Sandbox & Swarm(sandbox.py · personas.py · api_chaos.py)
Click any node in the diagram to inspectLaunches isolated Playwright browsers (Chromium, Firefox, WebKit & mobile devices), drives the 4 chaos personas, injects in-flight HTTP/Auth faults, and coordinates Barrier(N) race probes.
rage-clickernovice-chaoticnetwork-tormentoradversaryApiChaosEngineBarrier(N)
Core Modules
| Flag | Type | Default | Description |
|---|---|---|---|
| cli.py & safety.py | Entry & Auth Gate | Always active | Parses Typer CLI commands, resolves .loki/config.yaml and .loki/models.json, and enforces ensure_target_authorized() before any browser session starts. |
| sandbox.py & personas.py | Chaos Engine | Playwright | Launches isolated Chromium, Firefox, or WebKit contexts (desktop or emulated mobile devices), drives the 4 chaos personas (rage-clicker, novice-chaotic, network-tormentor, adversary), and orchestrates --concurrency race probes. |
| api_chaos.py | Network & Auth Faults | 30% fault rate | Intercepts XHR/fetch traffic in-flight to inject 5xx errors, corrupt JSON, artificial latency, stripped keys, and 401/403/cookie-eviction auth faults. |
| detectors.py | 7 Passive Detectors | Real-time | Monitors JS exceptions & unhandled rejections, network 4xx/5xx & failed requests, unexpected dialogs, error pages, broken resources, mobile layout overflow, and UI main-thread freezes. |
| reporter.py, scrubber.py & reproducer.py | Evidence & Repro | .loki/runs/run_*/ | Redacts secrets from network.har (NetworkScrubber), writes incident.json, replay.webm, and report.html, and generates deterministic Playwright reproduction scripts (repro_test.py). |
| brain.py & healer.py | AI Brain & CodeHealer | LiteLLM | Evaluates .loki/rules.md at the end of the session (PASSED / VIOLATED), diagnoses root causes, synthesizes surgical code patches with <file>.loki.bak backups, and verifies fixes via repro_test.py. |
