HermenixandClaude Opus 5 b4abd085cc test(stream): both ends of live.sock, the broker's verbs, and a real viewer in a guest
Three layers, because the stream has three and each one can be wrong on its own.

`tests/live/test_live_control.py` (20 tests) runs `Control` against a fake
capture: the four ops, `attach` idempotent on the phrase, the same phrase aimed
at another output refused, a malformed phrase refused *without the value in the
message*, and `fps` defaulting to the daemon's when the broker sends none.

`tests/sessions/unit/test_stream_verbs.py` (24 tests) runs the broker against a
fake daemon, and its subjects are the decisions rather than the plumbing: no
container output is a refusal and never a fallback to the main output; a
re-`enable` returns the same phrase and a different one is exit 8; a down daemon
turns `attached` false rather than failing a read; the sweep touches a watched
session and leaves an unwatched one alone; teardown detaches before the
container is destroyed.

`tests/unit/test_mcp_*` grow the two tools, the two resources and the three
`session_start` arguments, with the read-only half asserted *absent* as a tool
by name -- re-adding one should be a failure, not a silent widening.

`checks/vm-stream.nix` is the new guest check, and it exists for the two things
none of the above can say:

1. **That `grim` captures a real compositor from inside a unit.** It reads
   actual JPEGs off `/<phrase>/stream.mjpg` with `checks/lib/mjpeg_read.py`, a
   hand-rolled multipart reader that shares no code with the server -- a parser
   that did could not tell you the boundary was wrong. It framed on SOI/EOI
   rather than `Content-Length` for the same reason. This is what caught the
   unit's missing `XDG_RUNTIME_DIR`: `frames: [25827, 25827, 25827]` now, ten
   capture failures and a stream that gave up before.
2. **That a connected viewer moves the idle clock.** That needs the broker's
   real sweep, on a real timer, with a client genuinely still there a minute
   later -- hence `--hold`, and hence a check that spends ~90 seconds twice. The
   negative control runs first, because if the sweep touched an unwatched stream
   the positive case would pass for the wrong reason. Measured in the guest:
   with nobody watching `580s -> 502s` remaining, with a viewer `499s -> 596s`.

It also asserts the phrase is in neither the audit log nor a 404 body, that the
old URL stops serving after `disable`, that `disable` then `enable` rotates it,
that `kill` takes the stream down and leaves the daemon up, and that
`start --stream` yields an id and a URL that serves frames.

No clock is injected anywhere in this check. An injected one would prove the
arithmetic, which the unit tests already do, and not the daemon.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
2026-10-11 22:49:18 +00:00
2026-10-09 11:32:42 -04:00
2026-09-28 05:01:41 +00:00
2026-09-28 05:01:41 +00:00

hyprland-headless-stream-plugin

A Nix flake that runs a headless Hyprland session and publishes its frames on a persistent Unix socket, so any process that can open a socket can see the screen without owning a display.

Two parts:

  • NixOS module — services.hyprland-headless-stream: starts Hyprland with no physical monitor, and a small frame server beside it.
  • Package — hhstream — the frame server (publishes frames) and its client (reads them). Pure Python standard library.
{
  inputs.hhstream.url = "git+https://<host>/git/<owner>/hyprland-headless-stream-plugin.git";

  # in your host config
  imports = [ inputs.hhstream.nixosModules.default ];
  services.hyprland-headless-stream = {
    enable = true;
    # Optional: the default is one 1280x720@30 rule with an empty name, which
    # is Hyprland's wildcard and applies to whatever outputs the GPU has.
    outputs = [ { width = 1920; height = 1080; refresh = 60; } ];
  };
}

Then any consumer:

hhstream-client --socket /run/hypr-stream/stream.sock --count 1 --out frame.png

The socket is a plain file descriptor: the server serves every client that connects, and keeps running when one disconnects.

Driving it from an agent: the MCP server

hhstream-mcp is the hhstream CLI behind a Model Context Protocol surface, so an agent can look at this desktop, put an application on it, and aim its one pointer and keyboard at that application without writing command lines. The interface is frozen in docs/CONTRACT-mcp.md.

It is split the way the protocol splits things:

  • Resources are the state — eight of them, read by URI, and reading one changes nothing. hhstream://status is whether the desktop is up, hhstream://sessions is what is running, hhstream://sessions/<id>/logs is an application's own output, hhstream://pointer is who holds the input lease, hhstream://screen is a frame of the screen.
  • Tools are the acts — twenty-one, one per CLI verb that does something. session_start puts an application on the screen, pointer_acquire takes the input lease, keyboard_type types, session_kill ends a session.

A host decides what state to put in front of its model; the model decides what to do. That is the whole of the split, and it is why shot is still a tool (capturing is an act at a moment) while hhstream://screen exists beside it.

It is a thin wrapper and nothing more: every tool and every resource builds the argv list the CLI's own parser takes, runs the CLI's own handler, and maps what came back. The idle clock, the pointer lease, the allowlist and the exit-code table all stay where they were.

Install it with the module — off by default, because it is the surface through which a language model starts processes on this machine:

services.hyprland-headless-stream = {
  enable = true;
  sessions.enable = true;   # the session, pointer and keyboard tools need the broker
  mcp.enable = true;        # puts `hhstream-mcp` on the system PATH
};

Then register it with a client. The transport is stdio — one process per client, spawned by the client, no port and no daemon — so the whole configuration is a command and an environment:

{
  "mcpServers": {
    "hhstream": {
      "command": "hhstream-mcp",
      "env": {
        "HHSTREAM_SOCKET": "/run/hhstream/control.sock",
        "HHSTREAM_FRAME_SOCKET": "/run/hypr-stream/stream.sock"
      }
    }
  }
}

Both variables are the CLI's own and both are shown at their defaults, so they can be left out unless this machine moved a socket. The account the client runs as needs what the CLI needs: membership of the compositor's group (hhstream) to read the frame socket, and of the broker's to reach the control socket. The server cannot recover that for itself the way the CLI does — see docs/CONTRACT-mcp.md §5 — so if shot reports it cannot read the socket, the answer is "command": "sg", "args": ["hhstream", "-c", "hhstream-mcp"] or an account in the group.

hhstream-mcp --list-tools and --list-resources print the two tables and exit, which is the quickest way to check an install.

If twenty-one tools is more than a client has room for, --toolsets narrows what is offered to whichever families are wanted — frames, sessions, pointer, keyboard:

{ "command": "hhstream-mcp", "args": ["--toolsets", "frames,pointer,keyboard"] }

Resources are deliberately not narrowed by it: they are the host's context, not the model's tool budget. Nothing else about the server is configurable — it holds no state and caches no lease, and the pointer lease is an explicit argument on every gesture tool for exactly that reason.

Document What it is
docs/CONTRACT.md the wire protocol and the module surface — the interface other people build against
docs/CONTRACT-sessions.md the broker, the containers and the input lease
docs/CONTRACT-mcp.md the MCP surface: the resource URIs, the tool names, their arguments and the error mapping
docs/ARCHITECTURE.md how the pieces fit: compositor, capture, server, client
README.dev.md how to build, test and hack on it
examples/README.md the demo that films the screen: agent-eyes-demo.py

Status: work in progress — the module and the test suite are being built.

S
Description
No description provided
Readme
2.8 MiB
0 Stars 1 Watchers 0 Forks
Languages
Python 81.7%
Nix 18.1%
Shell 0.2%