Inspiration
Factories, industrial heaters, conveyors, and emergency stops around the world still run on 1970s relay ladder logic—a programming paradigm invented to mimic hardwired electromechanical relay cabinets. In a PLC (Programmable Logic Controller), rungs execute top-to-bottom in a tight scan loop. A single misordered rung, duplicate output coil, or timer race can energize a heater or start a conveyor while an over-temperature fault or open safety guard is active.
Testing these multi-scan hazards by hand misses edge cases, and asking an LLM to eyeball safety-critical wiring is reckless. RungScope resurrects 1970s relay ladder logic inside a zero-backend CRT oscilloscope workbench paired with a deterministic formal verifier—proving safety hazards mathematically in milliseconds, right in the browser and inside Kiro.
What it does
RungScope runs entirely client-side at rungscope.pages.dev with no login, no server, and no API keys:
- Bounded BFS Model Checking: Exhaustively explores reachable combinations of switches, sensors, timers, and latches to prove safety invariants or produce the shortest multi-scan counterexample. On first paint, it explores 11 states to depth 5 and catches a 5-scan Thermal Interlock Race where a heater stays energized during an over-temp fault.
- CRT Oscilloscope, Plant Mimics & Causal Blame: Scrubbing through the waveform trace animates the live industrial Plant Mimic scan-by-scan while Causal Blame pinpoints and highlights the exact offending rung. Plain-English hints explain every industrial term (rung, scan, invariant) directly in the UI.
- Live Click-to-Mutate & IEC 61131-3 IL Drawer: Click any contact on the ladder to invert it (XIC ↔ XIO) or edit raw IEC 61131-3 Instruction List (IL) assembly directly—the ladder, mimic, verdict, and digest recompute in milliseconds.
- One-Click Interlock Fix, FMEA & Adversarial Fuzzing:
- Apply Interlock Fix reorders the trip latch and proves the invariant holds across all 12 reachable states (FIX HOLDS).
- Sensor Fault Sweep (FMEA) tests every input stuck at 0 and stuck at 1, exposing single-point physical sensor failures (like a stuck-at-0 over-temp sensor) even after nominal logic passes.
- Adversarial Fuzz runs 200 randomized stress sequences against the circuit.
- 3 Industrial Presets: Thermal Interlock Race, Dual-Coil Conveyor Hazard (where a duplicate jog coil overrides an open safety guard on scan 1), and E-Stop Timer Trap.
- Tamper-Evident Receipts & Zero-Backend Proof Links: Every verification emits a deterministic JSON proof receipt with exact state/depth bounds and a SHA-256 circuitDigest. Copy Proof Link encodes edited circuits and preset state into #rung= URLs that restore cleanly across reloads.
- Installable Kiro Power (powers/rungscope-verifier): Exposes verify_plc_il, fmea_sweep_il, and list_presets over stdio MCP alongside a plc-safety-audit Agent Skill. Instead of guessing whether factory wiring is safe, Kiro invokes the exact same deterministic verifier and outputs a byte-for-byte identical SHA-256 circuitDigest (070906d7... faulty / 8b262905... fixed).
How we built it
RungScope was built spec-first with Kiro, anchored by three complete specification trees in .kiro/specs/:
- plc-verifier: IEC 61131-3 IL parser, deterministic scan-cycle evaluator, bounded BFS state-space explorer, Causal Blame engine, and stuck-sensor FMEA sweep.
- instrument-ui: Vector CRT oscilloscope trace renderer, interactive SVG ladder layout, animated Plant Mimics, plain-English glosses, and zero-backend URL codec (src/ui/shareUrl.ts).
- live-editor-fmea: Click-to-mutate contact editing, live IL drawer, adversarial fuzzer, JSON proof receipt exporter, and the standalone stdio MCP server (powers/rungscope-verifier/scripts/mcp-server.mjs).
The codebase is written in TypeScript + Vite and deployed as a static bundle on Cloudflare Pages. Correctness is guarded by 933 automated tests across 59 files (Vitest + fast-check property-based tests), including replay properties that execute every verifier counterexample through the scan evaluator and performance tests confirming 10,000-state exploration of an 8-input program finishes in under 500 ms.
Challenges we ran into
- Keeping AI honest on safety proofs: LLMs are great at explaining faults and proposing fixes, but they should never be the judge of whether industrial wiring is safe. Splitting the architecture—deterministic BFS + SHA-256 digests in the engine, Kiro as the builder and MCP operator—eliminated hallucinated verdicts while giving engineers a conversational audit workflow.
- Browser-to-CLI proof parity: Ensuring the browser bundle and the Node stdio MCP server serialize circuits identically so both compute the exact same SHA-256 circuitDigest for every preset and edited ladder.
- Stateless #rung= hydration: Edited proof links originally hydrated the ladder and digest properly while leaving the preset dropdown and Plant Mimic on the default thermal preset. Adding &presetId= encoding plus signal-based preset inference for legacy links—backed by 13 end-to-end reload regression tests—made shared links restore cleanly from the first frame.
Accomplishments that we're proud of
- Zero-backend formal verification running in milliseconds inside a browser tab with full SHA-256 receipts and URL-encoded proof sharing.
- Byte-for-byte hash parity between https://rungscope.pages.dev and the rungscope-verifier Kiro Power running in Kiro CLI over stdio MCP.
- 933 passing tests across 59 files, including property-based verification of ladder layout, waveform geometry, counterexample replay, and FMEA performance.
- Making 1970s industrial relay logic immediately understandable to non-engineers through plain-English UI glosses and animated Plant Mimics.
What we learned
- Formal methods do not have to feel intimidating—pairing a bounded model checker with a visual CRT trace, Plant Mimic, and plain-English Causal Blame turns state-space exploration into something anyone can grasp in 30 seconds.
- Spec-driven development in Kiro (requirements.md → design.md → tasks.md) keeps complex invariants aligned across parser, verifier, UI, and MCP layers.
- Pairing deterministic MCP tools with an Agent Skill turns Kiro from a code generator into an auditable engineering workbench.
What's next for RungScope
- Expanding IEC 61131-3 support to additional timers (TOF, TP), counters (CTU/CTD), and Structured Text (ST) import.
- Supporting multi-sensor simultaneous fault combinations in the FMEA matrix beyond single-point stuck-at-0/1 sweeps.
- Adding import/export bridges for common open PLC XML formats (PLCopen XML) so controls engineers can drop existing factory rungs straight into RungScope or audit them directly from Kiro.
Built With
- cloudflare-pages
- css3
- fast-check
- formal-verification
- html5
- iec-61131-3
- kiro
- kiro-powers
- mcp
- node.js
- svg
- typescript
- vite
- vitest