HermenixandClaude Opus 5 ca5dbfb2ea feat(nix): the hhstream-live unit, and the two things it has to be handed
`services.hyprland-headless-stream.sessions.stream.enable` (default **false**)
runs `hhstream-live` and hands the broker `/run/hhstream/live.sock`. Running it
still turns nothing on: a stream exists only for the sessions
`hhstream session stream enable` was run on, which is the plan's rule that a
stream is never on for all sessions at all times.

A fourth unit rather than a flag on an existing one, for the pointer driver's
reason: `grim` blocks tens to hundreds of milliseconds, so the capture must not
run where `touch` and `kill` are answered, and a LAN-facing HTTP parser must not
run in the frame server whose one-socket contract cannot grow one.

Two things the unit must be handed, both of them MEASURED failures rather than
precautions:

1. **The capture command, spelled out, with grim's store path.** A unit's
   `PATH` has no `grim`
   (`docs/TODO/capture-binary-and-the-unit-path.md`), and the symptom is a
   stream that answers with an empty frame area and says why only in the
   daemon's journal. Every word is passed as `--capture-command=<word>` and not
   `--capture-command <word>`, because grim's last word is a bare `-` and
   argparse reads a lone dash as an option prefix rather than a value -- a unit
   crash-looping with "expected one argument", which is how that form was
   chosen.
2. **The compositor's session.** `XDG_RUNTIME_DIR` on the unit plus `execLive`,
   which discovers whichever `wayland-N` the compositor actually bound and
   exports it -- `execServer`'s trick, for `execServer`'s reason: the name is
   only known once the compositor is up, so it cannot be an `Environment=`
   line. Without it the unit was `active (running)`, the broker attached,
   `stream status` said `attached: true`, and every capture exited 1 with
   "XDG_RUNTIME_DIR is invalid or not set in the environment" until the
   publisher gave up after ten in a row. checks/vm-stream.nix found that on its
   first real run, which is the whole reason that check reads bytes instead of
   asserting a 200.

`SupplementaryGroups` gets the compositor's group for the pointer driver's
reason one step further -- this one has to *capture*, not merely find the
socket -- and there is deliberately no `RuntimeDirectory=`: a second one on
/run/hhstream would delete the broker's control socket when this unit stopped,
which the plan names as the Stage 3 risk.

`sessions.stream.fps` is the daemon's own default and nothing else sends one, so
the option changes what actually happens; the port and bind address are the
daemon's too, and the broker learns the URL from it.

`nix/package.nix` names `hhstream_live.control` and `hhstreamd.live` in
`pythonImportsCheck`: they are the one pair in this package that has to agree
with each other across two processes, so an import error in either is worth
finding at build time rather than the first time an operator enables a stream.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
2026-10-11 22:48:22 +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%