Skip to content

[CTX-1419] feat(ui): reconcile Lua UI composition parity (#2191) - #2385

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1419/feat-ui-host-parity
Oct 21, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1419/feat-ui-host-parity

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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

Goal

Reconcile the bounded Plugin API v1 Lua UI composition surface with actual Core host behavior for #2191, implement only well-specified parity fixes, and record ambiguous parts as a design note instead of inventing vocabulary.

This PR adds no node kind, property, capability, slot, or error code.

What was audited

  • crates/bitty-lua/src/ui.rs — v1 kinds (Text/Row/Column/List), fg/bg/bold, on_click/on_scroll, per-item region, typed E_UI_COMPONENT_INVALID, and every bound (UI_MAX_DEPTH, UI_MAX_NODES, UI_MAX_TEXT_BYTES, per-generation blocks/aggregate, command/arg/token/region caps).
  • crates/bitty-runtime/src/runtime/band_host.rs, band_slots.rs, present.rs — flatten/inheritance, token resolution, bold double-strike, click/scroll/region routing, overlay paint.
  • crates/bitty-runtime/src/plugin_runtime/services.rs — mount/update gates, block registry budgets.
  • Accepted/candidate contracts: Plugin API v1 Lua Surface RFC, chrome-surface-api-candidate.md, chrome-band-contract-candidate.md, sdk/reference/ui.md.

Parity fixes in this PR

  1. Overlay style parity (the one real dropped-data defect). The overlay slot accepts the same UiNode vocabulary as a band, but paint_plugin_overlay rendered only theme defaults: fg/bg/bold were silently dropped. Overlay rows now paint per flattened run through the same closed host token table as bands (resolve_band_token), with the same synthetic bold double-strike and the same unknown-token fallback + BandHostStats::unknown_tokens counting.
    • A row with no style declaration keeps the pre-parity single-pill path byte-for-byte (same one fill and one overlay_text_glyphs call), so existing composer/palette scenes are unchanged.
    • OverlayRow/overlay_scene_rows now reuse flatten_band_runs, so the two hosted surfaces cannot disagree about inheritance.
  2. Doc-comment drift in ui.rs. ClickCommand claimed "max 128 bytes" command ids and "max 8 args" while the code enforces 64-byte ids and 16 args; corrected to reference the constants, and the module docs now name the additive style/interaction vocabulary and the overlay parity boundary.

Tests

New crates/bitty-runtime/tests/lua_ui_parity.rs (Lua table → UiNode::from_lua_value → host observation, the exact validator the bridge calls):

  • every_v1_kind_accepts_and_renders — each kind accepted; declared text/style/click/scroll/region reaches the effective span (container inheritance proven for Row/Column/List).
  • property_matrix_drop_one_fails — mutation check: dropping exactly one accepted property (fg, bg, bold, on_click, on_scroll, region) changes the host observation, so the matrix cannot pass vacuously.
  • unsupported_components_fail_typed — 26 cases: excluded/unknown kinds, malformed text/children/style/bindings/args/regions, mismatched click/scroll regions; all validation/E_UI_COMPONENT_INVALID.
  • bounds_fail_closed — exact edge accepted and one over rejected for depth (16), nodes (2048), text bytes (256 KiB).
  • slot_placement_is_exhaustive — every accepted slot maps to Band/Overlay/Unsupported; unhosted slots produce runtime/E_UI_UNAVAILABLE; statusline is not a slot.
  • click_and_scroll_route_through_commands / legacy_span_keeps_primary_button_and_args / regions_are_derived_from_painted_spans — real frame geometry → declared command; host-owned region/button/delta merged last; legacy spans keep the primary-button-only payload; foreign qualifiers denied; region rects clipped to the window.
  • hot_path_is_pure_data — flatten, region emission, and hit-testing run with no PluginRuntime/VM.
  • chrome_gestures_keep_terminal_authority — chrome click/scroll moves no focus or layout, starts no selection, and routes declared args only (no coordinates).

crates/bitty-lua/tests/ui_bridge.rs gains lua_component_carries_every_accepted_property (real Lua VM spelling → captured UiNode, plus a drop-one mutation), and present.rs gains five overlay paint tests (token resolution, bold double-strike, unknown-token fallback, unstyled multi-run fast path, styled per-run fills).

Verification

  • just fmt-check — pass.
  • just clippy (workspace, all targets, -D warnings) — pass.
  • cargo nextest run --workspace --locked — 7745 passed, 3 skipped.
  • cargo test --workspace --doc --locked — pass.
  • just scratch-paths — OK.
  • Targeted: cargo test -p bitty-lua -p bitty-runtime --locked — pass (including 11 new parity tests and 12 overlay paint tests).

Local limitation (reported, not hidden): the full just test recipe and just ci-local could not complete on this host. ci-local/act is prohibited by the task instruction; the remaining just test legs were interrupted when the shared /mnt/data filesystem hit 100% while linking workspace test binaries (concurrent agent builds), not by a test failure. Remote CI on this head is the acceptance gate for the platform/render legs.

Not in this PR — documented remainder (design note on #2191)

These are ambiguous or unaccepted contracts; guessing would widen the API:

  • Column/List inside a one-row band still flatten horizontally, while the overlay stacks direct children as rows. Multi-row band layout needs an accepted layout/thickness decision and a taller band host.
  • Overlay on_click/on_scroll are accepted and retained on the node but not routed: there is no accepted overlay hit-test/geometry contract. Click/scroll routing stays band-only.
  • Theme-token vocabulary is open: the bridge validates shape only, while the host resolves foreground, background, cursor, selection, accent and falls back on other well-formed names with a counter. Fail-closed unknown-token rejection would narrow behavior before the theme token contract is accepted.
  • tooltip and general layout/style properties (width, padding, ...) are not accepted; unknown optional fields remain tolerated for the accepted additive-minor-version rule.
  • Terminal-wide SCN-4/SCN-5 aggregation and BAND_MAX_NODES_PER_FRAME per-frame cap are not implemented; the bridge enforces the same numbers per generation as a strict subset.
  • The candidate "one surface per plugin per edge" rule is not enforced (existing documented gap).

Docs sync (plugins SDK reference, terminal-platform candidate note, bitty-manual) lands in the owning documentation repositories against the merged commit from this PR.

Refs #2191

@Xuepoo Xuepoo added feat Feature P1 Priority: high labels Oct 21, 2026
@Xuepoo Xuepoo added this to the v0.1.0 milestone Oct 21, 2026
@Xuepoo Xuepoo added area:ui Area: UI / layout area:plugins labels Oct 21, 2026
@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6194ae0a-d09c-4fca-b4fa-310096538ccd
📥 Commits

Reviewing files that changed from the base of the PR and between 27807ef and 18f116d.

📒 Files selected for processing: 4
  • crates/bitty-lua/src/ui.rs
  • crates/bitty-lua/tests/ui_bridge.rs
  • crates/bitty-runtime/src/runtime/present.rs
  • crates/bitty-runtime/tests/lua_ui_parity.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: [CTX-1419] feat(ui): honor overlay style and pin Lua UI parity matrix (#2191)

Verdict: LGTM — the overlay paint path now honors fg/bg/bold through the same closed band token table, the unstyled fast path is preserved byte-for-byte, and the new parity matrix is a real coverage increase with no contract widening.

Reviewed at 18f116d638eebfc8aa021288d359897789c00b5e (4 files, +1356/−64).

Contract checks

  • (a) slot set / registration — unchanged. UiSlot still carries exactly the accepted closed set (terminal | top | bottom | left | right | tabline | statusline | overlay) at crates/bitty-lua/src/ui.rs:68-88; the diff adds no variant, no panel registration, no provider hook (git show --stat = ui.rs, ui_bridge.rs, present.rs, lua_ui_parity.rs only).
  • (b) component kinds — no widening. UI_V1_NODE_KINDS stays ["Text","Row","Column","List"] and from_lua_value (ui.rs:648-677) still matches only those four names; nothing richer is introduced or labelled v1.
  • (c) capability gating — unchanged and not narrowed. ui_mount still gates the L2 surface on ui.rich and the overlay slot additionally on ui.overlay (crates/bitty-runtime/src/plugin_runtime/services.rs:3495-3509), and the update path keeps the ui.rich gate (:3545). The paint path stays behind set_plugin_overlay, so style painting adds no new grant surface. The doc text explicitly declines to claim overlay click/scroll routing ("not part of the accepted contract yet"), which is the right call.
  • (d) numeric limits — no invented numbers. New code adds no budgets; the parity test pins the existing constants at the boundary and one past it (UI_MAX_DEPTH, UI_MAX_NODES, UI_MAX_TEXT_BYTES). UI_MAX_NODES = 2048, UI_MAX_TEXT_BYTES = 256 KiB, UI_MAX_BLOCKS = 64, UI_MAX_AGGREGATED_TEXT_BYTES = 2 MiB all match the accepted scene limits. There is no docs diff in this PR, so nothing was asserted in prose.
  • (e) hygiene — the diff is on-topic, no debug leftovers (dbg!/println!/TODO/FIXME) in the new 934-line test file, and the removed extract_text_from_node walk has no remaining callers in the touched crate.

Non-blocking notes

  1. UI_MAX_DEPTH = 16 (crates/bitty-lua/src/ui.rs:136) is stricter than the accepted scene depth of 32. This is pre-existing and documented in the module header as a deliberate bridge-side budget, and this PR neither changes nor re-litigates it — flagging only so the disparity is not mistaken for drift introduced here.
  2. crates/bitty-lua/src/ui.rs:305-311 corrects the ClickCommand rustdoc from "max 8 args" to UI_CLICK_MAX_ARGS (= 16). The constant is unchanged, so this is a doc/const reconciliation — worth confirming that 16 (not 8) is the intended accepted value, since the old prose said otherwise.
  3. OverlayRow.runs retains command bindings that the overlay paint path deliberately does not route. That is documented in the struct comment, but a future routing change should revisit it rather than assume runs is purely stylistic.

CI (verbatim, gh pr checks 2385)

All legs pass except Windows check and test — pending; VM tier (main) and VM tier (nightly ARM64) are skipping. No failures: Analyze (actions) pass, Analyze (rust) pass, CodeQL pass, CodeRabbit pass (rate limited), Extension pin drift pass, Linux Wayland pass, Linux X11 (xvfb) pass, Supply chain (deny/audit) pass, VM tier (PR) pass, MSRV 1.85 check pass, Quality gates (1) pass, Quality gates (2) pass, macOS ARM64 check and test pass.

Per instructions I did not run cargo/just locally; the verdict rests on the diff, the gating call sites, and the reported CI state. Re-check the pending Windows leg before merge.

@Xuepoo
Xuepoo merged commit cd6b072 into main Oct 21, 2026
18 checks passed
@Xuepoo
Xuepoo deleted the ctx-1419/feat-ui-host-parity branch October 21, 2026 07:36
@Xuepoo

Xuepoo commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Independent review outcome (CTX-1419)

Verdict on the reviewed head 18f116d6: NEEDS-FIX — the parity matrix, bounds, typed rejections, click/scroll/region routing, no-VM and no-input-authority claims all hold; two overlay style defects did not. This PR merged before the fixes landed, so they ship in #2392.

Findings

  1. Fail-open chrome (blocking). A styled overlay row whose flattened runs paint no cell (empty text under bold/fg, or every span clipped away) painted nothing while the surface held keyboard capture, contradicting the CTX-1143 pill-chrome retention at present.rs:3934-3936. Probe: zero fills, where the unstyled control paints one. Fixed in [CTX-1419] fix(ui): keep overlay pill chrome and inherit root declaration (#2191) #2392 (paint_overlay_pill shared by both paths, styled_empty_overlay_row_keeps_pill_chrome).
  2. Root declaration dropped (blocking, claim vs code). overlay_scene_rows flattened each direct child of a Column/List root independently, so the root's own fg/bg/bold never reached the runs; ui.rs:16, the SDK reference, and both manual pages state "a container's declaration applies to descendant spans". Probe: run fg was None with a root fg = "accent". Fixed in [CTX-1419] fix(ui): keep overlay pill chrome and inherit root declaration (#2191) #2392 (BandInherited + flatten_band_runs_under, overlay_root_declaration_reaches_rows).

Verified good

  • Kinds/properties: Text/Row/Column/List × fg/bg/bold/on_click/on_scroll/region accepted and observed; excluded and unknown kinds, malformed text/children/style/bindings/region, and mismatched regions all fail as validation/E_UI_COMPONENT_INVALID.
  • Bounds: depth 16 / nodes 2048 / text 256 KiB at edge and one over; block, aggregate, region, queue and delta caps enforced.
  • Click/scroll/region parity: region rects derived from painted spans and clipped, region/button/delta merged last, legacy primary-button-only payload, foreign qualifiers denied.
  • Hot path: no PluginRuntime or VM in flatten/region/hit-test; chrome gestures move no focus, layout, or selection.
  • Mutation: forcing bold off in flatten_into fails every_v1_kind_accepts_and_renders and property_matrix_drop_one_fails; disabling the overlay bold branch fails bold_overlay_text_double_strikes_glyphs.

Notes

Refs #2191

Xuepoo added a commit that referenced this pull request Oct 21, 2026
…tion

Independent review of #2385 found two style defects on the overlay surface:

- A styled row whose flattened runs paint no cell (empty text under
  `bold`/`fg`, or every span clipped away) painted nothing at all, breaking
  the CTX-1143 fail-open pill chrome on a surface that holds keyboard
  capture. The unstyled path and the styled fallback now share
  `paint_overlay_pill`, so a live surface always keeps one default fill.
- `overlay_scene_rows` flattened each direct child of a `Column`/`List` root
  independently, so the root's own `fg`/`bg`/`bold`/bindings never reached
  the rows, unlike a band container declaration. `band_host` now exposes a
  crate-internal `BandInherited` snapshot and `flatten_band_runs_under`; the
  overlay flattens each row under the root's declaration, so "nearest
  declaration wins" is identical on both hosted surfaces.

No node kind, property, capability, slot, or error code is added. Regression
tests: `styled_empty_overlay_row_keeps_pill_chrome`,
`overlay_root_declaration_reaches_rows`.

Refs #2191
Xuepoo added a commit that referenced this pull request Oct 21, 2026
…tion (#2191) (#2392)

* [CTX-1419] fix(ui): keep overlay pill chrome and inherit root declaration

Independent review of #2385 found two style defects on the overlay surface:

- A styled row whose flattened runs paint no cell (empty text under
  `bold`/`fg`, or every span clipped away) painted nothing at all, breaking
  the CTX-1143 fail-open pill chrome on a surface that holds keyboard
  capture. The unstyled path and the styled fallback now share
  `paint_overlay_pill`, so a live surface always keeps one default fill.
- `overlay_scene_rows` flattened each direct child of a `Column`/`List` root
  independently, so the root's own `fg`/`bg`/`bold`/bindings never reached
  the rows, unlike a band container declaration. `band_host` now exposes a
  crate-internal `BandInherited` snapshot and `flatten_band_runs_under`; the
  overlay flattens each row under the root's declaration, so "nearest
  declaration wins" is identical on both hosted surfaces.

No node kind, property, capability, slot, or error code is added. Regression
tests: `styled_empty_overlay_row_keeps_pill_chrome`,
`overlay_root_declaration_reaches_rows`.

Refs #2191

* [CTX-1419] fix(ui): give the empty overlay pill a one-cell width (#2191)

* [CTX-1419] fix(ui): drop useless conversions, pin root binding propagation

CI `Quality gates (1)` failed on the one-cell-width follow-up with
`clippy::useless_conversion`: `CellMetrics::{width,height}` are already `u32`,
so the new pixel assertions wrapped them in `u32::from`. Drop both wrappers
and keep the assertions (the one-cell width and one-row height claims are the
point of the test).

Review nits:
- `BandInherited::layered` takes the region identity from the node's own
  declaration and falls back to the ancestor instead of recomputing it and
  discarding `own.region`.
- `overlay_root_declaration_reaches_rows` now pins the root click binding and
  region identity reaching the row run (data only; overlay routing stays
  band-only).

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

Labels

area:plugins area:ui Area: UI / layout feat Feature P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant