1
0

完成一个简易的全局skill、command管理器

This commit is contained in:
2026-02-25 14:33:56 +08:00
parent f4cb809f9d
commit 2d327b5af8
60 changed files with 6053 additions and 1 deletions

View File

@@ -0,0 +1,73 @@
package adapter
import (
"fmt"
"os"
"path/filepath"
"skillmgr/internal/types"
)
// ClaudeAdapter Claude Code 平台适配器
type ClaudeAdapter struct{}
// GetSkillInstallPath 获取 skill 安装路径
func (a *ClaudeAdapter) GetSkillInstallPath(scope types.Scope, skillName string) (string, error) {
base, err := getBasePath(scope)
if err != nil {
return "", err
}
return filepath.Join(base, ".claude", "skills", skillName), nil
}
// GetCommandInstallPath 获取 command 安装路径
func (a *ClaudeAdapter) GetCommandInstallPath(scope types.Scope, commandGroup string) (string, error) {
base, err := getBasePath(scope)
if err != nil {
return "", err
}
return filepath.Join(base, ".claude", "commands", commandGroup), nil
}
// AdaptSkill 适配 skill遍历源目录生成文件映射
func (a *ClaudeAdapter) AdaptSkill(sourcePath, destBasePath string) (map[string]string, error) {
mapping := make(map[string]string)
err := filepath.Walk(sourcePath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
relPath, err := filepath.Rel(sourcePath, path)
if err != nil {
return fmt.Errorf("计算相对路径失败: %w", err)
}
destPath := filepath.Join(destBasePath, relPath)
if !info.IsDir() {
mapping[path] = destPath
}
return nil
})
return mapping, err
}
// AdaptCommand 适配 command保持目录结构
func (a *ClaudeAdapter) AdaptCommand(sourcePath, destBasePath, commandGroup string) (map[string]string, error) {
mapping := make(map[string]string)
files, err := filepath.Glob(filepath.Join(sourcePath, "*.md"))
if err != nil {
return nil, err
}
for _, file := range files {
fileName := filepath.Base(file)
destPath := filepath.Join(destBasePath, fileName)
mapping[file] = destPath
}
return mapping, nil
}