# AI agent system — OpenCode, Pi, and MCP server configuration.
# Relies on coding.agents options provided by home/common/default.nix
# (inputs.m3ta-nixpkgs.homeManagerModules.default).
{
  config,
  inputs,
  lib,
  pkgs,
  videoDrivers ? [],
  ...
}: {
  # Agent Git Identity configuration
  # Note: Uses existing gitea SSH key (m3tam3re identity) for push auth
  coding.agents.gitIdentity = {
    enable = true;
    name = "m3ta-chiron";
    email = "m3ta-chiron@agentmail.to";
    sshKey = "/home/m3tam3re/.ssh/gitea";
  };

  imports = [
    # OpenCode and Pi agent configurations
    ./opencode.nix
    ./pi.nix
  ];

  coding.agents.skills = {
    agentsInput = inputs.agents;
    externalSkills = [
      {
        src = inputs.skills-anthropic;
        selectSkills = ["pdf" "docx" "frontend-design"];
      }
      {src = inputs.skills-superpowers;}
      {src = inputs.skills-vercel;}
      {src = inputs.skills-basecamp;}
      {src = inputs.skills-kestra;}
    ];
  };

  programs.mcp = {
    enable = true;
    servers = {
      DeepWiki = {
        url = "https://mcp.deepwiki.com/mcp";
      };
      Ref = {
        command = "bash";
        args = ["-c" "REF_API_KEY=$(cat /run/agenix/ref-key) exec bunx ref-tools-mcp@latest"];
      };
      Exa = {
        command = "bash";
        args = ["-c" "EXA_API_KEY=$(cat /run/agenix/exa-key) exec bunx exa-mcp-server@latest tools=web_search_exa"];
      };
      Outline = {
        url = "https://wiki.az-gruppe.com/mcp";
      };
      ContextMode = {
        command = "bash";
        args = ["-c" "exec bunx context-mode@latest"];
      };
      Honcho = {
        command = "bash";
        args = [
          "-c"
          ''exec bunx mcp-remote@latest https://mcp.honcho.dev --header "Authorization:Bearer $(cat /run/agenix/honcho-key)" --header "X-Honcho-User-Name:m3tam3re"''
        ];
      };
    };
  };

  home.packages = with pkgs; [
    agenix-cli
    agent-browser
    beads
    pi
    (qmd.override {
      vulkanSupport = videoDrivers == ["amdgpu"];
      cudaSupport = videoDrivers == ["nvidia"];
    })
    openshell
    openspec
  ];
}
