1
0
Files
Skill/manager/internal/adapter/claude.go

74 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}