joyskills-cli 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/install.js +62 -17
package/package.json
CHANGED
package/src/commands/install.js
CHANGED
|
@@ -67,42 +67,87 @@ function detectSkillType(skillName) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* 安装公开 skill
|
|
70
|
+
* 安装公开 skill(自己实现,不依赖 openskills)
|
|
71
71
|
*/
|
|
72
72
|
async function installPublicSkill(skillName, options, localManager, lockfileManager) {
|
|
73
73
|
console.log(`📦 Installing public skill: ${skillName}`);
|
|
74
|
-
console.log(`💡 Using openskills install...\n`);
|
|
75
74
|
|
|
75
|
+
const registryManager = require('../registry');
|
|
76
|
+
const tmpDir = `/tmp/joyskills-${Date.now()}`;
|
|
77
|
+
|
|
76
78
|
try {
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
throw new Error('openskills not found. Please install: npm install -g openskills');
|
|
79
|
+
// 1. 解析 skill 名称:anthropics/skills/pdf -> owner=anthropics, repo=skills, path=pdf
|
|
80
|
+
const parts = skillName.split('/');
|
|
81
|
+
if (parts.length < 2) {
|
|
82
|
+
throw new Error(`Invalid skill name: ${skillName}. Expected format: owner/repo or owner/repo/path`);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
const owner = parts[0];
|
|
86
|
+
const repo = parts[1];
|
|
87
|
+
const skillPath = parts.slice(2).join('/') || repo; // 如果没有 path,默认用 repo 名
|
|
88
|
+
|
|
89
|
+
// 2. clone 仓库
|
|
90
|
+
const repoUrl = `https://github.com/${owner}/${repo}`;
|
|
91
|
+
console.log(`🔄 Cloning from: ${repoUrl}`);
|
|
92
|
+
|
|
93
|
+
execSync(`git clone --depth 1 ${repoUrl} ${tmpDir}`, {
|
|
94
|
+
stdio: 'pipe',
|
|
95
|
+
encoding: 'utf-8'
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// 3. 寻找 SKILL.md
|
|
99
|
+
const skillSourceDir = path.join(tmpDir, skillPath);
|
|
100
|
+
const skillMdPath = path.join(skillSourceDir, 'SKILL.md');
|
|
101
|
+
|
|
102
|
+
if (!fs.existsSync(skillMdPath)) {
|
|
103
|
+
throw new Error(`SKILL.md not found at ${skillPath}. Please check the skill path.`);
|
|
90
104
|
}
|
|
91
105
|
|
|
92
|
-
//
|
|
106
|
+
// 4. 确定安装目标目录
|
|
107
|
+
const targetDir = options.global
|
|
108
|
+
? localManager.getGlobalSkillPath(skillPath)
|
|
109
|
+
: localManager.getProjectSkillPath(skillPath);
|
|
110
|
+
|
|
111
|
+
const location = options.global ? 'global (~/.claude/skills)' : 'project (./.claude/skills)';
|
|
112
|
+
console.log(`📍 Location: ${location}`);
|
|
113
|
+
|
|
114
|
+
// 5. 复制文件
|
|
115
|
+
if (fs.existsSync(targetDir)) {
|
|
116
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
117
|
+
}
|
|
118
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
119
|
+
|
|
120
|
+
// 复制所有文件
|
|
121
|
+
const files = fs.readdirSync(skillSourceDir);
|
|
122
|
+
for (const file of files) {
|
|
123
|
+
const srcPath = path.join(skillSourceDir, file);
|
|
124
|
+
const destPath = path.join(targetDir, file);
|
|
125
|
+
|
|
126
|
+
if (fs.statSync(srcPath).isDirectory()) {
|
|
127
|
+
fs.cpSync(srcPath, destPath, { recursive: true });
|
|
128
|
+
} else {
|
|
129
|
+
fs.copyFileSync(srcPath, destPath);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 6. 更新 lockfile
|
|
93
134
|
lockfileManager.updateSkill(skillName, {
|
|
94
135
|
version: options.version || 'latest',
|
|
95
136
|
source: 'public',
|
|
96
137
|
installedAt: new Date().toISOString()
|
|
97
138
|
});
|
|
98
|
-
|
|
99
139
|
await lockfileManager.save();
|
|
100
140
|
|
|
101
|
-
console.log(
|
|
141
|
+
console.log(`✅ Successfully installed ${skillName}`);
|
|
102
142
|
console.log(`💡 Run 'joySkills sync' to update AGENTS.md`);
|
|
103
143
|
|
|
104
144
|
} catch (error) {
|
|
105
|
-
throw new Error(`
|
|
145
|
+
throw new Error(`Failed to install ${skillName}: ${error.message}`);
|
|
146
|
+
} finally {
|
|
147
|
+
// 清理临时目录
|
|
148
|
+
if (fs.existsSync(tmpDir)) {
|
|
149
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
150
|
+
}
|
|
106
151
|
}
|
|
107
152
|
}
|
|
108
153
|
|