This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
bun run dev # Run TUI with hot reload
bun run start # Run TUI
bun run cli # Run CLI (--help for options)
bun test # Run all tests
bun test src/stats # Run tests in specific directoryMarigraph is a terminal-based volatility surface visualization tool with a multi-process architecture:
- Main Process (
src/main.ts): Spawns column workers viaBun.spawn(), routes IPC messages between them - Column Workers (
src/column/worker.ts): Independent subprocesses that handle widget rendering, communicate via stdin/stdout binary frames - TUI (
src/tui/App.tsx): Ink/React-based terminal UI that renders the 7-column risk oracle layout
Binary frame format (8-byte header):
length: u32- payload lengthtype: u8- MessageType enum fromsrc/ipc/protocol.tsflags: u8- compression, request/response flagsseq: u16- sequence number for request/response matching
Messages are encoded/decoded in src/ipc/frame.ts, surfaces serialized in src/ipc/serialize.ts.
External Data → Main Process → Column Workers → TUI Render
↓
Unix Sockets (/tmp/marigraph-{id}/*.sock)
↓
External Programs (JSON-RPC)
| Module | Purpose |
|---|---|
src/data/surface.ts |
Surface<Vec64|Vec32> type, slope computation |
src/render/project.ts |
3D→2D projection with rotation/zoom |
src/render/rasterize.ts |
ASCII/braille terminal rasterization |
src/stats/welford.ts |
Streaming statistics (Welford's algorithm) |
src/surface/svi.ts |
SVI volatility model calibration |
src/surface/arbitrage.ts |
Calendar/butterfly arbitrage detection |
src/oracle/risk.ts |
Risk metrics computation, term structure/smile analysis |
Widgets in src/column/widgets/ are Ink/React components:
Surface.tsx- 3D cube visualization with keyboard controlsList.tsx,Table.tsx,Chart.tsx,Log.tsx- Standard TUI widgets
Templates (src/config/) define column layouts and event wiring in YAML/JSON. Event wiring routes messages between columns (e.g., surface update → risk score recalculation).
- Use
bun:testfor testing withexpect()assertions - Use
Bun.spawn()for subprocesses,Bun.listen()for Unix sockets - Use
Bun.sleep()instead of setTimeout for async delays - Prefer
Bun.write(Bun.stdout, data)for binary stdout writes