agent-skills-nix

repository·master·Indexed 41 days ago

https://github.com/kyure-a/agent-skills-nix

A tool for the declarative management of Agent Skills (directories containing SKILL.md) using Nix flakes. It enables discovery, selection, and automated syncing of skills to agent-specific runtime destinations such as Claude, Copilot, and Cursor. It includes features for managing skill repositories via a Source Registry with npins, exporting skills as OpenAI-compatible Agent Plugins, and providing Home Manager modules for system-wide skill configuration.

Tokens
4.7K
Snippets
14
Records
25
Agent score
53%

What's inside agent-skills-nix

  1. Explore agent-skills-nix usage examples

    master

    The examples/ directory provides several use-case-oriented patterns for implementing agent-skills-nix in your projects:

    • Quickstart patterns: Demonstrates two ways to structure skills: a main pattern where skills are tightly coupled, and a child pattern where skills are organized into a separated catalog.
    • Library functions: Shows how to use the project's internal library helpers directly.
    • Agent Plugin export: Demonstrates how to export a selection of skills as a self-contained, skills-only Agent Plugin (experimental).
    • Skill customization: Provides examples of using transform and packages to customize skill behavior.
    • Local installation: Shows how to create a project-local install app using mkLocalInstallProgram.
    • Development shell: Demonstrates auto-installing dependencies within a development shell using mkShellHook.
    • Source registry: Explains how to use per-source manifests combined with an npins JSON lock to manage skills without requiring a separate flake input for every skill repository.
  2. Core Concepts of agent-skills-nix

    master

    agent-skills-nix provides declarative management of Agent Skills (directories containing a SKILL.md file). Key abstractions include:

    • sources: Named inputs or paths pointing to a skills root (subdir). You can use idPrefix to namespace discovered skill IDs to prevent collisions.
    • discover: A process that recursively scans sources for SKILL.md files to produce a catalog. Nested skills use / as a separator (e.g., ecosystem/c-ecosystem/).
    • Selection: Skills are picked using skills.enable (specific list), skills.enableAll (global or by source), or skills.explicit (restricts installation to named targets).
    • Agent Plugin export: A mechanism to map catalog entries to portable names and produce a self-contained, skills-only plugin directory.
    • targets: Agent-specific destinations (e.g., claude, copilot, cursor) where skills are synced. Targets are opt-in and use different sync structures (link, symlink-tree, or copy-tree).
  3. Handle symlinks inside skills

    master

    The synchronization process handles symlinks within skill directories based on their targets:

    • Allowed: Symlinks whose textual target stays inside the declared source root (e.g., ../shared to a sibling at the root) are preserved.
    • Dropped: Symlinks whose target escapes the root are dropped, along with any dangling links created by that drop.

    To ensure symlinks work correctly, keep them source-root-relative. The entire source root is imported into the Nix store, so you can scope the source via path = ./skills or subdir to avoid importing heavy unrelated trees like .git.

  4. Transform SKILL.md content and add package dependencies

    master

    Explicit skills can use transform and packages to customize the SKILL.md file and include binary dependencies.

    • packages: A list of packages to include. By default, these are added as a markdown table of dependencies in SKILL.md and symlinked into the skill directory (e.g., ./jq).
    • transform: A function to modify the SKILL.md content. It receives two arguments:
      • original: The original SKILL.md content.
      • dependencies: A markdown table of package dependencies with local paths.

    Example Output Structure:

    my-skill/
    ├── SKILL.md
    ├── jq -> /nix/store/xxx-jq/bin/jq
    └── curl/ -> /nix/store/xxx-curl/bin/
  5. Restrict skills to specific agents

    master

    You can use the agents option on an explicit skill to control which named targets receive it. This is useful for deploying different skill sets to different AI agents (e.g., Claude vs. Codex).

    • agents = [ "agent-name" ];: Only that agent receives the skill.
    • agents = null; or omitted: The skill is sent to every enabled target on the system.
    • agents = [];: The skill is included in the full bundle but installed nowhere.

    Note: If any selected skill has a non-null agents list, you cannot use AGENT_SKILLS_DESTS or AGENT_SKILLS_LOCAL_DESTS environment variables to override destinations, as those variables do not identify a specific target.

    programs.agent-skills = {
      targets.claude.enable = true;
      targets.codex.enable = true;
      targets.pi.enable = true;
    
      skills.explicit = {
        writing = {
          from = "my-source";
          agents = [ "claude" "codex" ];
        };
        pi-tools = {
          from = "my-source";
          agents = [ "pi" ];
        };
        shared = {
          from = "my-source";
        };
      };
    };
  6. Install skills locally in a project

    master

    To manage skills within a specific project directory, follow these steps:

    1. Configure your flake: Use mkLocalInstallProgram in your project's flake.
    2. Run the installer: Execute nix run .#skills-install-local from your project root. This installs skills to enabled local targets in the Default target paths.
    3. Automate with devShell: Use mkShellHook in your flake to automatically install skills whenever you enter the development shell via nix develop.

    Environment Variables:

    • AGENT_SKILLS_LOCAL_DESTS: Override local destinations (replaces destinations in target-name order).
    • AGENT_SKILLS_QUIET=1: Suppress synchronization output.
    • AGENT_SKILLS_FORCE=1: Force the synchronizer to take over a non-empty, unmarked directory.
  7. Use the Source Registry with npins

    master

    The source registry allows you to manage skill repositories without declaring every one as a flake input. It uses npins for revision resolution and hashing.

    1. Create Manifests: Maintain human-edited Nix manifests in a registry/sources/ directory.
    2. Define Pins: Use pin.type (github, git, or tarball). For GitHub, specify owner, repo, and branch.
    3. Generate Lock: Use the skills-sources-lock app to resolve pins and generate registry/sources.lock.json.
    4. Load in Nix: Use agentLib.sourcesFromLock to load the registry.

    Example manifest (registry/sources/anthropic.nix):

    {
      pin = {
        type = "github";
        owner = "anthropics";
        repo = "skills";
        branch = "main";
      };
    
      subdir = "skills";
      idPrefix = "anthropic";
      filter.maxDepth = 2;
    }

    Example loading in your configuration:

    sources = agentLib.sourcesFromLock {
      manifestsDir = ./registry/sources;
      lockFile = ./registry/sources.lock.json;
    };
    
    catalog = agentLib.discoverCatalog sources;
    # registry/sources/anthropic.nix
    {
      pin = {
        type = "github";
        owner = "anthropics";
        repo = "skills";
        branch = "main";
      };
    
      subdir = "skills";
      idPrefix = "anthropic";
      filter.maxDepth = 2;
    }
  8. Install skills globally via Home Manager

    master

    To manage skills globally on your system using Home Manager, use the following commands:

    • List available skills: nix run .#skills-list
    • Sync bundle to $HOME: nix run .#skills-install

    To override the default destinations for an unrestricted bundle, use the AGENT_SKILLS_DESTS environment variable with space-separated paths:

    AGENT_SKILLS_DESTS="~/tmp/skills1 ~/tmp/skills2" nix run .#skills-install
  9. Use the 'child' pattern for a separated skills catalog

    master
    The child pattern decouples your project from the skills management. The project-level flake.nix only depends on a skills-catalog (e.g., skills-catalog = path:./skills). The actual agent-skills and skill source inputs are then owned and managed by a nested flake located within the skills directory (e.g., child/skills/flake.nix).
  10. Build an Agent Plugin with a local agent-skills-nix checkout

    master

    If you are making changes to the agent-skills-nix repository itself and want to test them within the Agent Plugin example, use the --override-input flag to point the agent-skills input to your local directory instead of the remote GitHub source.

    nix build --no-write-lock-file --override-input agent-skills path:../.. .#agent-plugin