skill

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExtractionCandidateStatusPending  ExtractionCandidateStatus = "pending"
	ExtractionCandidateStatusApproved ExtractionCandidateStatus = "approved"
	ExtractionCandidateStatusRejected ExtractionCandidateStatus = "rejected"

	ExtractionCandidateActionApprove  ExtractionCandidateAction = "approve"
	ExtractionCandidateActionEvaluate ExtractionCandidateAction = "evaluate"
	ExtractionCandidateActionPromote  ExtractionCandidateAction = "promote"
	ExtractionCandidateActionRollback ExtractionCandidateAction = "rollback"
	ExtractionCandidateActionReject   ExtractionCandidateAction = "reject"
)

Variables

View Source
var ErrPromoteConflict = errors.New("workspace skill already exists")

ErrPromoteConflict is returned when OnConflict=abort and a workspace skill of the same name already exists.

Functions

func ExtractionInboxPath added in v0.31.110

func ExtractionInboxPath(root string) string

func FormatAvailableSkills

func FormatAvailableSkills(skills []Definition) string

func LoadCommandAliases added in v0.31.165

func LoadCommandAliases(dir string, available []Definition) ([]Definition, []Diagnostic)

LoadCommandAliases is kept for older call sites. New code should prefer LoadCommands; command files are now standalone prompts, not skill aliases.

func LoadCommands added in v0.31.179

func LoadCommands(dir string) ([]Definition, []Diagnostic)

LoadCommands walks dir for *.md command files and returns standalone, explicit slash commands. The command name is derived from the basename without the .md suffix — e.g. `commands/refactor.md` registers `/refactor`.

Commands are intentionally not aliases for skills. Even if a legacy file still contains `target_skill`, the file's own body remains the command prompt. A missing dir is treated as a no-op (no error, no diagnostics).

Types

type AvailabilityOptions added in v0.10.3

type AvailabilityOptions struct {
	OS               string
	Arch             string
	InstalledPlugins []string
	HasEnv           func(string) bool
	HasCommand       func(string) bool
}

type Definition

type Definition struct {
	Name                    string   `json:"name"`
	Description             string   `json:"description"`
	Slash                   string   `json:"slash,omitempty"`
	Aliases                 []string `json:"aliases,omitempty"`
	UserInvocable           bool     `json:"user_invocable"`
	Source                  Source   `json:"source"`
	FilePath                string   `json:"file_path"`
	RuntimePath             string   `json:"runtime_path,omitempty"`
	RequiresPlugin          string   `json:"requires_plugin,omitempty"`
	RequiresBins            []string `json:"requires_bins,omitempty"`
	RequiresEnv             []string `json:"requires_env,omitempty"`
	OS                      []string `json:"os,omitempty"`
	Arch                    []string `json:"arch,omitempty"`
	RecommendedTools        []string `json:"recommended_tools,omitempty"`
	RecommendedProjectFiles []string `json:"recommended_project_files,omitempty"`
	WakePhases              []string `json:"wake_phases,omitempty"`
	Tags                    []string `json:"tags,omitempty"`
	SmokeTests              []string `json:"smoke_tests,omitempty"`
	Content                 string   `json:"content,omitempty"`
}

type Diagnostic

type Diagnostic struct {
	Path    string `json:"path,omitempty"`
	Message string `json:"message"`
}

type ExtractionCandidate added in v0.31.110

type ExtractionCandidate struct {
	ID               string                    `json:"id"`
	Status           ExtractionCandidateStatus `json:"status"`
	Name             string                    `json:"name"`
	Title            string                    `json:"title"`
	Trigger          string                    `json:"trigger"`
	Summary          string                    `json:"summary"`
	UseCase          string                    `json:"use_case"`
	RecommendedTools []string                  `json:"recommended_tools,omitempty"`
	SourceSession    string                    `json:"source_session,omitempty"`
	MessageRange     string                    `json:"message_range,omitempty"`
	RepeatedCount    int                       `json:"repeated_count,omitempty"`
	Evidence         []ExtractionEvidence      `json:"evidence,omitempty"`
	Signals          []ExtractionSignal        `json:"signals,omitempty"`
	Provenance       ExtractionProvenance      `json:"provenance"`
	CreatedAt        time.Time                 `json:"created_at"`
	UpdatedAt        time.Time                 `json:"updated_at"`
	ReviewedAt       time.Time                 `json:"reviewed_at,omitempty"`
	DraftPath        string                    `json:"draft_path,omitempty"`
	DraftName        string                    `json:"draft_name,omitempty"`
}

func AppendExtractionCandidatesIfNew added in v0.31.110

func AppendExtractionCandidatesIfNew(root string, candidates []ExtractionCandidate) ([]ExtractionCandidate, bool, error)

func DetectExtractionCandidates added in v0.31.110

func DetectExtractionCandidates(sess session.Session, messages []session.Message, opts ExtractionOptions) []ExtractionCandidate

func FindExtractionCandidate added in v0.31.110

func FindExtractionCandidate(root string, id string) (ExtractionCandidate, error)

func ListExtractionCandidates added in v0.31.110

func ListExtractionCandidates(root string, opts ExtractionCandidateListOptions) ([]ExtractionCandidate, error)

func ReviewExtractionCandidate added in v0.31.110

func ReviewExtractionCandidate(root string, id string, review ExtractionCandidateReview) (ExtractionCandidate, error)

type ExtractionCandidateAction added in v0.31.110

type ExtractionCandidateAction string

type ExtractionCandidateListOptions added in v0.31.110

type ExtractionCandidateListOptions struct {
	Status ExtractionCandidateStatus
}

type ExtractionCandidateReview added in v0.31.110

