skills

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package skills owns Skills: tenant-owned bundles with immutable, numbered versions and a default version. It holds their vocabulary, the identifier, version and selector rules, the version deletion rules, and the use cases behind the Skills API. persistence/postgres/skillpg implements its storage.

Index

Constants

View Source
const MaxPageLimit = 100

MaxPageLimit bounds every Skill and version page. A limit of 0 returns an empty page whose HasMore reports whether anything follows the cursor.

Variables

View Source
var (
	// ErrNotFound reports a Skill or version that does not exist in the tenant.
	// Malformed identifiers and other tenants' resources are indistinguishable
	// from missing ones.
	ErrNotFound = errors.New("skill not found")
	// ErrInvalidInput reports an invalid archive, version, page limit or tenant.
	ErrInvalidInput = errors.New("invalid skill request")
	// ErrDefaultVersion rejects deleting the default version while other
	// versions remain.
	ErrDefaultVersion = errors.New("cannot delete the default skill version")
)
View Source
var ErrInvalidVersion = errors.New("skill version must be a canonical positive decimal integer")

ErrInvalidVersion reports a version that is not a canonical positive decimal.

Functions

func FormatID

func FormatID(id uuid.UUID) string

FormatID returns the public ID of the Skill whose key is id.

func FormatVersionID

func FormatVersionID(id uuid.UUID) string

FormatVersionID returns the public ID of the version whose key is id.

func ParseID

func ParseID(value string) (uuid.UUID, error)

ParseID returns the key of a public Skill ID: "skill_" followed by a canonical, nonzero UUID. Any other value names no Skill and is ErrNotFound.

func ParseVersion

func ParseVersion(value string) (int64, error)

ParseVersion accepts only the canonical decimal spelling of a positive version number, so every version has exactly one text form. Selecting "latest" or an omitted version belongs to the caller.

func ParseVersionID

func ParseVersionID(value string) (uuid.UUID, error)

ParseVersionID returns the key of a public version ID ("skillver_").

func PathID

func PathID(value string) uuid.UUID

PathID resolves a Skill ID from a request path. A malformed value resolves to the maximum UUID, which Core never assigns, so the request follows exactly the missing-Skill path. Request-body references use ParseID.

func PathVersion

func PathVersion(value string) int64

PathVersion resolves a version number from a request path. Versions start at 1, so a malformed value resolves to the never-assigned version 0 and follows the missing-version path. Request-body selectors use ParseVersion.

func SelectVersion

func SelectVersion(selector string, defaultVersion, latestVersion int64) (int64, error)

SelectVersion resolves a Skill reference's version selector against the Skill's pointers: empty selects the default version, "latest" the latest, and any other value must be a concrete version.

func ValidateSelector

func ValidateSelector(selector string) error

ValidateSelector checks a version selector without resolving it.

func VerifyContent

func VerifyContent(content Content) error

VerifyContent checks that a decrypted archive is still the complete bundle its version records, before anything reads or installs it.

Types

type Content

type Content struct {
	Version Version
	Archive []byte
}

Content is a version and its archive.

type CreateSkill

type CreateSkill struct {
	TenantID string
	Archive  []byte
}

CreateSkill uploads a new Skill.

type CreateVersion

type CreateVersion struct {
	TenantID    string
	SkillID     uuid.UUID
	Archive     []byte
	MakeDefault bool
}

CreateVersion uploads a new version of a Skill.

type CursorError

type CursorError struct{ Message string }

CursorError reports a version list cursor that does not name a version of the listed Skill. Message is the official message for the case.

func (*CursorError) Error

func (e *CursorError) Error() string

type DeleteSkill

type DeleteSkill struct {
	TenantID string
	SkillID  uuid.UUID
}

DeleteSkill deletes a Skill and its versions. Session installations frozen from them are independent copies and remain.

type DeleteVersion

type DeleteVersion struct {
	TenantID string
	SkillID  uuid.UUID
	Version  int64
}

DeleteVersion deletes one version of a Skill.

type ListSkills

type ListSkills struct {
	TenantID  string
	After     string
	Limit     int
	Ascending bool
}

ListSkills lists the tenant's Skills. After is a Skill ID; a malformed or missing one is ErrNotFound.

