Documentation
¶
Overview ¶
Package store persists user-managed skills under the Leros workspace.
Index ¶
- Constants
- Variables
- func DefaultSkillRoot() (string, error)
- type CreateRequest
- type DeleteRequest
- type EditRequest
- type InstallRequest
- type MutationHandler
- type MutationKind
- type PatchRequest
- type RemoveFileRequest
- type Result
- type Skill
- type SkillError
- type SkillMetadata
- type SkillStore
- func (s *SkillStore) Create(ctx context.Context, req CreateRequest) (*Result, error)
- func (s *SkillStore) Delete(ctx context.Context, req DeleteRequest) (*Result, error)
- func (s *SkillStore) Edit(ctx context.Context, req EditRequest) (*Result, error)
- func (s *SkillStore) Find(ctx context.Context, name string) (*Skill, error)
- func (s *SkillStore) Install(ctx context.Context, req InstallRequest) (*Result, error)
- func (s *SkillStore) Patch(ctx context.Context, req PatchRequest) (*Result, error)
- func (s *SkillStore) RemoveFile(ctx context.Context, req RemoveFileRequest) (*Result, error)
- func (s *SkillStore) RootDir() string
- func (s *SkillStore) WriteFile(ctx context.Context, req WriteFileRequest) (*Result, error)
- type WriteFileRequest
Constants ¶
const ( ActionCreate = "create" ActionPatch = "patch" ActionEdit = "edit" ActionDelete = "delete" ActionWriteFile = "write_file" ActionRemoveFile = "remove_file" )
Variables ¶
var ( ErrSkillExists = &SkillError{Code: "skill_exists", Message: "skill already exists"} ErrSkillNotFound = &SkillError{Code: "skill_not_found", Message: "skill not found"} ErrSkillIsBuiltin = &SkillError{Code: "skill_is_builtin", Message: "cannot uninstall built-in skill"} ErrNameInvalid = &SkillError{Code: "name_invalid", Message: "invalid skill name"} ErrDocumentInvalid = &SkillError{Code: "document_invalid", Message: "invalid skill document"} ErrPatchNoMatch = &SkillError{Code: "patch_no_match", Message: "old_text was not found"} ErrPatchAmbiguous = &SkillError{Code: "patch_ambiguous", Message: "old_text matched multiple locations"} ErrPathInvalid = &SkillError{Code: "path_invalid", Message: "invalid file path"} )
预定义 sentinel error,调用方可通过 errors.Is 匹配。
Functions ¶
func DefaultSkillRoot ¶
DefaultSkillRoot 返回默认 workspace skills 目录。
Types ¶
type CreateRequest ¶
CreateRequest 表示创建新 Skill 目录和 SKILL.md 的请求。
type EditRequest ¶
EditRequest 表示完整替换已有 Skill 的 SKILL.md 内容的请求。
type InstallRequest ¶
type InstallRequest struct {
Name string
Content string // SKILL.md 内容
Files map[string]string // 附属文件:相对路径 → 内容
Force bool // 是否覆盖已有 skill
Source string // 来源(Leros / ClawHub / github / SkillsSh / url)
SkillID string // 源内唯一标识
}
InstallRequest 表示安装一个完整 Skill 的请求(SKILL.md + 附属文件)。 先在临时目录中组装,再整体移动到最终位置。
type MutationHandler ¶ added in v0.1.17
type MutationHandler func(ctx context.Context, kind MutationKind, name, action string)
MutationHandler receives successful skill mutations for instance-scoped side effects.
type MutationKind ¶ added in v0.1.1
type MutationKind int
MutationKind 表示一次 skill 变更的类型。
const ( MutationCreate MutationKind = iota MutationModify MutationDelete )
type PatchRequest ¶
type PatchRequest struct {
Name string
FilePath string
OldText string
NewText string
ReplaceAll bool
}
PatchRequest 表示替换 SKILL.md 或 supporting file 中文本的请求。
type RemoveFileRequest ¶
RemoveFileRequest 表示删除 Skill 目录下 supporting file 的请求。
type Result ¶
type Result struct {
Success bool `json:"success"`
Action string `json:"action"`
Name string `json:"name"`
Message string `json:"message,omitempty"`
Path string `json:"path,omitempty"`
Error string `json:"error,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
}
Result 表示 Skill 变更操作的返回结果。
type SkillError ¶ added in v0.1.1
SkillError 表示可被调用方程序化匹配的业务错误。
func (*SkillError) Error ¶ added in v0.1.1
func (e *SkillError) Error() string
type SkillMetadata ¶ added in v0.1.15
SkillMetadata stores the source and skill_id from the marketplace.
func ReadSkillMetadata ¶ added in v0.1.15
func ReadSkillMetadata(skillDir string) (*SkillMetadata, error)
ReadSkillMetadata reads the .skill-metadata file from the given skill directory.
type SkillStore ¶
type SkillStore struct {
// contains filtered or unexported fields
}
SkillStore 管理文件型 Skill。
func NewSkillStore ¶
func NewSkillStore(rootDir string) (*SkillStore, error)
NewSkillStore 创建以 rootDir 为根目录的 SkillStore;rootDir 为空时使用默认 Leros skills 根目录。
func NewSkillStoreWithMutation ¶ added in v0.1.17
func NewSkillStoreWithMutation(rootDir string, onMutation MutationHandler) (*SkillStore, error)
NewSkillStoreWithMutation creates a SkillStore with an immutable mutation callback.
func (*SkillStore) Create ¶
func (s *SkillStore) Create(ctx context.Context, req CreateRequest) (*Result, error)
Create 写入一个新 Skill。
func (*SkillStore) Delete ¶
func (s *SkillStore) Delete(ctx context.Context, req DeleteRequest) (*Result, error)
Delete 删除整个 Skill 目录。
func (*SkillStore) Edit ¶
func (s *SkillStore) Edit(ctx context.Context, req EditRequest) (*Result, error)
Edit 完全替换已有 Skill 的 SKILL.md 内容。
func (*SkillStore) Install ¶
func (s *SkillStore) Install(ctx context.Context, req InstallRequest) (*Result, error)
Install 将完整 Skill(SKILL.md + 附属文件)先写入临时目录,验证后整体移动到最终位置。
func (*SkillStore) Patch ¶
func (s *SkillStore) Patch(ctx context.Context, req PatchRequest) (*Result, error)
Patch 替换 SKILL.md 或 supporting file 中的文本。
func (*SkillStore) RemoveFile ¶
func (s *SkillStore) RemoveFile(ctx context.Context, req RemoveFileRequest) (*Result, error)
RemoveFile 删除已有 Skill 下的 supporting file。
func (*SkillStore) WriteFile ¶
func (s *SkillStore) WriteFile(ctx context.Context, req WriteFileRequest) (*Result, error)
WriteFile 在已有 Skill 下写入 supporting file。
type WriteFileRequest ¶
WriteFileRequest 表示在 Skill 目录下写入 supporting file 的请求。