Skip to content

feat(watch): passive picture-in-picture viewer with bundled noVNC - #225

Merged
ElbertePlinio merged 28 commits into
mainfrom
feat/207-pip-viewer
Oct 3, 2026
Merged

ElbertePlinio merged 28 commits into
mainfrom
feat/207-pip-viewer

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

pickforge-lab watch now opens a small live view in a browser instead of an external VNC client. A loopback bridge serves a bundled, pinned noVNC 1.7.0 page and relays a token-gated WebSocket to the session's read-only x11vnc. The window opens as a 384 px thumbnail. A click expands it and never grants control. On Hyprland with a Lua config, it floats pinned in the corner without taking focus. Frames never reach the agent.

This is the first PR for #207. It covers the passive viewer. The take-control increment stays the second PR, so this PR refs the issue instead of closing it.

Status at 0db3456

  • Reviews: Astra and Fable at xhigh, with rechecks after each repair round. No finding is open. The last Astra finding was the browser identity-write failure path. stopOwnedDaemonGroup now sends SIGKILL to group members that survive their leader. When a stop is still not confirmed, the launcher rewrites the launch record with the browser pid, so teardown keeps ownership evidence. Astra's recheck at 788dd5e found it resolved, with no new defects. The maintainer approved this final round and the merge.
  • Checks at 0db3456, after merging main with test: guard the host X display socket during test runs #237's host display guard: typecheck and lint pass; the full coverage run passed 2,615 tests with 6 skipped, coverage 87.29 / 82.19 / 87.71 / 88.28; PickCheck 0 violations in 665 functions. Each new test file passed 10 of 10 runs under CPU load with no leaked processes, sockets or locks.
  • Device pass: first run at 6412bbc, key journeys rerun at 6afd5ad, 0d1a4f9, b0e9661 and 788dd5e. Rerun logs are in rerun/ to rerun4/ beside the report.
  • Since the first version: the read-only x11vnc also runs with -nocursorshape, so the agent's pointer shows in the view. Launch is serialized with teardown. Ctrl+C cleans up at any point. Bridge reuse is verified with an authenticated status probe. Teardown never signals a process without identity evidence. The Hyprland rule pins the window to one monitor.

Minor observations from Fable with no failure shown: a record without start ticks plus later pid reuse keeps a launch unremovable; a zombie leader no longer authorizes a group signal; the SIGTERM grace before SIGKILL is 1 s.

Follow-ups: #226 (small bridge entry point), #227 (pause the stream while hidden), #228 (hyprlang adapter), #239 (agents test timeout under load). The take-control increment for #207 uses a second writable x11vnc on a private Unix socket, as recorded in the issue.

Changes from the issue design

  • Chromium on Wayland ignores --class and derives the app id from the URL host and path. Each launch therefore gets a unique path, /viewer/<launchId>, and the Hyprland rule matches it. X11 still uses --class.
  • Hyprland 0.56 with Lua rejects hyprctl keyword, so the adapter uses hyprctl eval. Lua has no rule delete, so cleanup disables the named rule; it stays registered until a config reload. Hyprlang configs get an ordinary window.
  • window.resizeTo does not resize a Hyprland window, so expand and collapse go through the bridge's window API and a compositor resize. Elsewhere the page falls back to resizeTo.
  • Each launch uses a fresh private profile, so the browser process the CLI starts owns the window.
  • The token travels in the URL fragment. It is on the viewer browser's command line, which other local processes can read. x11vnc on loopback has no password today, so this adds no new exposure to other local users.

Traceability

Evidence lives outside the repo, in ~/Artifacts/pickforge/2026-10-03/device-pass/. The QA report is manifest.html in that folder.