type ListVersions

type ListVersions struct {
	TenantID  string
	SkillID   uuid.UUID
	After     string
	Limit     int
	Ascending bool
}

ListVersions lists a Skill's versions. After is a version ID, not a version number.

type NewSkill

type NewSkill struct {
	TenantID    string
	Name        string
	Description string
	Archive     []byte
}

NewSkill is a validated upload for a new Skill.

type NewVersion

type NewVersion struct {
	TenantID    string
	SkillID     uuid.UUID
	Name        string
	Description string
	Archive     []byte
	MakeDefault bool
}

NewVersion is a validated upload for an existing Skill. MakeDefault also points the Skill's default at the new version.

type Page

type Page struct {
	Skills  []Skill
	HasMore bool
}

Page is one page of Skills; HasMore reports whether any Skill follows it.

type ReadDefaultVersion

type ReadDefaultVersion struct {
	TenantID string
	SkillID  uuid.UUID
}

ReadDefaultVersion reads the archive of a Skill's default version, selecting the pointer and the content in one read.

type ReadVersion

type ReadVersion struct {
	TenantID string
	SkillID  uuid.UUID
	Version  int64
}

ReadVersion reads one version's archive.

type Reader

type Reader interface {
	Skill(ctx context.Context, tenantID string, id uuid.UUID) (Skill, error)
	// Skills lists one page of the tenant's Skills in creation order, then by
	// ID; a nil After starts at the first Skill.
	Skills(ctx context.Context, tenantID string, page SkillPageQuery) (Page, error)
	Version(ctx context.Context, tenantID string, skillID uuid.UUID, version int64) (Version, error)
	// VersionByID finds a version anywhere in the tenant, so a list cursor can
	// tell another Skill's version from a missing one.
	VersionByID(ctx context.Context, tenantID string, id uuid.UUID) (Version, error)
	// Versions lists one page of a Skill's versions in version order.
	Versions(ctx context.Context, tenantID string, skillID uuid.UUID, page VersionPageQuery) (VersionPage, error)
	// VersionContent and DefaultVersionContent decrypt one version's archive.
	VersionContent(ctx context.Context, tenantID string, skillID uuid.UUID, version int64) (Content, error)
	DefaultVersionContent(ctx context.Context, tenantID string, skillID uuid.UUID) (Content, error)
}

Reader reads Skills. Reads never lock and never decrypt metadata-only results.

type Service

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

Service runs the Skill use cases.

func NewService

func NewService(storage Storage, reader Reader) (*Service, error)

func (*Service) CreateSkill

func (s *Service) CreateSkill(ctx context.Context, c CreateSkill) (Skill, error)

CreateSkill validates the archive and stores it as the new Skill's version 1.

func (*Service) CreateVersion

func (s *Service) CreateVersion(ctx context.Context, c CreateVersion) (Version, error)

CreateVersion validates the archive before looking up the Skill, then stores it under the Skill's next version number.

func (*Service) DeleteSkill

func (s *Service) DeleteSkill(ctx context.Context, c DeleteSkill) error

func (*Service) DeleteVersion

func (s *Service) DeleteVersion(ctx context.Context, c DeleteVersion) (Version, error)

DeleteVersion decides under the Skill's lock, so it serializes with uploads and pointer changes, and returns the deleted version.

func (*Service) ListSkills

func (s *Service) ListSkills(ctx context.Context, c ListSkills) (Page, error)

func (*Service) ListVersions

func (s *Service) ListVersions(ctx context.Context, c ListVersions) (VersionPage, error)

ListVersions resolves the Skill before the cursor. A cursor that is not a version ID is a CursorError; a missing version, including another tenant's, is ErrNotFound; another Skill's version in the tenant is a CursorError. The Skill is looked up again before that last error, so a Skill deleted in between stays not found.

func (*Service) ReadDefaultVersion

func (s *Service) ReadDefaultVersion(ctx context.Context, c ReadDefaultVersion) (Content, error)

func (*Service) ReadVersion

func (s *Service) ReadVersion(ctx context.Context, c ReadVersion) (Content, error)

func (*Service) SetDefaultVersion

func (s *Service) SetDefaultVersion(ctx context.Context, c SetDefaultVersion) (Skill, error)

