skills

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MainFile = "SKILL.md"

Variables

This section is empty.

Functions

func SyncBuiltin added in v0.13.0

func SyncBuiltin(ctx context.Context, store *SQLiteStore, builtinFS fs.FS) error

SyncBuiltin imports or updates builtin skills from the embedded FS into the DB. Only scope='system' rows are created/updated; user/agent/project rows are never touched.

Called at server start (wiring happens in Phase 4; this function is exported for that use).

TODO(orphan-cleanup): Skills that exist in the DB as scope='system' but are absent from builtinFS are not deleted here. Phase 4+ should add an explicit tombstone pass once the full lifecycle is understood.

Types

type KnowledgeEntry added in v0.18.0

type KnowledgeEntry struct {
	ID            string
	Name          string
	Description   string
	Content       string // body text from SKILL.md
	KnowledgeType KnowledgeType
	Status        string // draft | active | deprecated
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

KnowledgeEntry is a fact or context entry derived from the skills table.

type KnowledgeStore added in v0.18.0

type KnowledgeStore interface {
	// ListKnowledge returns active knowledge entries for the given view context.
	// Pass knowledge types to filter; no types means all knowledge types.
	ListKnowledge(ctx context.Context, vc ViewContext, types ...KnowledgeType) ([]KnowledgeEntry, error)

	// ExpireKnowledgeDraftsByType deprecates draft knowledge entries of the given type
	// whose created-at timestamp is before the cutoff.
	ExpireKnowledgeDraftsByType(ctx context.Context, knowledgeType KnowledgeType, before time.Time) error
}

KnowledgeStore queries and manages knowledge entries (fact/context) stored in the skills table with disable_model_invocation=true. These entries never appear via the skills tool; they are injected into the ## Knowledge system prompt section.

type KnowledgeType added in v0.18.0

type KnowledgeType string

KnowledgeType classifies a knowledge entry.

const (
	KnowledgeTypeSkill   KnowledgeType = "skill"
	KnowledgeTypeFact    KnowledgeType = "fact"
	KnowledgeTypeContext KnowledgeType = "context"
)

type MigrateFSConfig added in v0.13.0

type MigrateFSConfig struct {
	// AnnaHome is intentionally unused: builtin (anna source) skills are handled
	// exclusively by SyncBuiltin, not by filesystem migration.
	AnnaHome      string
	AgentRoot     string
	UserRoot      string
	UserSkillsDir string
	// Owner fields used when creating scoped rows.
	UserID  int64
	AgentID string
}

MigrateFSConfig controls how on-disk skills are discovered and mapped to DB rows.

type MigrateFSResult added in v0.13.0

type MigrateFSResult struct {
	Imported int
	Skipped  int // already-in-DB duplicates
}

MigrateFSResult contains counts for a MigrateFilesystem run.

func MigrateFilesystem added in v0.13.0

func MigrateFilesystem(ctx context.Context, store *SQLiteStore, cfg MigrateFSConfig) (MigrateFSResult, error)

MigrateFilesystem reads on-disk skills and idempotently imports each into the DB.

Skills with source="anna" (builtin) are skipped — use SyncBuiltin for those. The function is safe to call multiple times; existing rows are counted as Skipped.

type SQLiteStore added in v0.13.0

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

SQLiteStore implements Store against a SQLite database via sqlc.

func New added in v0.13.0

func New(db *sql.DB) *SQLiteStore

New returns a new SQLiteStore. Callers may store it as a Store interface.

func (*SQLiteStore) Create added in v0.13.0

func (s *SQLiteStore) Create(ctx context.Context, sk Skill, files map[string]string) (string, error)

Create inserts the skill row and all its files in a transaction. The files map must include MainFile ("SKILL.md"). If s.ID is empty a new ID is generated.

func (*SQLiteStore) Delete added in v0.13.0

func (s *SQLiteStore) Delete(ctx context.Context, id string) error

Delete removes a skill and (via ON DELETE CASCADE) all its files.

func (*SQLiteStore) DeleteFile added in v0.13.0

func (s *SQLiteStore) DeleteFile(ctx context.Context, skillID, path string) error

DeleteFile removes a single file from a skill.

func (*SQLiteStore) ExpireDrafts added in v0.13.0

func (s *SQLiteStore) ExpireDrafts(ctx context.Context, before time.Time) error

ExpireDrafts deprecates all draft skills (disable_model_invocation=0) whose created-at metadata timestamp is before the given cutoff.

func (*SQLiteStore) ExpireKnowledgeDraftsByType added in v0.18.0

func (s *SQLiteStore) ExpireKnowledgeDraftsByType(ctx context.Context, knowledgeType KnowledgeType, before time.Time) error

ExpireKnowledgeDraftsByType deprecates draft knowledge entries of the given type whose created-at timestamp is before the cutoff.

func (*SQLiteStore) List added in v0.13.0

func (s *SQLiteStore) List(ctx context.Context, vc ViewContext) ([]Skill, error)

List returns all visible skills for the given context.

func (*SQLiteStore) ListAll added in v0.13.0

func (s *SQLiteStore) ListAll(ctx context.Context) ([]Skill, error)

ListAll returns every skill regardless of status, visibility, or scope filter.

func (*SQLiteStore) ListFiles added in v0.13.0

func (s *SQLiteStore) ListFiles(ctx context.Context, skillID string) ([]string, error)

ListFiles returns all file paths for a skill (no content).

func (*SQLiteStore) ListKnowledge added in v0.18.0

func (s *SQLiteStore) ListKnowledge(ctx context.Context, vc ViewContext, types ...KnowledgeType) ([]KnowledgeEntry, error)

ListKnowledge returns active knowledge entries for the given view context. Pass knowledge types to filter; no types means all.

func (*SQLiteStore) LoadFile added in v0.13.0

func (s *SQLiteStore) LoadFile(ctx context.Context, skillID, path string) (string, error)

LoadFile fetches a single file by path.

func (*SQLiteStore) Resolve added in v0.13.0

func (s *SQLiteStore) Resolve(ctx context.Context, name string, vc ViewContext) (*Skill, error)

Resolve finds the highest-priority visible skill by name.

func (*SQLiteStore) Update added in v0.13.0

func (s *SQLiteStore) Update(ctx context.Context, id string, patch UpdatePatch) error

Update patches metadata fields using read-modify-write.

func (*SQLiteStore) UpsertFile added in v0.13.0

func (s *SQLiteStore) UpsertFile(ctx context.Context, skillID, path, content string) error

UpsertFile creates or replaces a single file under a skill.

type Skill added in v0.13.0

type Skill struct {
	ID                     string
	Scope                  string // system | agent | user
	UserID                 int64
	AgentID                string
	Name                   string
	Description            string
	Status                 string // draft | active | deprecated
	DisableModelInvocation bool
	Metadata               json.RawMessage
	CreatedAt              time.Time
	UpdatedAt              time.Time
}

Skill represents a skill row (metadata only, no file content).

type Store added in v0.13.0

type Store interface {
	// List returns all visible skills for the given context (metadata only, no file content).
	List(ctx context.Context, vc ViewContext) ([]Skill, error)

	// ListAll returns every skill regardless of status or visibility (admin use only).
	ListAll(ctx context.Context) ([]Skill, error)

	// Resolve finds the highest-priority visible skill by name.
	// Priority: user > agent > system.
	Resolve(ctx context.Context, name string, vc ViewContext) (*Skill, error)

	// LoadFile fetches a single file by path. Pass MainFile ("SKILL.md") for the body.
	LoadFile(ctx context.Context, skillID, path string) (string, error)

	// ListFiles returns all file paths for a skill (no content).
	ListFiles(ctx context.Context, skillID string) ([]string, error)

	// Create inserts the skill row and all its files (must include "SKILL.md").
	Create(ctx context.Context, s Skill, files map[string]string) (string, error)

	// Update patches metadata fields. Use UpsertFile to change file content.
	Update(ctx context.Context, id string, patch UpdatePatch) error

	// UpsertFile creates or replaces a single file under a skill.
	UpsertFile(ctx context.Context, skillID, path, content string) error

	DeleteFile(ctx context.Context, skillID, path string) error
	Delete(ctx context.Context, id string) error

	// ExpireDrafts deprecates all draft skills (disable_model_invocation=0) whose
	// created-at timestamp is before the given cutoff. Knowledge entries are excluded.
	ExpireDrafts(ctx context.Context, before time.Time) error
}

Store is the persistence interface for skills.

type UpdatePatch added in v0.13.0

type UpdatePatch struct {
	Description            *string
	Status                 *string
	DisableModelInvocation *bool
	Metadata               json.RawMessage // optional; set to overwrite
}

UpdatePatch carries optional updates for a skill's metadata fields.

type ViewContext added in v0.13.0

type ViewContext struct {
	UserID  int64
	AgentID string
}

ViewContext describes who is asking and from where. Empty fields mean no such context (e.g. UserID=0 → only system skills visible).

Jump to

Keyboard shortcuts

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