Requirement Verified by Scenario and edge cases Result Evidence
Bridge binds HTTP and WebSocket to 127.0.0.1 Automated test; device pass Ephemeral port; ss shows only 127.0.0.1 Pass test/security/security-viewer-bridge.test.ts; manifest.html lifecycle
Host and Origin validated Automated test; device pass Missing, duplicate, localhost, rebinding Host; foreign, duplicate, null Origin; Origin required for POST and upgrade Pass Same test file; rerun/rerun.log J13
Per-session capability token Automated test; device pass Missing, wrong, duplicate token; timing-safe compare; 0600 file in a 0700 dir; never in the bridge's argv; rotated on bridge restart; /api/status 204/401/405 Pass packages/cli/test/viewer-bridge.test.ts, security test; rerun/rerun.log
Connect only to the session's recorded VNC endpoint Automated test; device pass Identity mismatch, missing port, writable server (4002), ended session (4003); check and connect under the session VNC lock Pass packages/desktop-linux/test/viewer-state.test.ts; takeover scenario
Bundled assets only, restrictive CSP, no caching Automated test; device pass Traversal, symlink, non-allowlisted file, wrong method; CSP, no-store, nosniff, no-referrer on every response; zero CSP violations in Chromium Pass Security test; manifest.html lifecycle
Never log the token or frames Automated test; device pass Daemon log stays empty; no token= anywhere under the QA home Pass viewer-bridge.test.ts; manifest.html lifecycle
Bounded buffers, backpressure, compression off Automated test Pause and resume in both directions without polling; hard limits; text frames closed; connection cap 8; ping and pong; perMessageDeflate: false Pass viewer-bridge.test.ts
-nosel on x11vnc Automated test; device pass Read-only and writable starts Pass packages/desktop-linux/test/builders.test.ts; process args in the QA run
Passive page: viewOnly, scaleViewport, no resizeSession, no focusOnClick Device pass; harness No KeyEvent or PointerEvent reached the RFB stream; session pointer unchanged Pass manifest.html expand scenario
Thumbnail and expanded sizes; expansion consumes the click Device pass Click, Escape, Collapse; reload keeps the mode; 240 px window fits the status text Pass 02-expanded-desktop.png, rerun/r02-expanded.png
Status states Device pass Live, human control active and back, viewer stopped after the bridge died, link expired without a token Pass 05-human-control-thumbnail.png, rerun/r15-bridge-killed.png, 07-no-token-page.png
Supervised bridge survives CLI exit, stops on teardown, closes idle connections Automated test; device pass Auto-open from session create --viewer; session destroy with the window open stops browser and bridge and removes the viewer dir; idle and session-ended exit in tests Pass viewer-bridge.test.ts, viewer-state.test.ts; 16-after-teardown.png
Private profile per launch Automated test; device pass Second launch never hands off; launch dir removed after exit; dead launches pruned Pass packages/cli/test/viewer-launch.test.ts
Launcher: Chromium or Chrome app mode, Firefox fallback, URL when no browser Automated test; device pass Firefox ordinary window; no GUI prints the URL and SSH tunnel; X11 without a window manager Pass 11-firefox-fallback.png, 10-no-gui-url-in-separate-browser.png, 12-x11-expanded.png
Hyprland rule installed before launch and removed after Automated test; device pass Fake hyprctl records order, timeout, early exit, spawn failure; a fresh window with the same app id tiles after cleanup Pass packages/cli/test/viewer-hyprland.test.ts; 07-no-token-page.png
Does not automatically take focus Device pass activewindow empty after launch and after auto-open Pass 01-thumbnail-desktop.png
Session pointer visible in the view Automated test; device pass Read-only x11vnc with -nocursorshape; RFB frames change at the pointer; pointer at 1100,650 shows in the expanded view Pass packages/desktop-linux/test/viewer-cursor.test.ts; rerun3/r17-cursor-expanded.png
Interrupt and teardown races Automated test; device pass Ctrl+C during placement exits 130 and leaves nothing; launch serialized with teardown; no signal without identity evidence; pid reuse cases Pass viewer-launch.test.ts, viewer-state.test.ts; rerun3/rerun3.log
Benchmarks: idle, scrolling, animation, minimized, closed Benchmark Table below Recorded benchmark-summary.md, benchmark-results.jsonl
Docs, UNRELEASED.md, tests, typecheck, test, coverage Automated bun run typecheck, bun run lint, bun run test:coverage (2,615 passed, 6 skipped at 0db3456), PickCheck 0 violations Pass CI
Take-control increment Not in this PR Second PR Pending #207

