Skip to content

[ui] Presentation-only overlay session: draw above the view without input capture #2849

Closed

Description

@Xuepoo

Priority: P2 | Area: ui | Labels: feat,P2,area:ui,area:architecture | Milestone: v0.1.0 | RFC: ADR-0014 / OQ-056 | Task: TBD

Core mechanism gap found while splitting the help/which-key presentation out of Core (bitty#2397, bitty#2408, upstream bitty-terminal/bitty-plugins#122).

Problem

The only overlay a plugin can mount today is the overlay slot plus bitty.ui.overlay.acquire, and that surface is exclusive, focusable and input-capturing by contract (crates/bitty-lua/src/host.rs: "Claim the Core-owned exclusive focusable-overlay input capture for one transient interaction"; a second acquire fails closed with E_UI_ALREADY_CAPTURED).

A help/which-key surface is the opposite: it is non-modal, must not take focus or capture input, must follow the focused view, and must dismiss on Esc without consuming the press unless a real confirmation gate also coincides. Expressing it through the capture overlay would either take input authority a help panel must not hold, or require a private Core channel - exactly what the ownership split exists to prevent.

Nothing in bitty-runtime/bitty-lua draws a plugin scene above the focused view without a capture session today (grep for presentation-only finds only config chrome).

Required mechanism (Core)

  • A presentation-only overlay session a granted plugin can mount into: drawn above the focused view's content, bounded to the view rectangle, clipped, and stacked deterministically with chrome bands.
  • No input capture: the session never receives key/mouse events, never takes focus, and never changes the focus ring. The only observation it gets is the dismiss edge it asks for (for example "the user pressed Esc / the view lost focus"), delivered as an event, not as a consumed press.
  • Focus-follow: the surface tracks the focused view and disappears (or reports a bounded unavailable state) when that view closes; unload/revoke tears it down with no residue.
  • Bounded resource profile: at most one presentation overlay per view per generation, bounded rows/bytes, render budget accounted like a chrome band, and no terminal-content reads.
  • Capability spelling that separates "draw above the view" from "capture input": the existing ui.overlay grant stays capture-only; the presentation surface needs its own name (for example ui.present) so a manifest cannot gain capture by asking to draw.
  • Safe mode: no presentation overlay when plugins are disabled; a revoked generation drops its surface on the next present.

Acceptance criteria

  • A bounded Lua API for the session plus the dismiss/observed-edge event, documented in the plugin API reference and the manual.
  • Headless tests: draw above the focused view, clipping at the view rectangle, Esc dismissal without consuming the press, no focus change, focus-follow on view close, unload/revoke teardown, safe-mode absence.
  • An independent security review records that the surface cannot read terminal content, cannot capture input, and cannot outlive its generation.
  • bitty.ui.overlay.* behaviour and its E_UI_ALREADY_CAPTURED contract unchanged.

Why this is Core

Placement, stacking, budgets, hit-testing, capability enforcement and teardown are Core mechanism per ADR-0014. What the surface shows stays with the plugin; this issue does not decide any help-panel content or styling.

Activity

  1. added this to the v0.1.0 milestone on Nov 1, 2026
  2. added
    feat
    area:ui
    P2
    on Nov 1, 2026
  3. Xuepoo commented on Nov 1, 2026

    @Xuepoo
    ContributorAuthor

    Cross-links: parent ownership split bitty#2397, plugin half bitty-terminal/bitty-plugins#122, composition umbrella bitty#2191. The Core-drawn help panel and its toggle_help chrome action stay in place until the plugin reproduces the parity matrix over this session.

  4. Xuepoo commented on Nov 3, 2026

    @Xuepoo
    ContributorAuthor

    Independent review by agent-reviewer (cron guard tick), 2026-11-03

    Read-only review of origin/main @ 8108e4f7 (squash of #2856) in a detached worktree; no code or branch was modified. Docs checked in the canonical repos at their current main (bitty-plugins-docs #182 merged 2026-11-03T11:33:21Z, bitty-manual #108 merged 2026-11-03). This tick had no compositor access, so paint behaviour is verified from the headless test harness and code paths, not a live window.

    Criteria

    # Criterion (from #2849) Verdict Evidence
    1 Bounded Lua API for the session plus the dismiss/observed-edge event, documented in the plugin API reference and the manual PASS API: bitty.ui.present is a read-only table with exactly show/hide — crates/bitty-lua/src/host.rs:6439-6494 (no acquire/poll/register, no callback). Both verbs route to the same Core session as the CTX-1431 bitty.ui.overlay.show/hide spelling (host.rs:6332-6428). Dismiss edge is an accepted event kind overlay.dismissed (crates/bitty-plugin-host/src/event.rs:235-237,268-270), payload is exactly {owner, handle, reason} (crates/bitty-terminal/src/terminal_app.rs:2666-2679). Reference: bitty-plugins-docs/sdk/reference/ui.md:323 (§Presentation-only overlay (ui.present)), errors :363, observation :386. Manual: bitty-manual/en/api/ui.md:272 (§Presentation-Only Overlay) and :350 (§Dismissal observation); the zh-CN/api/ui.md page was not updated (see gaps).
    2 Headless tests: draw above the focused view, clipping at the view rect, Esc dismissal without consuming the press, no focus change, focus-follow on view close, unload/revoke teardown, safe-mode absence PASS All seven exist and pass locally. Draw/center: crates/bitty-runtime/src/runtime/present.rs:8617 (+ paint order :3087-3092). Clipping to the frame: present.rs:8948 (clip rect built from frame.content at :5857-5871). Esc without consume: crates/bitty-terminal/src/tests.rs:17351 (asserts intercept_chrome_key returns false and 0x1b reaches the PTY). No focus change: present.rs:9063. Focus-follow on view close: tests.rs:17437 + unit tests presentation_overlay.rs:482-535. Unload/revoke teardown: crates/bitty-runtime/tests/presentation_overlay_api.rs:397, tests.rs:17547. Safe-mode absence: presentation_overlay_api.rs:513. Row/byte budgets: present.rs:8989,9019. Lua round trip: crates/bitty-lua/tests/ui_bridge.rs:769.
    3 Independent security review records that the surface cannot read terminal content, cannot capture input, and cannot outlive its generation PARTIAL Substance is true and I record it below from code, but the required artifact does not exist. The implementation record itself still says it is pending: specifications/presentation-overlay-session-ctx-1673-evidence.md:102-105 ("Independent security review is pending … does not self-certify them"), and the PR body leaves the same box unchecked. No ui.present security-review record exists in bitty, bitty-plugins-docs, bitty-manual, or bitty-terminal-docs (code search + tree reads). Missing artifact: a committed security-review record (e.g. specifications/security-review-presentation-overlay-ctx-1673.md or a bitty-docs review) by a non-author covering the three properties and the residual risks; a comment alone is not the record this criterion asks for.
    4 bitty.ui.overlay.* behaviour and its E_UI_ALREADY_CAPTURED contract unchanged PARTIAL Capture contract is untouched: plugin_runtime/overlay.rs is not in the diff and E_UI_ALREADY_CAPTURED is still raised at overlay.rs:214 (overlay.rs:193-215); cargo test -p bitty-runtime --test plugin_ui overlay_capture_is_single_owner_and_release_is_idempotent passes. But one bitty.ui.overlay.* verb changed behaviour: bitty.ui.overlay.show was gated on ui.rich + ui.overlay before this commit (f0a6d252:crates/bitty-runtime/src/plugin_runtime/services.rs:2741-2760) and is now gated on ui.present alone (crates/bitty-runtime/src/plugin_runtime/services.rs:2750-2759). A manifest holding only the old mount grants now gets E_CAPABILITY_DENIED ui.present; that is asserted as intended by presentation_overlay_api.rs:293-330. hide is unchanged (ungated/idempotent). The re-gate is coherent with the capability split and is unreleased (v0.0.31 does not contain f0a6d252, so no shipped plugin breaks), but it is literally a behaviour change to bitty.ui.overlay.show and it left two stale doc comments (below).

    Specific checks requested by the guard tick

    Check Verdict Evidence
    ui.present is its own capability head; cannot imply or be implied by ui.overlay / ui.overlay.focus PASS Closed head listed separately in both validators: crates/bitty-plugin-host/src/capability.rs:151-162, crates/bitty-package/src/manifest.rs:352-359 (three-way head-equality test capability.rs:1148-1160 passes). Grant resolution is an exact string compare, no expansion: crates/bitty-runtime/src/plugin_runtime/mod.rs:2770-2772, consumed as present at :2897. Draw gate requires only ui.present (services.rs:2757); mount gate still requires ui.rich (+ ui.overlay for the overlay slot) and is untouched (services.rs:4772-4776). Cross-grant denial is pinned by presentation_overlay_api.rs:289-347 (ui.rich+ui.overlay never imply ui.present; ui.present draws with no ui.overlay.focus).
    ui.overlay's E_UI_ALREADY_CAPTURED single-owner contract untouched PASS overlay.rs unmodified by #2856 (git diff --stat f0a6d252..8108e4f7 touches only host.rs and services.rs of this area). Single-owner refusal at overlay.rs:193-215; const at bitty-lua/src/host.rs:935; test passes. Presentation admits into its own OverlayManager (presentation_overlay.rs:105-113,160-176), so it cannot consume or steal the capture owner's slot.
    Revoked/suspended/unloaded generation cannot keep painting; admit slot released PASS (one-frame caveat) Suspend revokes: plugin_runtime/mod.rs:3335-3338; dispose/unload/crash: :3453-3456; failed activation rollback: :4445-4447. Revoke funnels through clear() which dismisses the admitted slot: presentation_overlay.rs:200-209,355-360. Paint content is re-resolved per tick from the live generation's retained blocks, so a revoked generation yields None: mod.rs:1920-1940 + terminal_app.rs:2782-2790. Esc clears the paint copy synchronously (terminal_app.rs:2622-2632). Caveat: suspend/dispose detected on the cold path can leave the cloned Runtime surface painted for at most one frame until the next update_plugin_overlay; session state and slot are already gone.
    Safe mode refuses admission before admission PASS require_presentation_overlay checks safe_mode first and returns E_UI_UNAVAILABLE before the grant check and before PresentationOverlay::show is called (services.rs:2750-2759; call order in ui_overlay_show_with_expiry services.rs:5120-5154). The flag is set on the generation at build time (mod.rs:2903). Note the test only exercises the "no generation admitted in safe mode" path (presentation_overlay_api.rs:513-540); the in-gate branch itself has no direct test.

    Verification actually run in the review worktree

    cargo test -p bitty-runtime --test presentation_overlay_api      -> 7 passed
    cargo test -p bitty-runtime --lib presentation_overlay           -> 19 passed
    cargo test --bin bitty presentation_overlay                      -> 4 passed
    cargo test -p bitty-lua --test ui_bridge present_namespace       -> 1 passed
    cargo test -p bitty-runtime --test plugin_ui overlay_capture_is_single_owner_and_release_is_idempotent -> 1 passed
    cargo test -p bitty-plugin-host --lib capability                 -> 37 passed
    

    PR #2856's own CI at 8108e4f7 is green on Linux X11/Wayland, macOS, Windows, MSRV, CodeQL and supply chain.

    Residual risks and gaps

    1. Missing security-review artifact (blocking, criterion 3). specifications/presentation-overlay-session-ctx-1673-evidence.md:102-105 still lists it as pending; nothing in the four doc repos supersedes it.
    2. bitty.ui.overlay.show re-gate (criterion 4). The grant moved from ui.rich+ui.overlay to ui.present; if the intent was literal "unchanged", this needs an explicit scope decision in the issue (or a compatibility alias that still accepts the old grants, which would weaken the split).
    3. Stale in-code docs contradict the new gate. crates/bitty-lua/src/host.rs:1989-1992 still says the caller "must hold ui.rich and ui.overlay"; crates/bitty-runtime/src/plugin_runtime/presentation_overlay.rs:11-14 still says "It needs only the v1 ui.rich + ui.overlay grants". DismissedEvent docs also say the reason is "escape" today (presentation_overlay.rs:60-64) although view-closed exists.
    4. Esc observation cannot leak input bytes. The payload is {owner, handle, reason} only (terminal_app.rs:2672-2676); no key code, text, modifiers, or coordinates. The Esc itself still reaches the focused PTY by design (tests.rs:17386-17390) — that is normal routing, not a plugin-visible leak. A plugin that also wants raw keys still needs a separate terminal.input.* grant.
    5. Paint path cannot read terminal content into plugin space. It renders the plugin's own mounted UiNode (present.rs:5739), and the dismiss payload carries no content. It does touch Core's layers.combined_glyphs to occlude underlay glyphs inside the card (present.rs:5897-5904) — Core-only geometry used to hide text under the card, never exposed to the plugin.
    6. One-frame ghost after cold-path revoke. Session and slot drop immediately, but the Runtime paint copy clears on the next tick (terminal_app.rs:2764-2790); the unload test only asserts clearance after a drive_tick (tests.rs:17547-17596).
    7. Workspace switch can be reported as view-closed. Runtime::is_live_view checks only the active layout, pinned leaves and floats (runtime/layout_focus.rs:3060-3064); observe_focus tests liveness before re-binding (presentation_overlay.rs:236-260), so switching to another workspace can dismiss a panel whose view still exists in an inactive workspace, with the view-closed reason.
    8. Z-order is asserted by call order, not by a test. present.rs:3087-3092 paints chrome bands → presentation → capture modal, but no test builds all three layers and asserts stacking; the "draw above the focused view" tests assert placement/layer membership only.
    9. Budget accounting is local. The presentation session's OverlayManager is its own instance (presentation_overlay.rs:105-113), so "consumes one non-modal slot under MAX_OVERLAYS_PER_WINDOW" does not bound overlays held by the window's live manager.
    10. zh-CN manual page not updated (bitty-manual/zh-CN/api/ui.md has no ui.present section; the English page does).

    Verdict

    NOT READY TO CLOSE — mechanism and tests are sound (criteria 1-2 and both capability-split/revoke checks PASS), but the required independent security-review record is still missing (criterion 3 PARTIAL) and bitty.ui.overlay.show's required grant changed (criterion 4 PARTIAL).

  5. Xuepoo commented on Nov 3, 2026

    @Xuepoo
    ContributorAuthor

    Closed by the CTX-1677 closeout wave.

    • Mechanism: bitty.ui.present (show/hide, read-only table) draws above the focused view's content, clipped to the view rectangle, OverlayKind::NonModal on OverlayTier::Popup, never hit-tested, never takes focus; the dismiss edge is delivered as overlay.dismissed {owner, handle, reason} instead of a consumed press — bitty PR [CTX-1673] feat(runtime,lua): presentation-only overlay session with ui.present (bitty#2849) #2856, closeout PR [CTX-1677] fix(runtime,lua): close the ui.present acceptance gaps (bitty#2849) #2857 (squash 7ac871d4).
    • Headless coverage in the tree: draw/center + paint order (crates/bitty-runtime/src/runtime/present.rs), clipping, Esc-without-consume (crates/bitty-terminal/src/tests.rs), no focus change, focus-follow on view close, unload/revoke teardown, safe-mode absence, and the four-grant-shape gate test (crates/bitty-runtime/tests/presentation_overlay_api.rs).
    • Independent security review recorded: bitty-terminal-docs security/audits/presentation-overlay-2026-11.md (PR [CTX-0214] feat(rich): streaming kitty chunked intake with 320MB ledger #376) records properties 1–3 (no terminal-content read, no input capture, cannot outlive its generation) against 8108e4f7.
    • bitty.ui.overlay.* and its E_UI_ALREADY_CAPTURED contract are unchanged; ui.overlay stays capture-only and ui.present neither implies nor is implied by ui.overlay.focus.

    Follow-up tracked elsewhere: help/which-key consuming surfaces stay with #2397 / #2408.

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

    P2area:architecturearea:uifeat

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions