diff --git a/nix/agent-modules/mcp.nix b/nix/agent-modules/mcp.nix index b0b0fffe3..d47f35fc6 100644 --- a/nix/agent-modules/mcp.nix +++ b/nix/agent-modules/mcp.nix @@ -19,7 +19,18 @@ let # opencode preset the provider key too. Either way it is handed the same # store identity ./queue-identity.nix hands the harness, under the same # switch. - subagentReadsStore = config.services.hyperhive.agent.bao.addr != null; + # The bash and subagent daemons publish to the swarm queue as the agent, so + # each reads the agent's queue secret from the store with the agent's own + # identity. Paths and a name only. `%d` is the unit's own credentials + # directory, where `hive-agent-bao-server-ca` is loaded. + daemonsReadStore = config.services.hyperhive.agent.bao.addr != null; + storeIdentityEnv = { + HIVE_AGENT_NAME = userName; + BAO_ADDR = config.services.hyperhive.agent.bao.addr; + BAO_CLIENT_CERT = config.services.hyperhive.agent.bao.clientCertFile; + BAO_CLIENT_KEY = config.services.hyperhive.agent.bao.clientKeyFile; + BAO_CACERT = "%d/hive-agent-bao-server-ca"; + }; in { options.services.hyperhive.agent.extraMcpServers = lib.mkOption { @@ -291,6 +302,8 @@ in description = "bash task runner + MCP daemon for hive-bash"; wantedBy = [ "multi-user.target" ]; before = [ "hive-agent.service" ]; + # The live certificate pair exists once ./bao.nix's unit has run. + after = lib.optional daemonsReadStore "hive-agent-bao-identity.service"; # The daemon runs every bash task via `Command::new("bash")` and the # commands themselves (hive-forge, git, jq, …) resolve from PATH. # A standalone daemon has no inherited agent PATH, so without this @@ -317,7 +330,13 @@ in # loose-ends dir paths; `hive_agent_sock::paths::harness_dir` # panics loudly if HYPERHIVE_HARNESS_DIR is unset rather than # deriving a fallback, since every service here always gets it. - }; + # + # The store identity is what lets the daemon publish each task's + # status and output to the swarm queue as this agent + # (`swarm_term.rs`): without it the daemon logs "bash tasks are not + # published" and the swarm UI's background-tasks list stays empty. + } + // lib.optionalAttrs daemonsReadStore storeIdentityEnv; serviceConfig = { ExecStart = "${config.services.hyperhive.agent.packages.hive-bash-daemon}/bin/hive-bash-daemon --http 127.0.0.1:${toString config.services.hyperhive.agent.mcp.bashHttpPort}"; SyslogIdentifier = "hive-bash-daemon"; @@ -338,6 +357,11 @@ in DelegateSubgroup = "daemon"; User = userName; Group = userName; + } + // lib.optionalAttrs daemonsReadStore { + # Bare id: inherits the credential the container manager passed in, + # the same form ./queue-identity.nix uses. + LoadCredential = [ "hive-agent-bao-server-ca" ]; }; }; @@ -360,7 +384,7 @@ in wantedBy = [ "multi-user.target" ]; before = [ "hive-agent.service" ]; # The live certificate pair exists once ./bao.nix's unit has run. - after = lib.optional subagentReadsStore "hive-agent-bao-identity.service"; + after = lib.optional daemonsReadStore "hive-agent-bao-identity.service"; # A subagent task runs its own nested `claude` invocation (via # `hive-claude`), which needs to resolve `claude` itself off PATH — # same reasoning as `hive-bash-daemon`'s `path` above, even though @@ -408,14 +432,7 @@ in # environment stays as is. BASH_DEFAULT_TIMEOUT_MS = "1800000"; # 30 minutes } - // lib.optionalAttrs subagentReadsStore { - # Paths and a name only. `%d` is this unit's own credentials directory. - HIVE_AGENT_NAME = userName; - BAO_ADDR = config.services.hyperhive.agent.bao.addr; - BAO_CLIENT_CERT = config.services.hyperhive.agent.bao.clientCertFile; - BAO_CLIENT_KEY = config.services.hyperhive.agent.bao.clientKeyFile; - BAO_CACERT = "%d/hive-agent-bao-server-ca"; - }; + // lib.optionalAttrs daemonsReadStore storeIdentityEnv; serviceConfig = { ExecStart = "${config.services.hyperhive.agent.packages.hive-subagent-daemon}/bin/hive-subagent-daemon --http 127.0.0.1:${toString config.services.hyperhive.agent.mcp.subagentHttpPort}"; SyslogIdentifier = "hive-subagent-daemon"; @@ -446,7 +463,7 @@ in User = userName; Group = userName; } - // lib.optionalAttrs subagentReadsStore { + // lib.optionalAttrs daemonsReadStore { # Bare id: inherits the credential the container manager passed in, # the same form ./queue-identity.nix uses. LoadCredential = [ "hive-agent-bao-server-ca" ]; diff --git a/nix/module-eval/agent-queue-bao.nix b/nix/module-eval/agent-queue-bao.nix index 38580968e..e2dd2a6b5 100644 --- a/nix/module-eval/agent-queue-bao.nix +++ b/nix/module-eval/agent-queue-bao.nix @@ -114,6 +114,30 @@ let # Control: the lookup finds the store identity's credential. && lib.elem "hive-agent-bao-server-ca" (credentials agentBao); } + { + # The bash daemon publishes each task to the queue as the agent, which + # takes the agent's name and store identity in its own environment; the + # swarm UI's background-tasks list is empty without them. Same + # identity and server CA as the subagent daemon, ordered after the + # login unit that writes the certificate. + name = "the bash daemon gets the agent's store identity to publish its tasks"; + ok = + let + a = agentBao.services.hyperhive.agent; + u = agentBao.systemd.services.hive-bash-daemon; + e = u.environment; + in + e.HIVE_AGENT_NAME == a.user.name + && e.BAO_ADDR == a.bao.addr + && e.BAO_CLIENT_CERT == a.bao.clientCertFile + && e.BAO_CLIENT_KEY == a.bao.clientKeyFile + && e.BAO_CACERT == "%d/hive-agent-bao-server-ca" + && lib.elem "hive-agent-bao-server-ca" u.serviceConfig.LoadCredential + && lib.elem "hive-agent-bao-identity.service" u.after + # Control: with no store address the daemon names no identity. + && !(agentNoBao.systemd.services.hive-bash-daemon.environment ? BAO_ADDR) + && !(agentNoBao.systemd.services.hive-bash-daemon.serviceConfig ? LoadCredential); + } { # Both options are refused, naming where the address # comes from now, rather than dropped silently.