MoonBit UI where every component is readable by humans and AI equally
Dependencies
let volume = signal(0.7)
let (node, narrate) = slider("vol", "Volume", volume, 0.0, 1.0, 0.05, "")
// render `node` → a draggable track a human slides
// `narrate()` → the same state as prose, live: "0.7"
volume.set(0.95) // an instance's hand on the same signal:
// the thumb moves, narrate() reads "0.95 (near max)"moon add helios-house/valencepub struct ActionDef {
name : String
description : String
param_type : String
}pub(all) struct ActionResult {
success : Bool
message : String
}pub(all) enum Change {
PickedUp(String)
SetDown(String)
Turned(String)
Arrived
SteppedAway
}pub struct CountedState {
name : String
count : Int
total : Int
critical_threshold : Int
}pub struct DeviceState {
name : String
connected : Bool
battery_pct : Int
critical_threshold : Int
}pub(all) struct Event {
timestamp : String
actor : String
kind : String
action : String
target : String
source : String
message : String
data : String
link : String
}pub(all) struct FeedLine {
key : String
meta : String
text : String
salience : Double
}pub(all) struct NarrativeNode {
kind : String
salience : Double
text : String
children : Array[NarrativeNode]
}pub(all) struct Presence {
name : String
cadence : String
tone : () -> String
presence : () -> String
held : () -> String
state : () -> String
}pub(all) struct Register {
name : String
rules : Array[NarrativeRule]
preserves_epistemic_status : Bool
permits_spatial_drama : Bool
min_context_capacity : Int
}pub(all) enum Selector {
ByKind(String)
BySalience(Double, Double)
ByEpistemicStatus(String)
ByAge(Int, Int)
ByReaderTierMatch(String)
}pub(all) struct Slot {
label : String
detail : String
band : () -> String
}pub struct Stat {
name : String
value : Int
unit : String
warn_below : Int
critical_below : Int
}pub(all) enum Treatment {
Indent((Double) -> Int)
Border(String)
Density(String)
Case(String)
PunctuationRegister(String)
Ellipsis(String)
}pub(all) struct TreatmentApplied {
border : String
should_drift : Bool
should_isolate : Bool
}pub enum ZoomLevel {
ZoomedOut
Default
ZoomedIn
}fn being_narrative(name : String, presence : String, state : String, items : Array[(String, String, String)]) -> Stringfn control_event(name : String, actor : String, source : String, prev : String, cur : String, timestamp : String) -> Eventfn device_event(prev : DeviceState, cur : DeviceState, source : String, timestamp : String) -> Event?fn device_state(name : String, connected : Bool, battery_pct : Int, critical_threshold : Int) -> DeviceStatefn discrete_event(prev : DiscreteState, cur : DiscreteState, actor : String, source : String, timestamp : String) -> Event?fn discrete_state(name : String, current : String, narratives : Map[String, String]) -> DiscreteStatelet live = signal(true)
let (vis, narrate) = inventory([
Slot::{ label: "the presence card", detail: "building",
band: fn() { if live.get() { "active" } else { "stale" } } },
Slot::{ label: "a long transcript", detail: "settling", band: fn() { "holding" } },
])
// human sees two chips; instance reads
// "carrying 2 — in hand: the presence card (building) · within reach: a long transcript (settling)"fn level_bar_narrative(level : Double, muted : Bool) -> Stringfn[T] list_dual(container_id : String, items : () -> Array[T], key : (T) -> String, row_html : (T) -> String, row_node : (T) -> NarrativeNode) -> (DomNode, () -> NarrativeNode)fn listbox(selected : Signal[String], options : Array[(String, String)]) -> (DomNode, () -> NarrativeNode)fn meter_narrative(level : Double) -> Stringlet connected = signal(true)
let (vis, narrate) = pip(
fn() { if connected.get() { "base connected" } else { "base disconnected" } },
fn() { if connected.get() { "ok" } else { "off" } },
)
// human sees a green dot; instance reads "base connected"fn pip_narrative(label : String, tone : String) -> Stringlet here = signal(true)
let (vis, narrate) = presence_card(Presence::{
name: "Sonnet", cadence: "builder",
tone: fn() { if here.get() { "ok" } else { "idle" } },
presence: fn() { if here.get() { "here" } else { "away" } },
held: fn() { "the classifier" },
state: fn() { "into it" },
})
// human sees a lit dot + a row; instance reads "Sonnet · here · holding the classifier · into it"fn presence_narrative(name : String, presence : String, held : String, state : String) -> Stringfn salience_from_band(band : String) -> Doublefn salience_from_significance(sig : String) -> Doublefn salience_from_tone(tone : String) -> Doublefn segmented(sig : Signal[String], options : Array[(String, String)]) -> (DomNode, () -> NarrativeNode)let side = signal("ext")
let (vis, narrate) = segmented(side, [("ext", "Extensor"), ("flex", "Flexor")])
// human clicks "Flexor" → side == "flex"; narrate() == "Flexor"
// instance: side.set("ext") → the human's control moves to Extensorfn slider(id : String, label : String, sig : Signal[Double], lo : Double, hi : Double, step : Double, unit : String) -> (DomNode, () -> NarrativeNode)fn slider_narrative(value : Double, lo : Double, hi : Double, unit : String) -> Stringfn stat_banded(name : String, value : Int, unit : String, warn_below : Int, critical_below : Int) -> Statfn surface(title : String, parts : Array[(DomNode, () -> NarrativeNode)]) -> (DomNode, () -> NarrativeNode)let house = surface("the house", [presence_card(opus), presence_card(qwen)])
// dual_read(house) =>
// ═══ the house ═══
// Opus · here · laying the floor (bright: flush, reads first)
// Qwen · asleep (faint: drifted into the fog)fn toggle(sig : Signal[Bool], on_label : String, off_label : String) -> (DomNode, () -> NarrativeNode)let rec = signal(false)
let (vis, narrate) = toggle(rec, "recording", "idle")
// human clicks → rec == true; narrate() == "recording"
// instance: rec.set(false) → the switch slides off on the human's screenfn toggle_narrative(on : Bool, on_label : String, off_label : String) -> Stringfn track_control(name : String, actor : String, source : String, read : () -> String, now : () -> String, emit : (Event) -> Unit) -> Unitlet side = signal("ext")
let (vis, narrate) = segmented(side, opts)
track_control("muscle-side", "AB91", "gesture-lab",
fn() { side.get() }, now, fn(e) { sink.push(e) })
// human picks Flexor → emit { control · set · muscle-side · ext->flex }MoonBit UI where every component is readable by humans and AI equally
Dependencies