type SetDefaultVersion

type SetDefaultVersion struct {
	TenantID string
	SkillID  uuid.UUID
	Version  string
}

SetDefaultVersion points a Skill's default at one of its versions. Version is the request's selector and must be a concrete version number.

type Skill

type Skill struct {
	ID             string
	Name           string
	Description    string
	CreatedAt      time.Time
	DefaultVersion int64
	LatestVersion  int64
}

Skill is a tenant-owned Skill. Its name and description are those of its default version.

type SkillCursor

type SkillCursor struct {
	CreatedAt time.Time
	ID        uuid.UUID
}

SkillCursor is the position of the Skill a page starts after.

type SkillPageQuery

type SkillPageQuery struct {
	After     *SkillCursor
	Limit     int
	Ascending bool
}

SkillPageQuery selects one page of Skills. Limit is at most MaxPageLimit.

type Storage

type Storage interface {
	// CreateSkill stores a new Skill with the archive as its version 1, which
	// is both its default and latest version.
	CreateSkill(context.Context, NewSkill) (Skill, error)
	// CreateVersion locks the Skill and stores the archive under the Skill's
	// next version number. It is ErrNotFound for a missing Skill and
	// ErrInvalidInput once the version numbers are exhausted.
	CreateVersion(context.Context, NewVersion) (Version, error)
	// SetDefaultVersion locks the Skill and points its default at an existing
	// version, whose name and description the Skill then takes.
	SetDefaultVersion(ctx context.Context, tenantID string, skillID uuid.UUID, version int64) (Skill, error)
	// DeleteSkill deletes the Skill and all its versions.
	DeleteSkill(ctx context.Context, tenantID string, skillID uuid.UUID) error
	// WithVersionDeletion locks the Skill, or is ErrNotFound, and runs apply
	// in that transaction. It commits only when apply returns nil.
	WithVersionDeletion(ctx context.Context, tenantID string, skillID uuid.UUID, apply func(VersionDeletionTx) error) error
}

Storage persists Skill writes. Each method, and each WithVersionDeletion callback, runs in one transaction that also records the write's audit. Tenant IDs are UUIDs; a malformed one is ErrInvalidInput.

type Version

type Version struct {
	ID          string
	SkillID     string
	Version     int64
	Name        string
	Description string
	CreatedAt   time.Time
}

Version is one immutable version of a Skill. Version numbers start at 1 and are never reused.

type VersionDeletion

type VersionDeletion struct {
	Target        Version
	DeleteSkill   bool
	RefreshLatest bool
}

VersionDeletion is a decided version deletion. DeleteSkill deletes the whole Skill, whose only version Target is; otherwise only Target is deleted and RefreshLatest moves the latest pointer to the highest remaining version.

func DecideVersionDeletion

func DecideVersionDeletion(facts VersionDeletionFacts) (VersionDeletion, error)

DecideVersionDeletion applies the deletion rules. The default version can be deleted only as the Skill's sole version, and that deletes the Skill itself; Session installations frozen from it are independent copies.

type VersionDeletionFacts

type VersionDeletionFacts struct {
	Skill  Skill
	Target Version
	// OthersRemain reports whether the Skill has a version besides Target.
	OthersRemain bool
}

VersionDeletionFacts is what a version deletion decides from, loaded under the Skill's lock.

type VersionDeletionTx

type VersionDeletionTx interface {
	// LoadVersionDeletion loads the facts DecideVersionDeletion needs. It is
	// ErrNotFound when the Skill has no such version.
	LoadVersionDeletion(version int64) (VersionDeletionFacts, error)
	// ApplyVersionDeletion carries out a decided deletion.
	ApplyVersionDeletion(VersionDeletion) error
}

VersionDeletionTx is one locked Skill during a version deletion.

type VersionPage

type VersionPage struct {
	Versions []Version
	HasMore  bool
}

VersionPage is one page of a Skill's versions.

type VersionPageQuery

type VersionPageQuery struct {
	AfterVersion int64
	Limit        int
	Ascending    bool
}

VersionPageQuery selects one page of versions after the version number AfterVersion, or from the first when it is 0.

Jump to

Keyboard shortcuts

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