From e3c3823a466194d65dbf0d96d8361618849e7d19 Mon Sep 17 00:00:00 2001 From: m3ta-chiron Date: Sat, 31 Oct 2026 15:23:58 +0100 Subject: [PATCH] =?UTF-8?q?feat(m3-hermes):=20T3=20agent=20runtime=20?= =?UTF-8?q?=E2=80=94=20agent-lib=20skills=20+=20gitea=20as=20m3ta-chiron?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - agent-lib v2 client: /etc config + timer sync (2h/on-boot) as m3tam3re, deploys work repo into ~/.agents/skills + ~/.config/opencode/* - Claude Code skills mirror (system path unit, port of m3ta-home claude-skills.nix) - git identity m3ta-chiron via t3code service env (no ~/.gitconfig hijack) - gitea SSH for m3tam3re (User gitea, key ~/.ssh/gitea) + host key pinned system-wide; one-time keygen steps documented in module header --- hosts/m3-hermes/services/t3code.nix | 157 +++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 2 deletions(-) diff --git a/hosts/m3-hermes/services/t3code.nix b/hosts/m3-hermes/services/t3code.nix index c5a8242..d4fe3c4 100644 --- a/hosts/m3-hermes/services/t3code.nix +++ b/hosts/m3-hermes/services/t3code.nix @@ -10,6 +10,19 @@ # The server binds 0.0.0.0, but the firewall admits the port for mesh # peers only — same posture as ai-memory and the hermes dashboard. # +# Agent runtime for the T3 harnesses (OpenCode / Claude Code, 2026-10-31): +# - Skills/commands/agents via agent-lib v2: a timer syncs the work repo +# (gitea m3tam3re/agent-lib — anonymously readable over HTTPS, verified, +# so no deploy token) into ~/.agents/skills + ~/.config/opencode/*. A +# path unit mirrors skills into ~/.claude/skills for Claude Code +# (port of m3ta-home profiles/sets/coding/agents/claude-skills.nix). +# - Git identity: every harness spawned by `t3 serve` commits as the +# m3ta-chiron bot account — via service env vars, deliberately NOT via +# ~/.gitconfig, so m3tam3re's interactive git on this host is untouched. +# - Gitea SSH: m3tam3re's ssh config pins User gitea + key ~/.ssh/gitea +# (one-time keygen; pubkey added to the m3ta-chiron account) — covers +# git remotes AND git+ssh:// flake inputs. Host key pinned system-wide. +# # One-time interactive steps after deploy (deliberately NOT declarative — # subscription auth must live in each harness's own credential store and # may not be shared with other tools per provider ToS): @@ -20,6 +33,13 @@ # (persists in /home/m3tam3re/.claude). # - OpenCode: `sudo -u m3tam3re opencode auth login` # (subscription auth persists in OpenCode's own state dir). +# - Gitea push key for the T3 lane (a private key must not live in the +# nix store, so imperative like the harness auths above): +# sudo -u m3tam3re ssh-keygen -t ed25519 -N "" \ +# -C chiron-t3-m3-hermes -f /home/m3tam3re/.ssh/gitea +# Then add the pubkey to the m3ta-chiron account on code.m3ta.dev +# (m3ta-chiron → Settings → SSH / GPG Keys → "chiron-t3-m3-hermes"). +# Verify: sudo -u m3tam3re ssh -T gitea@code.m3ta.dev { config, pkgs, @@ -28,14 +48,74 @@ # Mesh-only via interface match on wt0 (NetBird) — an IPv4 CIDR in -s # would abort the ip6tables run of ip46tables and fail the unit. port = config.m3ta.ports.get "t3code"; + + # ── Lane-1 agent runtime ───────────────────────────────────────────── + cockpitUser = "m3tam3re"; + cockpitHome = "/home/${cockpitUser}"; + + # Commit identity of the T3 Code agents: the fleet bot account. Env + # vars are respected by git in every process the service spawns; they + # survive restarts and stay out of m3tam3re's dotfiles. + gitIdentityEnv = { + GIT_AUTHOR_NAME = "m3ta-chiron"; + GIT_AUTHOR_EMAIL = "m3ta-chiron@agentmail.to"; + GIT_COMMITTER_NAME = "m3ta-chiron"; + GIT_COMMITTER_EMAIL = "m3ta-chiron@agentmail.to"; + }; + + # SSH to the private Gitea for the T3 lane. Sits in m3tam3re's ssh + # config (per-user — Hermes' own gitea access via its own ssh config + # is unaffected). URL-embedded users (gitea@code.m3ta.dev) match the + # Host block, so IdentityFile applies to git remotes and flake inputs + # alike. + t3SshConfig = pkgs.writeText "t3-gitea-ssh-config" '' + Host code.m3ta.dev + User gitea + IdentityFile ~/.ssh/gitea + IdentitiesOnly yes + ''; + + # Mirror ~/.agents/skills → ~/.claude/skills so Claude Code sees the + # same skills OpenCode does. Per-skill symlinks: Claude's own entries + # and hand-made skills stay untouched, vanished skills get unlinked. + claudeSkillsSync = pkgs.writeShellApplication { + name = "t3-claude-skills-sync"; + runtimeInputs = [pkgs.coreutils]; + text = '' + src="${cockpitHome}/.agents/skills" + dst="${cockpitHome}/.claude/skills" + mkdir -p "$src" "$dst" + + # Drop links whose target is gone. + for link in "$dst"/*; do + [ -L "$link" ] || continue + case "$(readlink "$link")" in + "$src"/*) [ -e "$link" ] || rm -f "$link" ;; + esac + done + + # Link every skill folder; never replace a real dir or foreign link. + for skill in "$src"/*/; do + skill="''${skill%/}" + [ -f "$skill/SKILL.md" ] || continue + name="$(basename "$skill")" + target="$dst/$name" + if [ -L "$target" ] || [ ! -e "$target" ]; then + ln -sfn "$skill" "$target" + fi + done + ''; + }; in { # CLI on the system for interactive admin (t3 pair, t3 service status) # plus the harnesses T3 Code orchestrates. Login shells need them for - # the one-time auth flows documented in the header. + # the one-time auth flows documented in the header. agent-lib enables + # interactive syncs by the cockpit user (`agent-lib sync` / `status`). environment.systemPackages = [ pkgs.llm-agents.t3code pkgs.llm-agents.opencode2 pkgs.llm-agents.claude-code + pkgs.agent-lib ]; # ── T3 Code server (system service, cockpit user) ──────────────────── @@ -54,7 +134,11 @@ in { RestartSec = "5"; }; - environment.T3CODE_PORT = toString port; + environment = + { + T3CODE_PORT = toString port; + } + // gitIdentityEnv; # Harness CLIs and git for the agents T3 Code spawns. path = with pkgs; [ @@ -64,6 +148,75 @@ in { ]; }; + # ── Gitea (code.m3ta.dev) for the T3 lane ──────────────────────────── + # Host key pinned system-wide: non-interactive SSH (git clone, nix + # flake git+ssh inputs) works for every user without a first-connect + # prompt. Read-only fact, safe to share across users. + environment.etc."ssh/ssh_known_hosts".text = '' + code.m3ta.dev ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFmmqZ4GgDEXJgj8uYrZAr/EoLIA6LJGkTIyKGQD/60a + ''; + + # Per-user SSH config (User gitea + key, see t3SshConfig). NOTE: L+ + # replaces a pre-existing real file — none existed at PR time. If + # m3tam3re ever grows his own ssh config here, fold the Host block in + # by hand and drop this rule. + systemd.tmpfiles.rules = [ + "d ${cockpitHome}/.ssh 0700 ${cockpitUser} users -" + "L+ ${cockpitHome}/.ssh/config - - - - ${t3SshConfig}" + ]; + + # ── agent-lib v2 client: skills/commands/agents for the harnesses ──── + # Fleet rollout pattern (agent-lib docs/fleet-handoff.md): one + # admin-protected config at /etc/agent-lib/config.json, root-owned and + # world-readable (mode 0644 by default). The work repo is anonymously + # readable over HTTPS (verified 2026-10-31) — no token in the config. + environment.etc."agent-lib/config.json".text = + builtins.toJSON {repo_url = "https://code.m3ta.dev/m3tam3re/agent-lib.git";}; + + # Sync runs in the cockpit user's context (deployment targets resolve + # against $HOME) and mirrors skills into Claude Code right after. + systemd.services.agent-lib-sync = { + description = "agent-lib sync — deploy work repo into T3 agent runtime paths"; + after = ["network-online.target"]; + wants = ["network-online.target"]; + serviceConfig = { + Type = "oneshot"; + User = cockpitUser; + Group = "users"; + ExecStart = "${pkgs.agent-lib}/bin/agent-lib sync"; + ExecStartPost = "${claudeSkillsSync}/bin/t3-claude-skills-sync"; + }; + environment.HOME = cockpitHome; + }; + + systemd.timers.agent-lib-sync = { + description = "agent-lib sync every 2h (skills for T3 Code agents)"; + wantedBy = ["timers.target"]; + timerConfig = { + OnBootSec = "5min"; + OnUnitActiveSec = "2h"; + Persistent = true; + }; + }; + + # Catch manual `agent-lib sync` runs by the cockpit user as well. + systemd.paths.t3-claude-skills-sync = { + description = "Watch ~/.agents/skills for changes (mirror to Claude Code)"; + wantedBy = ["multi-user.target"]; + pathConfig.PathChanged = "${cockpitHome}/.agents/skills"; + }; + + systemd.services.t3-claude-skills-sync = { + description = "Mirror ~/.agents/skills into ~/.claude/skills (Claude Code)"; + serviceConfig = { + Type = "oneshot"; + User = cockpitUser; + Group = "users"; + ExecStart = "${claudeSkillsSync}/bin/t3-claude-skills-sync"; + }; + environment.HOME = cockpitHome; + }; + networking.firewall = { extraCommands = '' # Allow t3code only from Netbird mesh VPN