type ExtractionCandidateReview struct {
	Action    ExtractionCandidateAction `json:"action"`
	DraftPath string                    `json:"draft_path,omitempty"`
	DraftName string                    `json:"draft_name,omitempty"`
	Note      string                    `json:"note,omitempty"`
}

type ExtractionCandidateStatus added in v0.31.110

type ExtractionCandidateStatus string

type ExtractionEvidence added in v0.31.110

type ExtractionEvidence struct {
	MessageID string `json:"message_id,omitempty"`
	Index     int    `json:"index"`
	Role      string `json:"role"`
	Snippet   string `json:"snippet"`
}

type ExtractionOptions added in v0.31.110

type ExtractionOptions struct {
	Now           time.Time
	MaxCandidates int
}

type ExtractionProvenance added in v0.31.110

type ExtractionProvenance struct {
	Source        string    `json:"source,omitempty"`
	SessionID     string    `json:"session_id,omitempty"`
	MessageRange  string    `json:"message_range,omitempty"`
	SourceSummary string    `json:"source_summary,omitempty"`
	ExtractedAt   time.Time `json:"extracted_at,omitempty"`
}

type ExtractionSignal added in v0.35.0

type ExtractionSignal struct {
	Kind      ExtractionSignalKind `json:"kind"`
	MessageID string               `json:"message_id,omitempty"`
	Index     int                  `json:"index"`
	Role      string               `json:"role"`
	Snippet   string               `json:"snippet"`
}

func DetectExtractionSignals added in v0.35.0

func DetectExtractionSignals(messages []session.Message) []ExtractionSignal

type ExtractionSignalKind added in v0.35.0

type ExtractionSignalKind string
const (
	ExtractionSignalSuccess        ExtractionSignalKind = "success"
	ExtractionSignalFailure        ExtractionSignalKind = "failure"
	ExtractionSignalDeadEnd        ExtractionSignalKind = "dead_end"
	ExtractionSignalUserCorrection ExtractionSignalKind = "user_correction"
)

type Frontmatter

type Frontmatter struct {
	Name                    string
	Description             string
	Slash                   string
	Aliases                 []string
	UserInvocable           *bool
	RequiresPlugin          string
	RequiresBins            []string
	RequiresEnv             []string
	OS                      []string
	Arch                    []string
	RecommendedTools        []string
	RecommendedProjectFiles []string
	WakePhases              []string
	Tags                    []string
	SmokeTests              []string
	// TargetSkill is a legacy command frontmatter field retained for
	// compatibility while command files are loaded as standalone prompts.
	TargetSkill string
}

func ParseFrontmatter

func ParseFrontmatter(raw string) (Frontmatter, string, error)

type LoadOptions

type LoadOptions struct {
	Sources      []SourceDir
	Availability AvailabilityOptions
}

type PromoteAction added in v0.32.23

type PromoteAction string

PromoteAction describes the outcome relative to the requested name.

const (
	PromoteActionCreated     PromoteAction = "created"
	PromoteActionOverwritten PromoteAction = "overwritten"
	PromoteActionRenamed     PromoteAction = "renamed"
)

type PromoteConflictPolicy added in v0.32.23

type PromoteConflictPolicy string

PromoteConflictPolicy decides what happens when a workspace skill with the same name already exists at the target location.

const (
	PromoteOnConflictRename    PromoteConflictPolicy = "rename"
	PromoteOnConflictOverwrite PromoteConflictPolicy = "overwrite"
	PromoteOnConflictAbort     PromoteConflictPolicy = "abort"
)

type PromoteMode added in v0.32.23

type PromoteMode string

PromoteMode controls whether the source skill directory is preserved after a successful copy.

const (
	PromoteModeCopy PromoteMode = "copy"
	PromoteModeMove PromoteMode = "move"
)

type PromoteRequest added in v0.32.23

type PromoteRequest struct {
	SourceSkillsRoot string // <cwd>/.tars/skills
	TargetSkillsRoot string // ${workspaceDir}/skills
	Name             string
	Mode             PromoteMode
	OnConflict       PromoteConflictPolicy
}

PromoteRequest copies a session-local skill directory into the shared workspace skills root. The on-disk source is computed as safeJoinUnder(SourceSkillsRoot, Name) — the caller does not get to supply the full source path, which prevents path-traversal attacks from flowing through `Name` into filesystem operations.

type PromoteResult added in v0.32.23

type PromoteResult struct {
	RequestedName string        `json:"requested_name"`
	TargetName    string        `json:"target_name"`
	TargetPath    string        `json:"target_path"`
	Action        PromoteAction `json:"action"`
	SourceDeleted bool          `json:"source_deleted"`
}

PromoteResult captures the chosen target name + final on-disk action.

func Promote added in v0.32.23

func Promote(req PromoteRequest) (PromoteResult, error)

Promote copies (or moves) a session-local skill directory into the workspace skills root, applying the requested conflict policy.

type Snapshot

type Snapshot struct {
	Version     int64        `json:"version"`
	Skills      []Definition `json:"skills"`
	Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
}

func Load

func Load(opts LoadOptions) (Snapshot, error)

func MirrorToWorkspace

func MirrorToWorkspace(workspaceDir string, snapshot Snapshot) (Snapshot, error)

type Source

type Source string
const (
	SourceWorkspace Source = "workspace"
	SourceUser      Source = "user"
	SourceBundled   Source = "bundled"
	// SourceSessionCwd identifies skills and commands discovered
	// under `<active_cwd>/.tars/skills/` and `<active_cwd>/.tars/commands/`.
	// In the loader's last-write-wins ordering this source is appended
	// after all others, so a cwd-local skill with the same name as a
	// bundled or user skill always wins.
	SourceSessionCwd Source = "session_cwd"
)

type SourceDir

type SourceDir struct {
	Source Source
	Dir    string
}

Jump to

Keyboard shortcuts

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