plugins

package
v0.134.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package plugins implements installation and runtime surfacing of Claude Code-format plugins: SKILL.md skills plus an optional AGENTS.md instruction ruleset. Plugin code (hooks/, commands/) is never executed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapInstructions

func CapInstructions(content string, maxLines, maxChars int) (string, string)

CapInstructions bounds instruction-file content at maxLines lines, then at maxChars characters. Returns the capped content and a truncation marker ("" when nothing was cut).

func ClaudeCodeAppend

func ClaudeCodeAppend(cfg *config.Config) string

ClaudeCodeAppend composes the --append-system-prompt payload for Claude Code mode. The project AGENTS.md is excluded - the claude CLI reads it natively, so appending it would double-inject.

func Commit

func Commit(stagingDir, finalDir string, overwrite bool) error

Commit atomically promotes stagingDir to finalDir. On overwrite the old dir is trash-renamed first and restored if the promotion fails. Staging and final must share a filesystem so os.Rename is atomic.

func InstructionsBlock

func InstructionsBlock(cfg *config.Config) string

InstructionsBlock renders the enabled plugins' rulesets as labeled system prompt sections. Empty when no enabled plugin ships instructions.

func Uninstall

func Uninstall(name, root string) (string, error)

Uninstall removes the plugin folder named name from root. The name must match the plugin-name regex; missing folders are not an error.

Types

type InstallResult

type InstallResult struct {
	Name            string
	Version         string
	Description     string
	Skills          []domain.Skill
	SkillErrors     []domain.SkillLoadError
	HasInstructions bool
	InstructionsLen int
	Unsupported     map[string]int
}

InstallResult describes an inspected (staged or installed) plugin.

func Inspect

func Inspect(dir, fallbackName string) (*InstallResult, error)

Inspect validates a staged or installed plugin dir: manifest (optional, falling back to fallbackName), skills, and instruction-file presence. Errors when the plugin has no valid skill and no AGENTS.md.

type Installer

type Installer struct {
	Client  *http.Client
	APIBase string
	RawBase string
	Token   string
}

Installer downloads the mapped subset of a plugin repo from GitHub. Tests substitute APIBase / RawBase with httptest servers.

func NewInstaller

func NewInstaller() *Installer

NewInstaller returns an Installer pointed at github.com, authenticated via GITHUB_TOKEN / GH_TOKEN when set.

func (*Installer) Stage

func (i *Installer) Stage(ctx context.Context, src Source, stagingDir string) (map[string]int, error)

Stage materializes the mapped subset of src into stagingDir and returns the counts of unsupported component files. On error the caller removes stagingDir.

type Instruction

type Instruction struct {
	PluginName string
	Content    string
	Truncated  bool
	Marker     string
}

Instruction is one enabled plugin's AGENTS.md ruleset, capped for prompt injection.

func Instructions

func Instructions(cfg *config.Config) []Instruction

Instructions reads each enabled plugin's AGENTS.md in registry order, skipping plugins without one. Content is read verbatim (never through os.ExpandEnv) so plugin-controlled text cannot expand environment variables.

type Manifest

type Manifest struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Description string `json:"description"`
	Author      struct {
		Name string `json:"name"`
		URL  string `json:"url"`
	} `json:"author"`
	Hooks    any `json:"hooks,omitempty"`
	Commands any `json:"commands,omitempty"`
	MCP      any `json:"mcpServers,omitempty"`
}

Manifest is the Claude Code plugin manifest (.claude-plugin/plugin.json). The hooks/commands/mcpServers keys are parsed only to detect presence.

type Source

type Source struct {
	Kind  SourceKind
	Owner string
	Repo  string
	Ref   string
	Path  string
	Raw   string
}

Source is a parsed plugin install target.

func ParseSource

func ParseSource(raw string) (Source, error)

ParseSource accepts:

func (Source) EffectiveRef

func (s Source) EffectiveRef() string

EffectiveRef returns the git ref to fetch: the parsed ref, or HEAD (which GitHub resolves to the default branch).

type SourceKind

type SourceKind int

SourceKind distinguishes GitHub sources from local directories.

const (
	SourceGitHub SourceKind = iota
	SourceLocal
)

Jump to

Keyboard shortcuts

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