Skip to content

feat(viewer): watch a lab session in a native picture-in-picture window - #349

Merged
ElbertePlinio merged 16 commits into
mainfrom
feat/340-native-viewer
Oct 28, 2026
Merged

ElbertePlinio merged 16 commits into
mainfrom
feat/340-native-viewer

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

The #207 viewer shows a lab session through x11vnc, a loopback bridge and noVNC in a Chromium window. It costs a browser per window and depends on VNC, so it is a poor base for a picture-in-picture view the user keeps open while an agent works.

This adds pickforge-viewer, a small Rust binary that reads the session's own Xvfb directly with MIT-SHM, DAMAGE and XFIXES and draws it in a native window (winit, softbuffer, swash). A detached TypeScript host supervises it over stdio JSON lines and exposes a private socket with status, expand, collapse and shutdown only. pickforge-lab watch and viewer.mode: "auto" use it when a matching binary is installed and a graphical session exists, and fall back to the noVNC viewer otherwise, including when the native viewer fails to start. The viewer is watch only; control comes in #341. Releases now ship the binary as a separate Linux x86_64 asset with a checksum, and the installer installs it, as approved by the owner.

Closes #340

Requirement Verified by Scenario Result Evidence
Native window on Wayland and X11, reading the Xvfb directly Rust tests, live viewer test, manual QA Nested Xvfb host (X11 backend); owner's Hyprland desktop (Wayland backend); own-display refusal; Xvfb identity mismatch at launch and after Session shown with no VNC, bridge or browser; refusals exit with the documented codes crates/pickforge-viewer tests, native-viewer-live.test.ts, QA notes
Damage-driven SHM capture, idle near zero, pause when hidden Rust tests, benchmark Idle session; unmap, remap and iconic state on X11; frame-callback pause on Wayland; SHM failure fallback with detach; fetch error keeps the damaged area Idle 0.53% CPU; capture pauses and resumes with a full fetch capture_tests.rs, app_tests.rs, benchmark below
Aspect-preserving scaling and a visible cursor Rust tests, screenshots Scaler goldens; cursor shape change without movement; cursor removal Letterboxed image; cursor repainted on every change --self-test, app_tests.rs, QA screenshots
Thumbnail pinned bottom-right on Hyprland without focus; click expands; Fullscreen and Collapse; status text Live Hyprland check, unit tests, manual QA 384x240 at 24 px from the corner; active window unchanged; expand to 1280x832 at 1:1; three expand and collapse cycles; owner clicked thumbnail, Fullscreen, Esc twice and Close on Wayland; "Session ended" after the Xvfb dies; expand capped on a smaller screen without Hyprland All as specified; the window stays opaque when the compositor dims windows viewer-hyprland.test.ts, native-viewer.test.ts, QA notes
Watch only Tests Socket ops other than status, expand, collapse and shutdown; input, grant and takeover ops Refused as unknown operations; the viewer opens no input path native-viewer.test.ts
watch and viewer.mode: "auto" prefer native, else noVNC Tests, manual QA Matching binary; missing binary; version mismatch; no window system (DISPLAY=:999); stale readiness with and without a launch record; concurrent stop and start Native when usable; otherwise the reason on stderr and the noVNC path; stale state never blocks the next launch watch.test.ts, native-viewer.test.ts, QA notes
CPU against noVNC, recorded here scripts/lab/viewer-bench.mjs on the owner's Hyprland desktop 30 s per phase, both thumbnails visible side by side, 1280x800 sessions See the table below Local run
Release asset and installer Tests, CI candidates Candidate build packs the binary; the installer verifies its checksum and version and installs it next to pickforge; npm-only installs keep the fallback Pass installer.test.ts, candidate jobs
Tests and docs Repo checks Rust fmt, clippy (also for Windows), tests; typecheck, lint, coverage, build, PickCheck Pass: 3,214 tests, lines 89.6%; live viewer test passed; PickCheck 0 violations in 643 functions TypeScript run at a564cfe; Rust fmt, clippy on Rust 1.99 for Linux and Windows, and tests at bd9d990, which changes only Rust

CPU use, with the noVNC figure covering Chromium, the bridge and x11vnc:

Phase Native noVNC
Idle 0.53% 1.03%
Scrolling 1.26% 2.43%
Text animation 3.46% 17.88%

QA pass: I drove the built CLI and the release binary on nested Xvfb displays, then on the owner's Hyprland desktop with their approval. The live check found that Omarchy dims every window, so the PiP showed the desktop through it. A per-launch opacity rule now keeps both viewer windows opaque until the viewer exits. Once, before that fix was rebuilt, the window sat off screen and expand failed. A fresh launch and three cycles did not reproduce it.

The viewer renders text with swash instead of fontdue, because fontdue depends on ttf-parser, which RUSTSEC-2026-0192 marks unmaintained. Swash adds about 1.6 MB to the stripped binary, which is now 5.0 MB.

Declined: backoff for a GetImage failure that persists on the same area. Lab displays have a fixed size, so it needs a failing X server.

PickCheck has no grammar for shell, so scripts/install.sh and scripts/candidate-smoke.sh were not measured.

Follow-up: #348, the --gaia-url bar in browser sessions, seen during this QA.

Rollback: revert this PR. watch and viewer.mode: "auto" go back to the noVNC viewer, and the release stops shipping the binary.

Council review, 3 rounds:

Delegate Round 1 Round 2 Round 3
GPT-6 Astra 7/10 8/10 9/10
Fable 5.1 8/10 8/10 not run
Kimi K3.1 Pro 8/10 10/10 not run

After the council, Astra reviewed the opacity rule from the live check. It found that a viewer browser that exits on its own left the rule enabled. The rule is now disabled when the browser exits, with tests for an early exit and an interrupt. Astra's recheck approved the fix at 10/10.

Add pickforge-viewer, a Linux binary that shows one lab session in a
native window and speaks the stdio protocol in PROTOCOL.md.

- Capture the session Xvfb through /tmp/.X11-unix with empty auth:
  MIT-SHM fetches of the DAMAGE bounding box with a GetImage fallback,
  at most one fetch per 16 ms, XFIXES cursor image and XInput 2 motion.
- Scale with area averaging down and bilinear up, recompute only dirty
  rows, letterbox, and composite the cursor in the window.
- Draw a frameless winit and softbuffer window: a 384 px thumbnail that
  expands on click, a 32 px bar with Fullscreen, Collapse and Close,
  and a status pill. Honor --placement host|self and the scale factor.
- Pause capture while the window is occluded, minimized or, on Wayland,
  gets no frame callbacks. End the session on X EOF, a changed Xvfb
  start time or the host sessionEnded command.
- Embed Geist Medium under the SIL Open Font License 1.1.
- Test the protocol, scaler goldens, layout math and arguments without
  a display, capture against Xvfb, and the real window on a second Xvfb.
# Conflicts:
#	Cargo.lock
#	docs/releases/UNRELEASED.md
@ElbertePlinio
ElbertePlinio merged commit 5268e26 into main Oct 28, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the feat/340-native-viewer branch October 28, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

watch: native Rust picture-in-picture viewer

1 participant