agent

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package agent installs Agent Skills declared in a project's go.mod into the local `.agents/skills` directory.

Skills are versioned with Go modules. A consuming project marks required skills on require statements; this package resolves those modules (including replace directives), creates symlinks under the project root, and appends matching entries to `.gitignore`.

How to Integrate

Annotate each skill-providing require dependency in go.mod with `// +skill:<name>` on the lines above it. One require may declare multiple skills.

module example.com/app

go 1.22

require (
	// +skill:genx
	github.com/xoctopus/genx v0.3.1
)

replace github.com/xoctopus/genx => ../genx

Then run Installer.Install from the project (or any subdirectory). The zero-value installer walks up to the nearest go.mod and installs all declared skills:

import (
	"context"
	"fmt"
	"os"

	"github.com/xoctopus/genx/pkg/agent"
)

func main() {
	if err := (&agent.Installer{}).Install(context.Background()); err != nil {
		_, _ = fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
		return
	}
}

Replace directives are honored: a local or absolute replace path is used as the module root; a module replace updates the resolved path and version.

SkillInstaller is a thin wrapper that calls Installer.Install with a zero-value installer. For more control, set Installer.Root or Installer.GoModCache before calling Install. Lower-level helpers ExtractSkillRefsFromGoMod, SkillDef.Installation, and SkillInstallationPlan are available when building a custom plan.

Skill Layout

Each skill module must ship its content at:

.agents/skills/<name>/

For example, genx provides `.agents/skills/genx/SKILL.md` with supporting references. After installation, the consuming project exposes the same path via a symlink:

<project>/.agents/skills/<name> -> <module-root>/.agents/skills/<name>

Installation Plan

SkillInstallationPlan produces a Plan that:

  1. Resolves each skill source under GOMODCACHE (`<path>@<version>`) or a replace path.
  2. Maps destinations to `<root>/.agents/skills/<name>`.
  3. Records gitignore lines as `skills/<name>`.

Plan.Apply creates the skills directory, replaces any existing destination with a symlink to the source, and appends missing gitignore entries.

Index

Constants

This section is empty.

Variables

View Source
var GOMODCACHE string

Functions

This section is empty.

Types

type Installer

type Installer struct {
	Root       string
	GoModFile  string
	GoModCache string
}

func (*Installer) Install

func (i *Installer) Install(ctx context.Context) error

type Plan

type Plan struct {
	SkillsDir     string
	GitIgnorePath string
	GitIgnores    []string
	Skills        []SkillInstall
}

func SkillInstallationPlan

func SkillInstallationPlan(root, gomodcache string, skills []SkillDef) (*Plan, error)

func (*Plan) Apply

func (p *Plan) Apply() error

type SkillDef

type SkillDef struct {
	Name    string
	Path    string
	Version string
	Replace string
}

func ExtractSkillRefsFromGoMod

func ExtractSkillRefsFromGoMod(path string) ([]SkillDef, error)

func (*SkillDef) Installation

func (s *SkillDef) Installation(dst, gomodcache string) (*SkillInstall, error)

type SkillInstall

type SkillInstall struct {
	Ref         SkillDef
	ModuleRoot  string
	Source      string
	Destination string
}

type SkillInstaller

type SkillInstaller struct{}

func (*SkillInstaller) Run

func (s *SkillInstaller) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL