skill

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package skill provides skill management for GenCode. Skills are markdown-based prompts that can be invoked via slash commands or proactively by the model when active.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(cwd string) error

Initialize loads all skills and applies persisted states. This should be called at application startup.

Types

type InstalledPluginsData

type InstalledPluginsData struct {
	Version int                        `json:"version"`
	Plugins map[string][]PluginInstall `json:"plugins"`
}

InstalledPluginsData represents the installed_plugins.json structure.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader handles loading skills from multiple directories.

func NewLoader

func NewLoader(cwd string) *Loader

NewLoader creates a new skill loader.

func (*Loader) LoadAll

func (l *Loader) LoadAll() (map[string]*Skill, error)

LoadAll loads all skills from all directories. Higher priority scopes override lower priority ones with the same name.

type PluginInstall

type PluginInstall struct {
	Scope       string `json:"scope"`       // "user" or "project"
	InstallPath string `json:"installPath"` // Full path to plugin
	Version     string `json:"version"`
}

PluginInstall represents a single plugin installation.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages loaded skills and their states.

var DefaultRegistry *Registry

DefaultRegistry is the global skill registry instance.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the total number of loaded skills.

func (*Registry) FindByPartialName added in v1.2.0

func (r *Registry) FindByPartialName(name string) *Skill

FindByPartialName finds a skill by partial name match. It tries exact match first, then checks if name is a suffix (e.g., "commit" matches "git:commit").

func (*Registry) Get

func (r *Registry) Get(name string) (*Skill, bool)

Get returns a skill by name.

func (*Registry) GetActive

func (r *Registry) GetActive() []*Skill

GetActive returns all active skills (model-aware).

func (*Registry) GetAvailableSkillsPrompt

func (r *Registry) GetAvailableSkillsPrompt() string

GetAvailableSkillsPrompt generates the available skills section for the system prompt. Only includes active skills (state = active). Uses progressive loading: only name + description are included here. Full instructions are loaded when the Skill tool is invoked. Returns content wrapped in <available-skills> XML tags for consistency.

func (*Registry) GetEnabled

func (r *Registry) GetEnabled() []*Skill

GetEnabled returns all enabled or active skills.

func (*Registry) GetSkillInvocationPrompt

func (r *Registry) GetSkillInvocationPrompt(name string) string

GetSkillInvocationPrompt returns the full skill content wrapped in XML for injection. The name should be the full name (namespace:name or just name).

func (*Registry) GetStatesAt

func (r *Registry) GetStatesAt(userLevel bool) map[string]SkillState

GetStatesAt returns skill states from the specified level.

func (*Registry) List

func (r *Registry) List() []*Skill

List returns all skills sorted by full name (namespace:name).

func (*Registry) SetState

func (r *Registry) SetState(name string, state SkillState, userLevel bool) error

SetState sets the state for a skill and persists it to the specified level. The name should be the full name (namespace:name or just name). If userLevel is true, saves to ~/.gen/skills.json, otherwise to .gen/skills.json.

type Skill

type Skill struct {
	// Frontmatter fields (parsed from YAML header)
	Name         string   `yaml:"name"`
	Namespace    string   `yaml:"namespace"` // Optional namespace (e.g., "git", "jira")
	Description  string   `yaml:"description"`
	AllowedTools []string `yaml:"allowed-tools"`
	ArgumentHint string   `yaml:"argument-hint"`

	// Runtime fields
	FilePath     string     // Full path to the skill file
	SkillDir     string     // Directory containing the skill
	Scope        SkillScope // Where the skill was loaded from
	Instructions string     // Full markdown content (lazy loaded)
	State        SkillState // Current state (persisted separately)

	// Resource directories (Agent Skills spec)
	Scripts    []string // Files in scripts/ directory
	References []string // Files in references/ directory
	Assets     []string // Files in assets/ directory
	// contains filtered or unexported fields
}

Skill represents a loaded skill with metadata and instructions.

func (*Skill) FullName

func (s *Skill) FullName() string

FullName returns the namespaced skill name (namespace:name or just name).

func (*Skill) GetAssetPath added in v1.2.0

func (s *Skill) GetAssetPath(name string) string

GetAssetPath returns the full path to an asset file.

func (*Skill) GetInstructions

func (s *Skill) GetInstructions() string

GetInstructions returns the full skill instructions, loading if needed.

func (*Skill) GetReferencePath added in v1.2.0

func (s *Skill) GetReferencePath(name string) string

GetReferencePath returns the full path to a reference file.

func (*Skill) GetScriptPath added in v1.2.0

func (s *Skill) GetScriptPath(name string) string

GetScriptPath returns the full path to a script file.

func (*Skill) HasResources added in v1.2.0

func (s *Skill) HasResources() bool

HasResources returns true if the skill has any bundled resources.

func (*Skill) IsActive

func (s *Skill) IsActive() bool

IsActive returns true if the skill is active (model aware).

func (*Skill) IsEnabled

func (s *Skill) IsEnabled() bool

IsEnabled returns true if the skill is enabled or active.

type SkillScope

type SkillScope int

SkillScope represents where a skill was loaded from. Higher values have higher priority.

const (
	// ScopeClaudeUser is ~/.claude/skills/ (lowest priority, Claude compatibility)
	ScopeClaudeUser SkillScope = iota

	// ScopeUserPlugin is ~/.gen/plugins/*/skills/ (User plugins)
	ScopeUserPlugin

	// ScopeUser is ~/.gen/skills/ (GenCode user level)
	ScopeUser

	// ScopeClaudeProject is .claude/skills/ (Claude project compatibility)
	ScopeClaudeProject

	// ScopeProjectPlugin is .gen/plugins/*/skills/ (Project plugins)
	ScopeProjectPlugin

	// ScopeProject is .gen/skills/ (GenCode project level, highest priority)
	ScopeProject
)

func (SkillScope) String

func (s SkillScope) String() string

String returns the display name for the scope.

type SkillState

type SkillState string

SkillState represents the state of a skill. Three states control visibility and model awareness.

const (
	// StateDisable means the skill is hidden and not available.
	StateDisable SkillState = "disable"

	// StateEnable means the skill is visible as a slash command but the model
	// is not aware of it (user-invoked only).
	StateEnable SkillState = "enable"

	// StateActive means the skill metadata is included in the system prompt
	// and the model can invoke it proactively.
	StateActive SkillState = "active"
)

func (SkillState) Icon

func (s SkillState) Icon() string

StateIcon returns the display icon for the state.

func (SkillState) NextState

func (s SkillState) NextState() SkillState

NextState cycles through states: disable -> enable -> active -> disable.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store handles persistence of skill states to a skills.json file.

func NewProjectStore

func NewProjectStore(cwd string) (*Store, error)

NewProjectStore creates a store for project-level settings (.gen/skills.json).

func NewStore

func NewStore(path string) (*Store, error)

NewStore creates a new store for skill state persistence at the given path.

func NewUserStore

func NewUserStore() (*Store, error)

NewUserStore creates a store for user-level settings (~/.gen/skills.json).

func (*Store) GetState

func (s *Store) GetState(name string) (SkillState, bool)

GetState returns the persisted state for a skill.

func (*Store) SetState

func (s *Store) SetState(name string, state SkillState) error

SetState sets and persists the state for a skill.

type StoreData

type StoreData struct {
	Skills map[string]SkillState `json:"skills"`
}

StoreData is the JSON structure for skills.json.

Jump to

Keyboard shortcuts

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