Files
alkane-os/third-party/flare-ui/docs/live.md
T
noahandClaude Opus 4.8 c752fc6d8b third-party: re-vendor flare-ui at sprint (the most-ahead branch)
The vendored flare-ui was a Nov-4 snapshot with no recorded pin. Advance it to
the furthest-along upstream branch: blueflare/flare-ui `sprint`
(0e1f5a259faa), which is 247 commits beyond `main`, 71 beyond `next`, and
already contains `next` in full. The scattered 1-3 commit leads on individual
sp/* feature branches are unmerged side-work, not a more-ahead integration line,
so vendoring one of those would drop the 247-commit integration; `sprint` is the
single most-ahead branch.

This brings sprint's flare-ui crate additions (form.rs, page.rs, page/, table.rs
and the flare-ui-axum / flare-plugin-host crates) into the tree. Record the pin
in flare-ui.lock so the next re-vendor is reproducible.

alkane-os builds against it with no source changes: the console (console.rs) and
the rest compile clean, clippy -D warnings is clean, and 183 lib + integration
tests pass (including the dashboard schema tests, so the wschema model stayed
compatible). Re-verified the live console on sprint: --serve-sim boots, the
flare-ui shell and control pages render, and stop -> ambient:18000 -> start all
succeed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BdKQBPjAXpCwmigUov5eQk
2026-11-10 20:19:12 -06:00

5.8 KiB

Live client

The named page client consumes canonical HTML events and snapshot resync. It is a separate explicit protocol from the JSON reading client described below; a page opens only one of them.

crates/flare-ui/assets/js/live.js (embedded as flare_ui::live::LIVE_JS).

Setting Default Meaning
ringCap 600 samples kept per series; oldest overwritten
maxSeries 64 series per stream; further keys are counted in dropped
staleAfterMs 15000 silence before the stream is marked stale
backoffMinMs / backoffMaxMs 1000 / 30000 reconnect delay doubles up to the cap; reset on open

Payload per SSE message: JSON {"k": key, "v": value, "t": ms} or an array of those. Malformed items are dropped and counted. bindStaleMarker(live, document) marks [data-live] elements immediately and toggles bf-stale as the stream changes. Rejected packets leave the freshness timestamp, watchdog and readings unchanged. A valid appended sample clears stale state.

Tests: node --test crates/flare-ui/tests/js/live.test.js, also run by cargo test when node is installed.

Islands and page assets

assets/js/islands.js (flare_ui::assets::ISLANDS_JS): table sort kept in the URL (sort, dir; both are in the closed query set) and column width clamp (40 to 800 px). th[data-sort] cells navigate to the toggled query.

flare_ui::assets::PageAssets renders head tags (styles, then deferred scripts). lint rejects, on plain HTTP only: more than 5 SSE streams per page (browsers allow 6 connections per origin; one stays free), and scripts that use secure-context-only APIs (crypto.subtle, navigator.clipboard, serviceWorker, mediaDevices, geolocation).

Typed charts

flare_ui::chart::Chart builds the D63 island. props() validates and returns the data contract; render(path) escapes it into data-chart, adds the canvas and emits normal ?tier=min, ?tier=hour and ?tier=day links. The canonical page path must start with one slash and contain no query, fragment, backslash or control character.

Prop Meaning
id Chart identity, also carried by its live events
series Up to 64 unique key, label, unit and hexadecimal RGB color definitions
tiers min, hour, day, each with n:60 and a positive step_s
tier Selected tier
points Selected-tier seed samples by key: oldest-first [timestamp_ms, value] pairs, at most 60 per series

Keys must belong to a declared series. Samples must be finite with strictly increasing timestamps. Empty or missing histories are valid. Invalid props return flare_ui::chart::Error; labels and units are rendered as text.

use std::collections::BTreeMap;
use flare_ui::chart::{Chart, Series, Tier, TierSpec};

let chart = Chart {
    id: "traffic".into(),
    label: "Network traffic".into(),
    series: vec![Series {
        key: "rx".into(), label: "Receive".into(),
        unit: "B/s".into(), color: "#3776BE".into(),
    }],
    tiers: [
        TierSpec { n: 60, step_s: 60 },
        TierSpec { n: 60, step_s: 3600 },
        TierSpec { n: 60, step_s: 86400 },
    ],
    tier: Tier::Min,
    points: BTreeMap::from([("rx".into(), vec![(1000.0, 42.0)])]),
};
let html = chart.render("/network/traffic");

The server emits a bf-vh latest-values table for assistive technology and JavaScript-free reading. It stays outside the visible chart. Empty histories display -- with the unit. Tier links work without JavaScript.

Named SSE events append points to their chart and series:

event: series
data: {"id":"traffic","key":"rx","p":[2000,43]}

Live keeps these rings separate from legacy reading keys and other chart identities. They share the stream's maxSeries limit. The binding merges seed and live samples by timestamp, keeps the newest 60 and updates the accessible values. Exact numeric formatting uses up to 3 decimals and rounds exact ties away from zero. Structured reading values display --.

The retained canvas engine handles geometry and sliding. The adapter scales extreme finite magnitudes before painting and keeps raw values in the table. Stale data and histories shorter than 4 samples draw without sliding so seed points remain visible. Reduced motion also disables sliding. Normal motion resumes when the data is fresh and every nonempty series has enough history.

Reading glue

assets/js/chart.js (flare_ui::assets::CHART_JS): bindCharts(live, document) also supports legacy [data-island="chart"][data-key] canvases. On each data event it writes the latest value into matching [data-live][data-key] readings (.bf-kv-value keeps its units, .bf-hero-value, meter). Non-numeric samples are not plotted. Pure helpers (bounds, plotPoints, formatValue, withValue) are covered by crates/flare-ui/tests/js/chart.test.js.

Browser check

scripts/e2e/live-sse.mjs runs headless Chromium against a stub SSE server: readings update, the chart canvas draws, a dropped stream marks readings stale, and a reconnect clears the marker. Set PLAYWRIGHT_DIR to a directory whose node_modules holds Playwright; without it the script skips. The check found that timers must run unbound (issue #17).

Page glue

assets/js/boot.js (flare_ui::assets::BOOT_JS) runs on DOMContentLoaded and wires the page from optional meta tags:

Meta name Effect
bf-stream Path-absolute SSE URL. Opens the stream, binds the stale marker and chart islands. Protocol-relative, absolute, backslash and unescaped whitespace/control URLs are ignored.
bf-csrf Token sent as X-CSRF-Token on every htmx request (htmx:configRequest).
bf-live-protocol page selects the named page client and disables legacy stream startup.

Table sort binds regardless. Load order: live.js, chart.js, islands.js, boot.js (all deferred). Tests: crates/flare-ui/tests/js/boot.test.js.