nix: move the agent option namespace under services.hyperhive.agent
Every per-agent harness option lived at the top-level `hyperhive.*` while the host tier has always been `services.hyperhive.*`. Move all 52 agent-tier option leaves (33 top-level names across 16 modules) to `services.hyperhive.agent.*`, repoint every read, and keep existing agent configs evaluating through one `mkRenamedOptionModule` per old leaf path in the new nix/agent-modules/renamed-options.nix. The shims are per leaf rather than per namespace: `user`, `mcp`, `otel`, `queue`, `docs`, `forge`, `frontend`, `github`, `gui`, `logs`, `matrix` and `cargo` are plain attrsets of declarations, not submodule-typed options, so a parent-path rename would not reach their children. Three read-only options (`frontend.mergedDist`, `queue.clientIdFile`, `queue.clientSecretFile`) deliberately get no shim — a rename contributes a definition, which a read-only option refuses; the exclusions are commented in place. Refs #4473
This commit is contained in:
parent
60393d0e32
commit
3662eda440
21 changed files with 531 additions and 290 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# Per-agent matrix integration: the `hyperhive.matrix.*` +
|
||||
# `hyperhive.matrixAccounts` options, the long-running
|
||||
# Per-agent matrix integration: the `services.hyperhive.agent.matrix.*` +
|
||||
# `services.hyperhive.agent.matrixAccounts` options, the long-running
|
||||
# hive-matrix-daemon (serves its MCP tools directly over
|
||||
# streamable-http), its token-arrival path trigger, and the
|
||||
# auto-injected extraMcpServers entry.
|
||||
|
|
@ -10,19 +10,19 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
userName = config.hyperhive.user.name;
|
||||
# Rasterize the operator-set agent icon (`hyperhive.icon`, an SVG) to a
|
||||
userName = config.services.hyperhive.agent.user.name;
|
||||
# Rasterize the operator-set agent icon (`services.hyperhive.agent.icon`, an SVG) to a
|
||||
# 512x512 PNG so the matrix daemon can upload it as each account's avatar
|
||||
# over the live authenticated Client (see hive-matrix-mcp::client::sync_avatar).
|
||||
# Only forced when an icon is configured — the `HIVE_ICON_PNG` daemon-env
|
||||
# entry is gated on `hyperhive.icon != null`, so this binding stays lazy
|
||||
# entry is gated on `services.hyperhive.agent.icon != null`, so this binding stays lazy
|
||||
# when no icon is set.
|
||||
iconPng = pkgs.runCommand "hive-agent-icon.png" { nativeBuildInputs = [ pkgs.librsvg ]; } ''
|
||||
rsvg-convert -f png -w 512 -h 512 ${config.hyperhive.icon} -o $out
|
||||
rsvg-convert -f png -w 512 -h 512 ${config.services.hyperhive.agent.icon} -o $out
|
||||
'';
|
||||
in
|
||||
{
|
||||
options.hyperhive.matrix.enable = lib.mkOption {
|
||||
options.services.hyperhive.agent.matrix.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
|
|
@ -31,7 +31,7 @@ in
|
|||
|
||||
- runs `hive-matrix-daemon` as a systemd unit that holds a
|
||||
matrix-sdk Client + sync against the homeserver named by
|
||||
`HIVE_MATRIX_URL` (see `hyperhive.matrix.url` — there is no
|
||||
`HIVE_MATRIX_URL` (see `services.hyperhive.agent.matrix.url` — there is no
|
||||
default, since an agent's own netns makes a loopback guess
|
||||
wrong). The daemon auto-skips when that URL or
|
||||
`<state>/matrix-token` is missing, and a `systemd.paths`
|
||||
|
|
@ -41,7 +41,7 @@ in
|
|||
send_reaction, send_reply, mark_read, list_rooms,
|
||||
list_room_members, read_room) to claude via an auto-injected
|
||||
`extraMcpServers.matrix` entry pointed at the daemon's own
|
||||
streamable-http listener (`hyperhive.mcp.matrixHttpPort`) — no
|
||||
streamable-http listener (`services.hyperhive.agent.mcp.matrixHttpPort`) — no
|
||||
stdio bridge, no per-turn respawn, same shape as the built-in
|
||||
hyperhive surface and `hive-bash-daemon`.
|
||||
- wakes the agent on incoming room events via a short teaser
|
||||
|
|
@ -50,13 +50,13 @@ in
|
|||
unread server-side until `read_room` consumes it.
|
||||
|
||||
Set to `false` for agents that should NOT have matrix tools at
|
||||
all (e.g. agents on a host without `hyperhive.matrix.enable` on
|
||||
all (e.g. agents on a host without `services.hyperhive.agent.matrix.enable` on
|
||||
the meta side). When token file is absent the daemon and MCP
|
||||
both no-op cleanly anyway, so `false` is rarely necessary.
|
||||
'';
|
||||
};
|
||||
|
||||
options.hyperhive.matrix.url = lib.mkOption {
|
||||
options.services.hyperhive.agent.matrix.url = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "https://matrix.darkest.space";
|
||||
|
|
@ -82,7 +82,7 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
options.hyperhive.matrixAccounts = lib.mkOption {
|
||||
options.services.hyperhive.agent.matrixAccounts = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
|
|
@ -112,7 +112,7 @@ in
|
|||
example = "https://matrix.example.org";
|
||||
description = ''
|
||||
Homeserver URL for this account. When null (the default),
|
||||
the account falls back to `hyperhive.matrix.url`. Set it for
|
||||
the account falls back to `services.hyperhive.agent.matrix.url`. Set it for
|
||||
an account on a different homeserver than the agent's
|
||||
default (e.g. an external public-matrix account).
|
||||
'';
|
||||
|
|
@ -140,7 +140,7 @@ in
|
|||
|
||||
The **hive-internal account is always present and is the primary**:
|
||||
it is named `main`, synthesized by the daemon from
|
||||
`hyperhive.matrix.url` + `<state>/matrix-token` +
|
||||
`services.hyperhive.agent.matrix.url` + `<state>/matrix-token` +
|
||||
`<state>/matrix-sdk-state`, and is the account a tool call acts as
|
||||
when it omits `account`. You never declare it here --- this option
|
||||
is only for the extras (e.g. an external public-matrix account).
|
||||
|
|
@ -149,23 +149,23 @@ in
|
|||
agent then has only `main`. When non-empty, the extras are
|
||||
serialized to the daemon's `HIVE_MATRIX_ACCOUNTS` environment
|
||||
variable and the daemon appends them after `main`. Requires
|
||||
`hyperhive.matrix.enable` (there is no `main` to extend otherwise).
|
||||
`services.hyperhive.agent.matrix.enable` (there is no `main` to extend otherwise).
|
||||
'';
|
||||
};
|
||||
|
||||
options.hyperhive.mcp.matrixHttpPort = lib.mkOption {
|
||||
options.services.hyperhive.agent.mcp.matrixHttpPort = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8792;
|
||||
example = 8793;
|
||||
description = ''
|
||||
Loopback port `hive-matrix-daemon` serves its MCP tools
|
||||
(`send_message`, `list_rooms`, `read_room`, …) on. Same shape as
|
||||
`hyperhive.mcp.bashHttpPort`: HTTP is the *sole* transport (no
|
||||
`services.hyperhive.agent.mcp.bashHttpPort`: HTTP is the *sole* transport (no
|
||||
stdio bridge — the daemon that owns the matrix-sdk `Client`
|
||||
registry serves the MCP tools directly in-process),
|
||||
`Restart = "always"` keeps the listener self-healing, and
|
||||
loopback-only binding means no auth token is needed (same
|
||||
`allowed_hosts` reasoning as `hyperhive.mcp.httpPort`). Safe as a
|
||||
`allowed_hosts` reasoning as `services.hyperhive.agent.mcp.httpPort`). Safe as a
|
||||
single fixed default across all agents (private per-container
|
||||
network namespace — see docs/networking/network.md).
|
||||
'';
|
||||
|
|
@ -177,18 +177,20 @@ in
|
|||
# `main` account they extend, which exists only when matrix is
|
||||
# enabled.
|
||||
{
|
||||
assertion = config.hyperhive.matrixAccounts == { } || config.hyperhive.matrix.enable;
|
||||
assertion =
|
||||
config.services.hyperhive.agent.matrixAccounts == { }
|
||||
|| config.services.hyperhive.agent.matrix.enable;
|
||||
message =
|
||||
"hyperhive.matrixAccounts requires hyperhive.matrix.enable = true "
|
||||
"services.hyperhive.agent.matrixAccounts requires services.hyperhive.agent.matrix.enable = true "
|
||||
+ "(the extras extend the hive-internal `main` account, which only "
|
||||
+ "exists when matrix is enabled).";
|
||||
}
|
||||
# `main` is reserved for the synthesized hive-internal account; a
|
||||
# declared extra by that name would silently collide with it.
|
||||
{
|
||||
assertion = !builtins.hasAttr "main" config.hyperhive.matrixAccounts;
|
||||
assertion = !builtins.hasAttr "main" config.services.hyperhive.agent.matrixAccounts;
|
||||
message =
|
||||
"hyperhive.matrixAccounts cannot contain a key named \"main\" "
|
||||
"services.hyperhive.agent.matrixAccounts cannot contain a key named \"main\" "
|
||||
+ "--- that name is reserved for the hive-internal account.";
|
||||
}
|
||||
# Token files must land at the `matrix-token*` name the daemon
|
||||
|
|
@ -199,17 +201,17 @@ in
|
|||
# `matrix-catgirl-token`) is caught at build time, not silently.
|
||||
{
|
||||
assertion = lib.all (a: lib.hasPrefix "matrix-token" (baseNameOf a.tokenFile)) (
|
||||
lib.attrValues config.hyperhive.matrixAccounts
|
||||
lib.attrValues config.services.hyperhive.agent.matrixAccounts
|
||||
);
|
||||
message =
|
||||
"every hyperhive.matrixAccounts.<name>.tokenFile basename must start with "
|
||||
"every services.hyperhive.agent.matrixAccounts.<name>.tokenFile basename must start with "
|
||||
+ "\"matrix-token\" so the daemon path-watcher glob "
|
||||
+ "(matrix-token* in the agent's state dir) picks it up live. Offending: "
|
||||
+ lib.concatStringsSep ", " (
|
||||
lib.mapAttrsToList (n: a: "${n}=${baseNameOf a.tokenFile}") (
|
||||
lib.filterAttrs (
|
||||
_n: a: !lib.hasPrefix "matrix-token" (baseNameOf a.tokenFile)
|
||||
) config.hyperhive.matrixAccounts
|
||||
) config.services.hyperhive.agent.matrixAccounts
|
||||
)
|
||||
)
|
||||
+ ".";
|
||||
|
|
@ -220,10 +222,10 @@ in
|
|||
# ./mcp.nix. `lib.mkDefault` so the operator's own agent.nix can
|
||||
# override it. Points at the daemon's own persistent
|
||||
# streamable-http listener — no stdio bridge, no per-turn spawn.
|
||||
hyperhive.extraMcpServers = lib.mkIf config.hyperhive.matrix.enable {
|
||||
services.hyperhive.agent.extraMcpServers = lib.mkIf config.services.hyperhive.agent.matrix.enable {
|
||||
matrix = lib.mkDefault {
|
||||
type = "http";
|
||||
url = "http://127.0.0.1:${toString config.hyperhive.mcp.matrixHttpPort}/mcp";
|
||||
url = "http://127.0.0.1:${toString config.services.hyperhive.agent.mcp.matrixHttpPort}/mcp";
|
||||
allowedTools = [ "*" ];
|
||||
};
|
||||
};
|
||||
|
|
@ -233,7 +235,7 @@ in
|
|||
# signals on incoming room events via `/run/hive/mcp.sock`. See
|
||||
# `docs/agent-lifecycle/persistence.md::Matrix per-agent daemon + token-arrival
|
||||
# trigger` for the first-boot-ordering rationale.
|
||||
systemd.services.hive-matrix-daemon = lib.mkIf config.hyperhive.matrix.enable {
|
||||
systemd.services.hive-matrix-daemon = lib.mkIf config.services.hyperhive.agent.matrix.enable {
|
||||
description = "long-running matrix-sdk Client + MCP daemon";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
before = [ "hive-agent.service" ];
|
||||
|
|
@ -255,8 +257,8 @@ in
|
|||
# token and no-ops. Nothing here falls back to loopback: that would
|
||||
# be a value that evaluates fine and then addresses the agent's own
|
||||
# netns instead of the homeserver.
|
||||
// lib.optionalAttrs (config.hyperhive.matrix.url != null) {
|
||||
HIVE_MATRIX_URL = config.hyperhive.matrix.url;
|
||||
// lib.optionalAttrs (config.services.hyperhive.agent.matrix.url != null) {
|
||||
HIVE_MATRIX_URL = config.services.hyperhive.agent.matrix.url;
|
||||
}
|
||||
# Multi-account: serialize the *extra* accounts to the JSON the
|
||||
# daemon parses (`accounts::configured`). Only set when extras are
|
||||
|
|
@ -265,7 +267,7 @@ in
|
|||
# prepends it, so we emit extras only. Each entry is in the
|
||||
# daemon's `AccountCfg` serde shape: name (the attr key) /
|
||||
# token_file / state_dir / optional homeserver.
|
||||
// lib.optionalAttrs (config.hyperhive.matrixAccounts != { }) {
|
||||
// lib.optionalAttrs (config.services.hyperhive.agent.matrixAccounts != { }) {
|
||||
HIVE_MATRIX_ACCOUNTS = builtins.toJSON (
|
||||
lib.mapAttrsToList (
|
||||
name: a:
|
||||
|
|
@ -275,17 +277,17 @@ in
|
|||
state_dir = a.sessionDir;
|
||||
}
|
||||
// lib.optionalAttrs (a.homeserver != null) { inherit (a) homeserver; }
|
||||
) config.hyperhive.matrixAccounts
|
||||
) config.services.hyperhive.agent.matrixAccounts
|
||||
);
|
||||
}
|
||||
# Rasterized agent icon path for the daemon's avatar sync. Only set
|
||||
# when an icon is configured; absent → the daemon skips avatar setting
|
||||
# (hive-matrix-mcp::client::sync_avatar returns early on unset env).
|
||||
// lib.optionalAttrs (config.hyperhive.icon != null) {
|
||||
// lib.optionalAttrs (config.services.hyperhive.agent.icon != null) {
|
||||
HIVE_ICON_PNG = "${iconPng}";
|
||||
};
|
||||
serviceConfig = {
|
||||
ExecStart = "${config.hyperhive.packages.hive-matrix-daemon}/bin/hive-matrix-daemon --http 127.0.0.1:${toString config.hyperhive.mcp.matrixHttpPort}";
|
||||
ExecStart = "${config.services.hyperhive.agent.packages.hive-matrix-daemon}/bin/hive-matrix-daemon --http 127.0.0.1:${toString config.services.hyperhive.agent.mcp.matrixHttpPort}";
|
||||
SyslogIdentifier = "hive-matrix-daemon";
|
||||
# `on-failure`, not `always`: the daemon deliberately exits 0
|
||||
# (a clean, non-failure exit) when no token is provisioned yet
|
||||
|
|
@ -308,7 +310,7 @@ in
|
|||
# the daemon would exit 0 silently on first boot and the MCP
|
||||
# would have no backend until next restart. See
|
||||
# `docs/agent-lifecycle/persistence.md` (same section as above).
|
||||
systemd.paths.hive-matrix-daemon = lib.mkIf config.hyperhive.matrix.enable {
|
||||
systemd.paths.hive-matrix-daemon = lib.mkIf config.services.hyperhive.agent.matrix.enable {
|
||||
description = "trigger hive-matrix-daemon when a matrix token appears";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
# `matrix-token*` (not just `matrix-token`) so a secondary
|
||||
|
|
|
|||
Loading…
Reference in a new issue