Benchmarks

Nested Hyprland 0.56.2, 1280x800 session, Chromium 152. Percent of one CPU core, mean of three 20 s samples at 6afd5ad. "Animation" is unthrottled glxgears, a worst case. "Hidden" moves the window to a special workspace, since Hyprland has no minimize. Browser memory sums its process tree and counts shared pages more than once.

State Bridge x11vnc Browser Total Bridge out KiB/s RSS bridge / x11vnc / browser MiB
No viewer, static 0.05 0.02 0.00 0.07 0 122 / 17 / 0
Thumbnail, idle 0.10 0.30 0.30 0.70 0 100 / 17 / 1005
Thumbnail, scrolling terminal 0.47 1.83 4.13 6.43 186 101 / 18 / 1026
Thumbnail, animation 1.58 5.89 19.83 27.30 436 102 / 18 / 1129
Expanded, animation 1.43 5.97 20.46 27.87 434 103 / 18 / 1189
Hidden, animation 1.30 5.82 15.40 22.52 436 103 / 18 / 1229
Closed, animation 0.03 0.03 0.00 0.07 0 103 / 18 / 0

QA limits

The pass ran in a nested Hyprland inside a headless Sway, never on a live desktop. Page clicks and keys went through CDP input events, because that compositor has no pointer device. Hyprlang configs, KDE and GNOME were not tested.

Refs #207

Shared routes, asset resolution and typed stubs for the bridge, the
viewer state and the Hyprland adapter. Adds ws and pinned noVNC.

Refs #207
Detect a Hyprland instance with a Lua config, install a named runtime
rule that floats, pins and places the thumbnail without initial focus,
and disable it by name afterwards. applyHyprlandWindowMode finds the
launch's floating window by class pattern and pid and resizes and moves
it by client address, from the work area of its monitor.

Refs #207
Detect Chromium, Chrome or Firefox, give each launch a fresh profile,
record the launch before spawning and the browser identity right after,
and keep the Hyprland rule active only until the window maps, the
browser exits or the bounded wait ends.

Refs #207
A view-only noVNC page that fits the CSP: the token moves from the
fragment to sessionStorage, a shield catches every pointer event above
the canvas, a click expands the window through the window API, and
status text covers each bridge close code.

Refs #207
Plain watch, session create --viewer and viewer.mode auto now start the
viewer bridge and open the browser window. Without a GUI or a browser
they print the viewer URL and an SSH tunnel command. watch --control
keeps its external VNC client.

Refs #207
Copy the page and the pinned noVNC core, vendor files and license texts
into dist/viewer after each build, where resolveViewerAssets finds them.

Refs #207
test/security forbids execFile; runCommand keeps the argv array, the
timeout and the output bound.

Refs #207
The bridge serves the bundled viewer page and pinned noVNC, and relays a
token-gated WebSocket to the session's read-only x11vnc. It checks Host,
Origin and the capability token, sends a restrictive CSP and no-store, and
bounds buffers with backpressure. It reaches VNC only through a check
that holds the session VNC lock and refuses a writable server.

The detached bridge survives the CLI, records its identity in the
session, exits when idle or when the session ends, and stops on teardown
together with owned viewer browsers. x11vnc now runs with -nosel.

Refs #207
After an abnormal WebSocket close the page asks GET /api/status with its
token. 401 or 403 ends with Link expired, two failed probes in a row end
with Viewer stopped, and any other answer keeps the backoff retry.

Refs #207
Without a graphical session, watch prints only the SSH tunnel and URL
guidance. Without a browser, it adds the install hint.

Refs #207
Keep validSize within the PickCheck boolean operator limit.

Refs #207
Add the authenticated viewer status endpoint and test its request boundary.

Expand bridge and viewer state code for readability, group imports, and simplify validation and daemon startup without changing their checks.

