Skip to Content
IntelligenceWhy principled stats

Intelligence Layer — Overview

Most terminal UIs are a bag of heuristics. A magic number says “coalesce resizes after 50 ms.” Another magic number says “show this hint after the user idles for 1.5 seconds.” A third says “switch to a full redraw if more than 40% of cells changed.” The numbers are plausible, the authors meant well, and the system still thrashes the moment a workload drifts off the spreadsheet that produced them.

FrankenTUI takes a different posture: every non-trivial decision inside the frame loop is cast as a statistical problem, solved with a principled estimator, and written to a JSONL evidence sink so you can re-run the decision offline. Thresholds are quantiles, schedules are optimal policies, alerts are test martingales. The numbers become consequences of the data, not tuning dials.

This page is the index to that machinery. Each linked page explains one technique, motivates it against the naive alternative, shows the math, and points at the subsystem that consumes it.

The unifying idea

Five recurring concerns drive the design of every component in this layer:

  1. Calibrated uncertainty — a TUI never has more than a few hundred samples of anything. Bayesian posteriors (Beta over rates, Normal-Normal over heights) give usable uncertainty from a handful of observations; frequentist point estimates do not.
  2. Anytime-valid testing — the runtime “peeks” at every frame. A fixed-α\alpha test breaks under repeated looks. E-processes and conformal prediction keep their guarantees under continuous monitoring.
  3. Cost-aware decisions — the cheapest rendering strategy depends on the workload. The diff, presenter, and degradation cascade all pick argmin\arg\min over an explicit cost model rather than a static rule.
  4. Bounded starvation — background effects still need to make progress. Smith’s rule with aging gives an optimal weighted-completion schedule plus a provable wait-time bound.
  5. Auditable reasoning — every decision emits a ftui-evidence-v1 JSONL record. If the palette ranked the wrong command, the evidence ledger shows exactly which Bayes factors pushed it up.

Mental model: think of FrankenTUI’s runtime as a control plant instrumented with probes. Bayesian estimators turn noisy probes into posteriors. Change detectors watch posteriors for regime shifts. Conformal layers wrap risk bounds around predictions. Control theory closes the loop on frame budget. Everything upstream writes evidence so the decisions are inspectable after the fact.

Map of techniques

Bayesian inference — what to believe

PageWhat it estimatesWhere it’s used
Command-palette ledgerP(relevantmatch evidence)P(\text{relevant}\mid\text{match evidence})widgets/command-palette
Hint rankingBeta\text{Beta} utility per keybindingHelp overlay, focus hints
Diff strategyBeta\text{Beta} change raterender/diff
Capability detectionlogit(p)\text{logit}(p) per capabilitycore/capabilities
Height predictionNormal-Normal posterior per row classwidgets/virtualized-list

Change detection — when the world shifts

PageWhat it detectsWhere it’s used
BOCPDSteady ↔ burst resize regimesruntime/overview
CUSUMMouse jitter · allocation driftHover stabilizer · budget
Alpha-investingmFDR across concurrent monitorsRuntime alert bus

Conformal prediction — calibrated risk

PageWhat it boundsWhere it’s used
Vanilla conformalResidual quantile alertsGeneric threshold gating
Mondrian conformalPer-bucket frame-time upper CIoperations/frame-budget
Rank confidenceGap-based p-value on top-kPalette tie-breaking

Cross-cutting machinery

Heuristic vs. principled — a side-by-side

// The usual story. if change_pct > 0.4 { full_redraw(); } else { dirty_row_diff(); }

One magic number. No defence when terminals get wider, scrollback gets shorter, or the workload starts drifting. Tuning drift shows up as p99 regressions weeks later.

Evidence sink — the ground truth for every decision

Every page in this section ends with a “How to debug” subsection that names the JSONL event emitted by that subsystem. The envelope is ftui-evidence-v1 and writes land in FTUI_EVIDENCE_SINK (stdout or file).

# Enable evidence to a file FTUI_EVIDENCE_SINK=/tmp/ftui.jsonl cargo run -p ftui-demo-showcase # Inspect the last 5 diff decisions: jq -c 'select(.schema=="diff_decision")' /tmp/ftui.jsonl | tail -5

See runtime/evidence-sink for the envelope schema and the full event catalog in reference/telemetry-events.

How to read this section

Start with the overview you’re on

You’re here. Skim the tables above to find the subsystem that’s bothering you or interesting to you.

Follow one page through to the evidence

Each page walks the same arc: what goes wrong naivelymental modelformulaRust interfacehow to debug. Read one end-to-end before fanning out — the sink event name gives you a scalpel for live investigation.

Every technique is anchored in a consumer. If you are debugging a resize glitch, you want BOCPD and runtime/overview. If you are tuning p99 frame time, you want Mondrian and operations/frame-budget.

Keep the math-at-a-glance table open as a cheat sheet

intelligence/math-at-a-glance is the single table that maps every technique to a one-line formula and a performance impact. Use it to orient yourself before diving into a page.

What this layer does not promise

Principled ≠ magical. A calibrated posterior tells you what the data says; it cannot invent signal that is not in the data. If your palette corpus is unrepresentative, Bayes factors will happily rank the wrong command. If your calibration window is shorter than the longest regime, conformal bounds will over-cover and then catastrophically under-cover. The evidence sink exists precisely so you can catch these cases — stare at the ledger when a decision surprises you.

Cross-references