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,50 @@
package adapter
import (
"fmt"
"os"
"skillmgr/internal/types"
)
// PlatformAdapter 平台适配器接口
type PlatformAdapter interface {
// GetSkillInstallPath 获取 skill 安装路径
GetSkillInstallPath(scope types.Scope, skillName string) (string, error)
// GetCommandInstallPath 获取 command 安装路径
GetCommandInstallPath(scope types.Scope, commandGroup string) (string, error)
// AdaptSkill 适配 skill返回 source → dest 映射)
AdaptSkill(sourcePath, destBasePath string) (map[string]string, error)
// AdaptCommand 适配 command返回 source → dest 映射)
AdaptCommand(sourcePath, destBasePath, commandGroup string) (map[string]string, error)
}
// GetAdapter 获取平台适配器
func GetAdapter(platform types.Platform) (PlatformAdapter, error) {
switch platform {
case types.PlatformClaude:
return &ClaudeAdapter{}, nil
case types.PlatformOpenCode:
return &OpenCodeAdapter{}, nil
default:
return nil, fmt.Errorf("不支持的平台: %s", platform)
}
}
// getBasePath 获取基础路径
// 支持通过环境变量 SKILLMGR_TEST_BASE 覆盖(用于测试隔离)
func getBasePath(scope types.Scope) (string, error) {
// 测试模式:使用环境变量指定的目录
if testBase := os.Getenv("SKILLMGR_TEST_BASE"); testBase != "" {
return testBase, nil
}
// 生产模式
if scope == types.ScopeGlobal {
return os.UserHomeDir()
}
return os.Getwd()
}