Refs #207
Refs #207

# Conflicts:
#	docs/releases/UNRELEASED.md
The viewer bridge security tests send the published sample nonce as
Sec-WebSocket-Key. Allowlist that exact value, as the policy in
.gitleaks.toml describes.

Refs #207
Take the session VNC lock around a fresh running check, the profile,
the launch records and the spawn, so a teardown either runs first or
finds the recorded browser. Release it before the placement wait.

When the browser identity cannot be recorded, stop its group by
verified identity with escalation, and keep the launch for teardown
unless the group is confirmed gone.

Handle interrupts from before the spawn through placement and the exit
wait. The first sends SIGTERM to the browser group, the next SIGKILL.
Once the browser is gone, disable the rule, remove the launch and end
with the same signal.

Report a browser exit seen during the placement wait of an automatic
launch. Place the mapped window once on its own monitor, because the
rule used the focused monitor's reserved area.

Refs #207
Fail an automatic launch whose browser exited with an error during
placement, so watch and session create --viewer report it. When the
browser stops because the session ended, say so instead of claiming
that the session still runs.

Refs #207
Verify bridge reuse through the authenticated status endpoint.
Keep viewer profiles until their browser process groups are empty.
Skip unsafe launch entries during pruning and name teardown failures.
Report ended sessions with the correct WebSocket close code.
Support linked registry roots and paint read-only cursor pixels.
Complete protocol and signal assertions and control the idle test clock.

Refs #207
@ElbertePlinio

Copy link
Copy Markdown
Member Author

From #234: viewer-cursor.test.ts no longer touches display :0, because it now passes an explicit display. Two smaller risks remain in this test, and #234 hands them to this PR.

The random display from randomInt(1_000, 30_000) can collide with a live server. allocateDisplay from ../src/index.js respects live locks and avoids that.

Cleanup stops Xvfb with SIGKILL, which leaves a stale /tmp/.X11-unix/X<n> socket and /tmp/.X<n>-lock after every run. SIGTERM lets Xvfb remove both. Keep SIGKILL only as a fallback after a timeout.

#234 adds a test/security check that rejects -displayfd without an explicit display. The current form here passes it.

…acement

When the pid-bearing launch record cannot be written, stop the browser
through the process group this process spawned it to lead, with
stopOwnedDaemonGroup. This also works when the leader already exited and
left members behind. The launch is removed only once the group is empty.
Otherwise the error names the browser pid and says to close it by hand.

Pin the Hyprland launch rule to the focused monitor whose reserved space
it uses, and drop the post-map thumbnail placement. That placement could
land after an early expansion and shrink an expanded window.

Refs #207
Treat reused live leaders as proof that the recorded group is gone.
Stop orphaned browser members only when their arguments name the exact profile.
Retain state for unverified members and report their pids and launch id.
Apply the same identity rules to launch removal and bridge cleanup.
Cover reused leaders, orphaned members, mixed groups, and natural exits.

Refs #207
Wait for accepted requests and upstream connects after closing the bridge servers.
Keep VNC lock sentinel cleanup inside the shutdown boundary.
Use the display allocator and managed Xvfb startup in the cursor test.
Stop Xvfb with SIGTERM first and verify its socket and lock are gone.
Cover delayed connects and queued locks, and stress all four viewer test files.

Refs #207
When the pid-bearing launch record write failed and the browser group
could not be confirmed gone, the launch kept a record without a pid, so
teardown deleted the profile while the browser still ran. Retry the
record with the pid and start ticks so teardown can find the group.
Keep the manual-close error when the retry also fails.

Refs #207
Escalate group cleanup when the leader closes after SIGTERM but members remain.
Document why surviving members keep the original process group id reserved.
Cover a detached leader that exits normally and a member that ignores SIGTERM.
Confirm that the member identity and the whole group are gone before success.

Refs #207
@ElbertePlinio
ElbertePlinio merged commit 9a1e371 into main Oct 3, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the feat/207-pip-viewer branch October 3, 2026 21:10
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.

1 participant