ADR-0302:
Automated TUI Geometry, Contrast, Cluster & Spin-Loop Linter
(tui_lint)
- Status: Accepted
- Date: 2026-11-28
- Scope:
plugins/tui_lint/,plugins/tui_devtools/
Context
Terminal UIs fail in subtle ways across real user environments:
low-contrast color pairings that pass on dark themes but fail WCAG
AA on light backgrounds, CJK/wide-character grapheme clusters
clipped or split at right viewport edges, overlapping non-modal
sibling widgets, off-screen focused controls, clipped approval
modals on narrow panes, and leaked timers or animation ticks that
keep waking the event loop (wait_ms != -1) while
rendered screen cells never change.
Manual visual inspection does not scale across viewport sizes,
cluster policies, and dark/light palettes, and cannot catch idle
CPU spin-loops reliably. Following ADR-0291 ("Freeze Rust, Grow in
Tenon"), we want a pure, deterministic, zero-capability Tenon
plugin that audits any tui.runtime.App or
tui.types.Screen in-memory in milliseconds with
identical behavior on both native C and tenon interp
backends.
Decision
New Pure Library Plugin
plugins/tui_lint/(capabilities = [])contrast.tn(WCAG Contrast Audit):- Implements exact sRGB linearization (via pure-
f64Newton iteration for x2.4 with zero external math dependency) and WCAG 2.1 relative luminance and contrast ratio calculation. - Resolves
tui.types.Colorvalues (0default terminal fg/bg againstdark_palette()/light_palette()orCaps.background,0x0200000024-bit RGB, and0x01000000256-color indexed palette matchingtui.present), plus SGR 7 reverse video (attrs & 16). - Audits non-decorative text spans (skipping whitespace and
Unicode box-drawing/block elements
U+2500..U+259F) against WCAG AA thresholds (>= 4.5normal text,>= 3.0bold/UI text).
- Implements exact sRGB linearization (via pure-
geometry.tn(Geometry & Cluster Audit):- Accepts an optional
vec<LintRect>({ id, role, rect, modal, focused }) designed to pair directly withtui.a11ynode rects after Wave 2 merge, with automatic fallback checks againstscreen.hits,screen.focus_order, andscreen.modal. - Flags
cursor_oob,row_overflow,cluster_clip(wide/CJK graphemes straddling the right screen edge),cluster_width_mismatch(declaredspan_cellsdisagreeing withdisplay_width_policy),rect_overlap(overlapping non-modal siblings),focus_offscreen, andmodal_clipped(clipped approval modals/dialogs).
- Accepts an optional
spin.tn(Idle-Discipline / Spin-Loop Audit):- Runs
tui.runtime.start+tickin-memory, stepping virtualInput.Clockforward up to10,000 mswith zero user input. - Flags
idle_spin_loopifwait_ms != -1persists across repeated static-screen wakeups or reaches the horizon with unchanged rendered cells, while permitting both cleanly idle apps (wait_ms == -1) and active animations whose rendered cells genuinely change.
- Runs
lib.tn(Matrix Runner & Structured JSON Reporting):- Provides
audit_app,audit_app_with, andaudit_screenacross the standard 12-cell matrix[80x24, 120x40, 48x16] x [cluster=true, false] x [dark, light]. - Serializes
LintReportandFindingtojson.lib.Value(report_to_value) and canonical JSON strings (report_to_json).
- Provides
DevTools Integration (
plugins/tui_devtools/)- Adds
tui_lintas a pure path dependency and exportsLintSummary,lint_summary,lint_summary_line,lint_overlay, andoverlay_with_lintso live TUI devtools overlays can display and export lint counts without modifying existingCounters/overlaycallers.
- Adds
Consequences
- Zero Rust compiler changes and zero runtime capabilities
(
capabilities = []). - Full dual-backend parity across native C
(
tenon test) andtenon interp. - Catches contrast regressions, CJK edge clipping, overlapping
rects, off-screen focus, clipped modals, and idle spin-loops
deterministically in
< 5 msin-memory. - Ready for Wave 2 post-merge pairing with
tui.a11yviaLintRectwithout cross-lane file conflicts.