Files
HermenixandClaude Opus 5 ca5e309e51 feat(mcp): the hhstream CLI as Model Context Protocol tools
`hhstream_mcp` serves the whole `hhstream` surface -- the four frame verbs, the
ten session verbs, the eight pointer verbs and the four keyboard verbs -- as 26
MCP tools over stdio, so an agent drives this desktop through typed tools
instead of writing command lines.

It is a shim and nothing more. Each tool builds the argv list the CLI's own
parser takes, hands it to the CLI's own handler **in this process**, and maps
what came back. The idle clock, the pointer lease, the allowlist, the exit-code
table and every refusal message stay where they already were.

Four decisions worth stating, each argued at length where it lives:

* **One tool per verb**, not one per family with an `action` enum. The
  arguments do not rhyme, the two rules an agent gets wrong have to be on the
  tool it gets wrong, and `readOnlyHint` is a real per-verb distinction here --
  `session_container` with an id runs `container.reconcile`, so it is not
  marked read-only.
* **In process, not as a subprocess.** `hhstream.cli`'s parser already takes an
  argv list and its handlers already return a code from the frozen table. Two
  of its paths cannot be called here and both end in an `exec` that would
  replace this server: `main`'s `sg` re-exec, and `cmd_run`'s `execvpe`. The
  first is therefore unavailable and said out loud (`access_hint`); the second
  is why `run` goes through `posix_spawn` into its own session.
* **The transport leaves file descriptor 1.** The CLI prints, and `record`
  spawns an `ffmpeg` whose output it does not capture. `claim_transport` takes
  a private duplicate of stdin and stdout at start-up and points fd 1 at the
  log, so a stray write is a log line and never a corrupted JSON-RPC stream.
* **No state, and the lease is an argument.** The CLI caches a lease id between
  invocations because its surface is flagless; this passes `--lease` on every
  call and never reads that cache. A cached lease is a lease an agent cannot
  see.

Refusals come back as tool errors -- never as a success -- carrying the remedy
sentence, the CLI's own `error`/`reason`/`hint`, everything it said, and the
frozen exit code in `structuredContent`. Exits 8 and 9 are held apart by a
test, because an agent that sees 8 must wait and one that sees 9 must acquire.

The root pyproject excludes `hhstream_mcp*` from package discovery: without
that, `packages.hhstream` would ship a module whose first import line fails.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
2026-10-11 06:32:23 +00:00

52 lines
2.5 KiB
TOML

[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"
[project]
name = "hhstream"
version = "0.1.0"
description = "Publish a headless Hyprland session's frames on a Unix socket"
requires-python = ">=3.11"
# The frame socket, the CLI and the broker are stdlib-only by policy
# (docs/CONTRACT-sessions.md §6, rule 3). The input driver is the one
# exception, twice over: talking Wayland means speaking the wire protocol, and
# turning a keysym name into the keycode-plus-modifier-mask that *this* layout
# needs means compiling an XKB keymap. Re-implementing either here would be a
# worse idea than a dependency, and `xkbcommon` is deliberately NOT optional --
# an optional one would let `tests/pointer/test_keymap.py` skip, and the
# unmappable-character path is exactly the one that must not rot.
dependencies = ["pywayland>=0.4", "xkbcommon>=1.0"]
[project.scripts]
hhstream-server = "hhstream.server:main"
hhstream-client = "hhstream.client:main"
# The one front door: frames/launch/record verbs plus the `session` namespace.
hhstream = "hhstream.cli:main"
# The session daemon. A separate process on purpose: it outlives every CLI call.
hhstreamd = "hhstreamd.__main__:main"
# The pointer driver. Its own process because a Wayland client needs its own
# connection, and a blocked one must not stall the broker.
hhstream-pointer = "hhstream_pointer.__main__:main"
# The session-stream web app (one port, a page per enabled session). Its own
# process beside the pointer driver: a LAN-facing HTTP parser must not be able
# to stall session lifecycle, and `grim` blocking must not reach the broker.
hhstream-live = "hhstream_live.__main__:main"
[tool.setuptools.packages.find]
where = ["src"]
# `hhstream_mcp` lives under src/ beside the others -- so the dev shell's
# PYTHONPATH reaches it and the tests import it the same way they import
# everything else -- but it is a *different distribution*
# (src/hhstream_mcp/pyproject.toml, built by nix/mcp.nix) because it depends on
# the MCP SDK. Without this exclusion `find` would sweep it into this wheel,
# and `packages.hhstream` would ship a module whose first import line fails:
# the dependency policy above would be intact and the package would still be
# broken.
exclude = ["hhstream_mcp*"]
# The phrase generator reads this at runtime, so it has to be *installed*, not
# just present in the checkout: a wheel (and the Nix build) that dropped it
# would make every `enable` fail with an empty wordlist.
[tool.setuptools.package-data]
hhstream_live = ["wordlist.txt"]