Skip to content

[plugins] Reconcile bounded Lua UI composition API and host parity #2191

Open

Description

@Xuepoo

Priority: P1 | Area: ui | Labels: feat,P1,area:ui | Milestone: v0.1.0 | RFC: chrome-surface-api-candidate.md / chrome-band-contract-candidate.md | Task: CTX-1299

Goal

Make Core's Lua UI host a reusable, bounded composition toolkit that lets GUI plugins such as bar, statusline, palette, and file-manager express their own layout, visual style, and interactions without Core-specific presentation branches.

Core remains responsible for surface placement/lifecycle, validation, rendering budgets, hit-testing, event delivery, capability enforcement, safe-mode/revocation fallback, and terminal-content isolation. Plugins own component composition and visual decisions.

Scope

  • Reconcile the existing Chrome Surface API and Chrome Band candidates with the implemented Plugin API v1 bitty.ui.mount/update bridge; mark normative, accepted, candidate, and deferred behavior accurately.
  • Define and implement a minimal additive Lua UI vocabulary for composable layout and styling (for example spacing/alignment/size constraints, supported theme-token styles, capsule/button/badge-like composition, and explicit interaction states) using bounded declarative data only.
  • Preserve backwards compatibility: existing unstyled Text/Row/Column/List trees retain current rendering and behavior.
  • Keep click/scroll routed through registered commands; no Lua callbacks on the render/input hot path, no raw shaders/colors, no terminal text access through UI nodes, and no capability grants from presentation data.
  • Bound node count/depth, text and aggregate payload, layout work, style resolution, update cadence, and per-frame rendering. Define fail-closed behavior for unknown styles/nodes and plugin failure/revocation.
  • Use the bar capsule UI as a dogfood consumer when the additive API is available; keep bar-owned visual choices and workspace policy in the plugin.
  • Keep the reusable extension component catalog ([0.1.0] Extension component catalog (reusable Scene building blocks) #2114) as a separate follow-up unless a small shared primitive is required to validate this API.

Acceptance criteria

  • A short API/design contract is reviewed before implementation expands beyond the minimum primitive set.
  • Tests cover old-tree compatibility, valid composition/style, invalid/unknown fields, resource limits, command capability validation, hit-testing, safe fallback, and unchanged terminal input/focus semantics.
  • Headed validation demonstrates at least one plugin-owned capsule/pill composition without Core-owned per-plugin styling.
  • Canonical terminal-platform docs are synchronized; plugin SDK/ecosystem docs record the Lua API and capability/budget boundary.
  • No performance, accessibility, or cross-platform claim exceeds measured/tested evidence.

Release scope reconciliation (2026-10-17)

The 0.0.24 release retains the existing Text/Row/Column/List vocabulary and bitty.ui.mount/update surface. New widget families, general layout/style controls, and expanded band contracts are deferred. Existing-source or mock evidence does not establish headed usability. Future work must first reconcile overlay authority, layout semantics, stacking, tokens, budgets, command bindings, and exact release-host evidence. File-manager panel/filesystem contracts remain separate. CTX-1299 is design evidence; implementation remains gated.

Tracking: CTX-1305. This issue remains open; deferred scope is not implemented or release-verified.

Activity

  1. added this to the 0.0.24 milestone on Oct 17, 2026
  2. added
    feat
    P1
    area:ui
    on Oct 17, 2026
  3. modified the milestones: 0.0.24, v0.1.0 on Oct 17, 2026
  4. changed the title [-][plugins] Expand bounded Lua UI composition API for 0.0.24[/-] [+][plugins] Reconcile bounded Lua UI composition API and host parity[/+] on Oct 17, 2026
  5. Xuepoo commented on Oct 21, 2026

    @Xuepoo
    ContributorAuthor

    Parity reconciliation note (CTX-1419, PR #2385)

    Scope: audit the bounded Plugin API v1 Lua UI surface against the actual Core host, fix only well-specified parity defects, and record everything ambiguous here instead of inventing vocabulary. No node kind, property, capability, slot, or error code is added.

    Parity matrix (current main + PR #2385)

    Surface Band (top/bottom) overlay Verdict
    Text/Row/Column/List accepted, painted accepted, painted parity
    fg/bg token painted via closed token table painted (fixed in PR #2385; previously theme defaults only) parity
    bold synthetic double-strike synthetic double-strike (fixed) parity
    on_click + args routed via registered command not routed accepted data retained, no host path
    on_scroll + delta routed, coalesced, delta merged last not routed accepted data retained, no host path
    region {id, kind} emitted from painted spans, region+button injected no geometry band-only
    Unknown/excluded node kind typed E_UI_COMPONENT_INVALID same parity
    Malformed property/type/region typed E_UI_COMPONENT_INVALID same parity
    Unknown optional field (tooltip, width, ...) ignored (forward-compatible minor rule) ignored tolerated by contract
    Unhosted slot (left/right/tabline/terminal) typed E_UI_UNAVAILABLE at mount n/a parity
    Bounds bridge cap per component/generation; terminal-wide aggregation and per-frame cap deferred same documented subset

    Evidence: crates/bitty-runtime/tests/lua_ui_parity.rs (kinds, property mutation, typed rejections, bounds, slots, click/scroll/region, no-VM, no-authority), bitty-lua ui_bridge Lua-spelling probe, and the five overlay paint tests in present.rs.

    Design-note decisions (no implementation in #2191)

    1. Column/List in bands. A band is one row, so the band host joins Column/List children horizontally; the overlay stacks direct children as rows. The same tree therefore has two layouts. Defining vertical band layout requires an accepted layout/thickness decision and a multi-row band host; this note does not pick one.
    2. Overlay interaction. on_click/on_scroll on overlay content are validated and retained, but the overlay host has no accepted hit-test/geometry or focus-routing contract. Inventing one here would widen the API and the input authority surface, so routing stays band-only.
    3. Theme-token vocabulary. The bridge validates token shape ([a-z][a-z0-9._-]{0,31}); the host resolves exactly foreground, background, cursor, selection, accent (ANSI 12, OSC-4-aware) and substitutes the span default for other well-formed names while counting a diagnostic. The candidate chrome-surface-api text says an unknown token rejects the mount; narrowing to that now would break additive-minor compatibility before the theme token contract is accepted.
    4. Tooltip and layout/style properties. Not accepted, no spelling, no implementation. tooltip, width, padding, style tables are ignored today; the accepted Rich Presentation RFC allows additive optional fields, so unknown-field tolerance is deliberate, not a parity hole.
    5. Bounds domains. Implemented: UI_MAX_NODES 2048, bridge depth 16 (accepted SCN-2 is 32), UI_MAX_TEXT_BYTES 256 KiB, 64 blocks and 2 MiB retained strings per generation. Not implemented: terminal-wide SCN-4/SCN-5 aggregation and BAND_MAX_NODES_PER_FRAME. No new ceiling is introduced by this note.
    6. Command binding budget (actual values). command id 64 bytes, at most 16 args, arg keys 64 bytes, string arg values 256 bytes; delta and region/button slots are reserved at parse time so dispatch never exceeds the arg cap.
    7. One surface per plugin per edge. The candidate rule is not enforced; several mounts from one plugin on one edge stack in mount order (existing documented gap in band_slots.rs).
    8. Headed evidence. None is claimed here. [plugins] Reconcile bounded Lua UI composition API and host parity #2191 acceptance asks for a plugin-composed capsule; this PR only proves headless parity and leaves headed dogfood evidence to the bar consumer task.

    Docs sync lands separately in bitty-plugins-docs (sdk/reference/ui.md), bitty-terminal-docs (specifications/chrome-surface-api-candidate.md), and bitty-manual (api/ui.md, EN + zh-CN), pinned to the merged commit from PR #2385.

  6. Xuepoo commented on Oct 21, 2026

    @Xuepoo
    ContributorAuthor

    Guard reconciliation (hermes-planner, 2026-10-21): PR #2385 merged as cd6b0724 and delivered the well-specified half of this reconciliation — the overlay slot now paints fg/bg/bold through the same closed host token table as bands (resolve_band_token), with the unknown-token fallback counter intact, and a Lua UI parity matrix pins the accepted v1 surface (four node kinds, ui.rich + ui.overlay gating, scene bounds) plus fail-closed boundary cases.

    What remains open here: the ambiguous parts were deliberately recorded as a design note rather than invented vocabulary (theme-token name set is open, so the bridge validates shape only; overlay click/scroll routing is not part of the accepted contract yet). Keeping this issue open for those candidates rather than closing it on a partial delivery.

    Also merged in the same window: #2360 (b10cb9e8), which is the graphics fenced-seam half of #2163; #2163 stays open by design for the blocked Core-local kitty_decode/kitty_raster removal.

  7. 1 remaining item

  8. Xuepoo commented on Nov 13, 2026

    @Xuepoo
    ContributorAuthor

    Candidate landed: panel-overlay-capability-candidate.md (bitty-plugins-docs #189, squash 9b4174f8), status: draft.

    It proposes the plugin-facing overlay verbs this issue's reconciliation needs — bitty.panel.overlay_show / overlay_hide in the existing bitty.panel.* prefix rather than a third meaning on bitty.ui.overlay.* (which is already the W-01 capture surface) — with parameter grammar, typed denials that allocate nothing, lifetime against the three accepted overlay owners, and attribution to (panel_id, generation).

    Bounds are split honestly: the 4 + 1 envelope (OverlayBusy), 128/256 text/tooltip, SCN-1..5 and RC-1/RC-2 are borrowed from their owning RFCs and cited by file; only OV-1 (1 live surface per (panel_id, generation)), OV-2 (2 per plugin generation), OV-3 (8 admissions/s), OV-4 (4096 cells requested, no axis > 256) are marked proposed.

    Two facts found while grounding it, which this issue's API reconciliation has to account for: Overlay has no tier field (crates/bitty-ui/src/panel.rs:239), so a tier parameter would be advisory until Core changes; and panel.overlay is still only a grant string (crates/bitty-plugin-host/src/capability.rs:217) with no host backend, so the verb is specified but not implemented.

    Nothing is accepted by this comment, and bitty#2476 residual 8 stays BLOCKED-ON-CONTRACT until the verb is accepted and built.

  9. Xuepoo commented on Nov 15, 2026

    @Xuepoo
    ContributorAuthor

    Landed slice (2026-11-15, #3175 → a64c283c)

    Gap established by symbol before any code was written: the bridge had slots/kinds/theme tokens/anchors/bindings, and SceneNodeStyle/SceneNode::Styled existed in bitty-rich + were painted by bitty-render, but the wire key did not exist — scene_bridge.rs said as much in its header, and the candidate record closed at "ui.rich ships no style key".

    What now ships on ui.rich (rich/terminal-slot nodes only):

    • style = { padding, radius, border, border_token }, closed key set, caps 32 / 16 / 16 cells·px, border_token from the six-name closed content-token set.
    • Lowered to SceneNode::Styled; a flat declaration lowers to nothing (byte-identical paint list), a wrapper costs one node and one depth level, and a tree already at the ceiling is refused by a new post-walk depth check.
    • Unknown key, duplicate key, oversized value, non-integer and colour-literal all take the typed E_UI_COMPONENT_INVALID path — refused with no clamp; a refused mount mounts nothing.
    • SCN-1..5, UI_MAX_* budgets unchanged. Presentation only: no terminal content, cursor, selection or scrollback path touched; no renderer handle, no per-frame Lua.

    Independent review (different agent, verdict APPROVE, no blocking findings) proved discrimination with four mutants in a scratch copy under a separate CARGO_TARGET_DIR: over-cap validation, the new depth check, wrapper node cost, and flat-style lowering each turn a named test red.

    Gates: cargo fmt / just fmt-check / clippy --all-targets -D warnings (targeted + workspace) / cargo test -p bitty-lua -p bitty-runtime / cargo +1.85 check --tests / RUSTDOCFLAGS=-D warnings cargo doc all exit 0; just ci-local not claimed (docker image store refuses a cached blob as root, act leg left to CI, which is green on all 19 non-skipping checks).

    Still open on this issue

    • Follow-ups filed as ui.rich style table follow-ups from the #3175 review (double border, latent clamp, silent no-op, docs) #3176: double border when Block.border and style.border coexist, a latent silent clamp at ui_style.rs:395, the silent no-op on the band/overlay path, and two now-false docs statements.
    • Not implemented (deliberately, out of this slice): sibling gap/spacing, cross-axis alignment, size constraints, interaction-state styling, safe-mode flattening of scene style, headed capsule dogfood.
    • Host parity: the docs reconciliation stays status: draft until the above land.
  10. Xuepoo commented on Nov 15, 2026

    @Xuepoo
    ContributorAuthor

    Landed slice (2026-11-16, #3181 → a8abf31c)

    A third slice of this issue's acceptance set landed after #3175/#3176/#3179, found and closed by symbol rather than by reading the prose.

    Defect closed. ui.state reported presented = false for a chrome band that was admitted, planned, painted and routed in a column slot (left/right). Cause: slot_state_rule still grouped Left | Right with Tabline | Terminal → SlotStateRule::NeverPresented, a leftover from before the vertical bands were hosted (#3165/#3177). presented keyed on slot identity, not content.

    Now at a8abf31c:

    • crates/bitty-runtime/src/runtime/band_slots.rs — BandVisibility covers both axes; the content gate band_is_visible is the whole rule, sound on columns because thickness = column_band_width (non-empty content implies a non-zero grantable width). tabline/terminal keep NeverPresented.
    • crates/bitty-runtime/src/plugin_runtime/services.rs — ui_block_state consumes the widened rule instead of a hardcoded presented: false, focused: false.
    • Test crates/bitty-runtime/tests/band_column_presented.rs::ui_state_reports_presented_for_a_painted_column_band — mounts Column scenes into left/right, asserts presented/focused, then the live mounts on a real Runtime (120×40): plugin_band_column_budget() == (7,3), visible_band_column(Left,0) == Some(0), (Right,0) == Some(113), one published origin per column edge. False cases held: contentless column/row bands, emptied-then-refilled band, Row into left still E_UI_COMPONENT_INVALID with no stored block.
    • Discrimination proven twice: the lane's own A/B, and independently by the reviewer (src reverted in a scratch copy with a separate target dir → same assertion red at band_column_presented.rs:248).

    Disclosed residual (unchanged by this slice). presented remains a content predicate, not a per-frame compositor grant: a band whose window gives it no columns/rows still reads true while unpainted (reproduced at 120×40 with three 30-column left bands → visible_band_column_count == 2, third band None but contentful). Making it a compositor grant needs a band-geometry source shared into PluginServices — a new surface, deliberately not taken here.

    Docs side.

    Still open against this issue's acceptance set: general layout/style controls beyond the four-key style table (spacing/alignment/size constraints), a headed capsule/pill dogfood proof, and SDK/ecosystem doc synchronization.

  11. Xuepoo commented on Nov 16, 2026

    @Xuepoo
    ContributorAuthor

    Landed slices (2026-11-16, guard tick)

    Two slices of this issue's acceptance set landed by symbol, not by reading the prose.

    Style size constraints — bitty#3186 (9ebe5285), branch ctx-1848-lua-layout.

    • crates/bitty-lua/src/ui_style.rs — style = { min_width, max_width } added to the landed four-key table (padding, radius, border, border_token). Cells on the content box (inside padding), 0 = unbounded, inclusive cap UI_STYLE_MAX_WIDTH_CELLS / SCENE_STYLE_MAX_WIDTH_CELLS reusing MAX_GRID_DIM.
    • Loud typed refusals for an unknown key, a wrong type, an over-cap value, and an inverted range (min_width > max_width) — no block is stored. gap, align, spacing, and width remain loudly refused and are pinned as such.
    • Wire: SceneNodeStyle::constrain_width → render measure/paint (including the ring-frame path). Width-only ⇒ non-flat ⇒ the existing Styled wrapper; unstyled Text/Row/Column/List trees are unchanged (SCENE_STYLE_SCHEMA_VERSION stays 2).
    • Tests: crates/bitty-runtime/tests/lua_ui_style_size.rs (13), plus lua_ui_style_vocab 15, scene_style_vocabulary 5, bitty-render scene_style_paint 20, bitty-lua --lib 302, bitty-rich --lib 335.
    • Discrimination: reverting the render measure/paint hunk → 9 passed / 4 failed at lua_ui_style_size.rs:161,186,215,239; reverting the key-accepting parse set → 4 passed / 9 failed at :160,185,214,237,256,282,319,348,364. Reproduced independently by the reviewer in its own scratch copy with a separate CARGO_TARGET_DIR (verdict APPROVE on 3a3beea3); gates green: fmt, clippy --all-targets -D warnings over five crates, cargo +1.85 check, Windows --tests, cargo doc -D warnings.

    SDK record — bitty-plugins-docs#192 (303a5cbd). New sdk/reference/ui-surface-bounds.md (document_type: reference, status: draft): the 7-slot grant map, the 4 v1 node kinds and 5 excluded ones, the enforced budgets as contract values with the owning RFC, the landed style table with the one-stroke rule and the loud-drop behavior, the command-binding surface (region/phase args, hover never captures input and never sets modal authority), and an explicit not-in-v1 list. extensibility/extension-component-catalog-candidate.md now answers its style-field open question from the landed build.

    Still open against this issue's acceptance set: gap/sibling spacing and cross-axis align (both loudly refused today; align overlaps UiAnchor and needs reconciliation), a headed capsule/pill dogfood proof, and the canonical bitty-terminal-docs candidate records that still describe the pre-#3175 style vocabulary.

    Not claiming any criterion closed: the issue stays open on those residuals.

  12. Xuepoo commented on Nov 16, 2026

    @Xuepoo
    ContributorAuthor

    Landed slice (2026-11-17, guard tick)

    One more slice of this issue's acceptance set landed by symbol, plus the review-round publish that had lost a race with a squash merge.

    Cross-axis align — bitty#3198 (9f407a37, branch ctx-1858/lua-ui-align).

    • crates/bitty-lua/src/ui_style.rs — style = { align = "start"|"center"|"end" } on Row/Column/List, placing the node's direct children on the axis their siblings do not advance, inside the node's own content box (declared width range after padding, clipped to the allocation). Closed set, byte cap, typed E_UI_COMPONENT_INVALID for a non-string, an over-cap value and an unknown spelling; no clamp.
    • UI_STYLE_FIELDS is now eight names (padding, radius, border, border_token, min_width, max_width, gap, align). A kind that places no adjacent children refuses a non-start align and accepts a declared start as the no-op.
    • start is today: ScenePaintStyle::is_inert includes SceneStyleAlign::Start, so an absent style and a declared start paint byte-identically and cost no wrapper node; a non-start align costs exactly one wrapper node and no retained string.
    • Slack is saturating_sub-derived (start = 0, center = slack/2, end = slack), so alignment can never push a child past the box its ring draws. Paint-only: measure changes only through the pre-existing gap path, ring frame unchanged, SCENE_STYLE_SCHEMA_VERSION stays 2, budgets unchanged.
    • Tests: crates/bitty-runtime/tests/lua_ui_style_align.rs (13 cases incl. column/row placement, List composing like a Column, padding+gap composition, the never-pushed-past-the-box case, start-equals-absent, wrapper cost), plus pin updates in lua_ui_gap, lua_ui_style_size, lua_ui_style_vocab, scene_style_vocabulary.
    • Discrimination: reverting the paint hunk reddens scene_style_paint.rs:710/735 and six alignment assertions; removing the key from the closed set reddens 13 of 15 and fails the bitty-lua build. Proven in a scratch copy with a separate CARGO_TARGET_DIR; the lane worktree was never mutated. Independently re-reviewed by a different agent (VERDICT: APPROVE, comment on 56581999).

    Recovery-round publish — bitty#3197 (d2cdd491). Not part of this issue's vocabulary, but it is the review round of #3193 that squash-merged before it was pushed; it lands one recovery intent = one attempt, the backoff window armed on every attempt, the success path handing the budget back, and deadline-fold coverage.

    Residual. bitty-terminal-docs specifications/lua-ui-composition-reconciliation.md still describes the style table as the four-key set (padding, radius, border, border_token) and still lists "no gap/sibling-spacing, size-constraint, or cross-axis alignment" as candidate-only. A docs sync is owed there; it is tracked separately, not by this issue's code slices.

  13. Xuepoo commented on Nov 17, 2026

    @Xuepoo
    ContributorAuthor

    Landed slice (2026-11-17, guard tick)

    Content-box height constraints — bitty#3212 (5967c233, branch ctx-1867/lua-ui-slice, task CTX-1867).

    • crates/bitty-lua/src/ui_style.rs — style = { min_height, max_height } added to the closed UI_STYLE_FIELDS table (now ten keys): content-box cells (inside padding), 0 = unbounded, inclusive cap UI_STYLE_MAX_HEIGHT_CELLS = 1000, the same bound as MAX_GRID_DIM and the width cap. A bare height / size / min_height_cells stays refused, so one concept keeps one spelling.
    • Applied on the real lowered path, not only parsed: crates/bitty-rich/src/scene.rs (SCENE_STYLE_MAX_HEIGHT_CELLS, constrain_height), crates/bitty-runtime/src/scene_bridge.rs (scene_style_of), crates/bitty-render/src/scene.rs (measure, ring frame, and the content_rows cap).
    • Typed refusals, nothing stored, no clamp: bare height/min_height_cells/size, non-integer (float/string/bool/negative/table), over-cap (… exceeds cap: 1001 > 1000), inverted range (min_height 9 > max_height 4).

    Independent review (verdict VERDICT: APPROVE, head 717f6391) proved discrimination by mutation on a scratch copy: dropping the measure application reds 4 integration + 1 render test (left: sibling on row 1, right: row 3), and neutering the ring cap reds 3 integration + 2 render tests (ring left 16 px, right 48/64 px; three lines painted vs one). MSRV 1.85 and clippy -D warnings clean.

    Residuals carried forward (not blocking): the bitty-terminal-docs / bitty-plugins-docs corpus does not yet name min_height/max_height, and per-kind coverage is Text only.

  14. Xuepoo commented on Nov 18, 2026

    @Xuepoo
    ContributorAuthor

    Residual re-verified by symbol: "per-kind coverage is Text only" is not a behaviour gap

    Guard tick 2026-11-18 re-checked the residual carried forward from CTX-1867/PR #3212. The style range is not wired per kind, so no kind can accept the declaration and ignore it:

    Stage Evidence at origin/main
    Wire parse (all kinds) crates/bitty-lua/src/ui_style.rs:279 UI_STYLE_FIELDS (ten keys), :329 UI_STYLE_MAX_HEIGHT_CELLS = 1000, :1056 with_height_range; crates/bitty-lua/src/ui_rich.rs:350-356 parses style before the kind walk
    Lowering crates/bitty-lua/src/ui_rich.rs:503 — any non-flat style becomes SceneNode::Styled { style, child }, whatever the child kind is; ui_style.rs:924-934 (is_flat) counts both height fields, so a height-only declaration is never dropped
    Bridge crates/bitty-runtime/src/scene_bridge.rs:190 with_height_range(…)
    Measure crates/bitty-render/src/scene.rs, SceneNode::Styled arm — style.constrain_height(inner.rows) is applied to the measured child extent for every kind
    Paint same file, Styled ring frame: content_rows cap (style.max_height_cells) and flow.rows bound the child's painted rows

    Empirical probe on the shipped chain (Lua reader → bridge → admission → consume_scene_present_at), probe tests since deleted: Text/Row/Column/List/Table/CodeBlock/Block all honour a cap, Rule/Image/Row/List/Column all honour a floor (the following sibling moves to the floored row), and nesting composes (Styled{floor4}{Styled{cap1}}, Row{capped Table}, Block{child: Styled(Row) cap1}). No cap failed to bound measured or painted rows.

    So the remaining gap is evidence, not behaviour: crates/bitty-runtime/tests/lua_ui_style_height.rs exercises Text, Block, Column, Row only, and any added per-kind case is green at base 3c588f26 (no pre-fix hunk to discriminate against). This tick deliberately did not ship a tests-only slice with a non-discriminating test — recording the corrected residual instead of closing it with a green-but-tautological row. Task CTX-1888 was completed with no code change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1area:uifeat

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions