@workskills/getskill 1.1.0 → 1.1.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/EXAMPLES.md +2 -2
- package/README.md +9 -9
- package/index.js +174 -28
- package/package.json +1 -1
package/EXAMPLES.md
CHANGED
|
@@ -148,7 +148,7 @@ const getskill = require('@workskills/getskill');
|
|
|
148
148
|
(async () => {
|
|
149
149
|
try {
|
|
150
150
|
// 设置自定义 API 地址(可选)
|
|
151
|
-
getskill.setBaseUrl('https://
|
|
151
|
+
getskill.setBaseUrl('https://getskill.work');
|
|
152
152
|
|
|
153
153
|
// 查看当前 API 地址
|
|
154
154
|
console.log('当前 API:', getskill.getBaseUrl());
|
|
@@ -235,7 +235,7 @@ $ getskill search commit
|
|
|
235
235
|
```bash
|
|
236
236
|
# 查看当前 API 地址
|
|
237
237
|
$ getskill config get
|
|
238
|
-
当前 BASE_URL: https://
|
|
238
|
+
当前 BASE_URL: https://getskill.work
|
|
239
239
|
|
|
240
240
|
# 设置自定义 API 地址
|
|
241
241
|
$ getskill config set https://custom-api.example.com
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# GetSkill
|
|
2
2
|
|
|
3
|
-
OpenClaw 技能管理工具 - 从
|
|
3
|
+
OpenClaw 技能管理工具 - 从 getskill.work 搜索、下载和更新技能文件
|
|
4
4
|
|
|
5
5
|
## 功能特性
|
|
6
6
|
|
|
7
|
-
- 🔍 从
|
|
7
|
+
- 🔍 从 getskill.work API 搜索技能
|
|
8
8
|
- 📥 通过 Git 克隆技能仓库
|
|
9
9
|
- 🔄 通过 Git pull 更新已安装的技能
|
|
10
10
|
- 🛠️ 自动检测并引导安装 Git(如未安装)
|
|
@@ -14,7 +14,7 @@ OpenClaw 技能管理工具 - 从 getskills.certer 搜索、下载和更新技
|
|
|
14
14
|
|
|
15
15
|
## 工作原理
|
|
16
16
|
|
|
17
|
-
1. **搜索**: 从 `
|
|
17
|
+
1. **搜索**: 从 `getskill.work` API 获取技能列表,包含 Git 仓库地址
|
|
18
18
|
2. **安装**: 使用 `git clone` 克隆技能仓库到缓存目录
|
|
19
19
|
3. **复制**: 将仓库中的 `.md` 技能文件复制到 OpenClaw skills 目录
|
|
20
20
|
4. **更新**: 使用 `git pull` 更新仓库,并重新复制文件
|
|
@@ -165,7 +165,7 @@ GETSKILL_BASE_URL=https://your-custom-api.com getskill search keyword
|
|
|
165
165
|
### 搜索 API
|
|
166
166
|
|
|
167
167
|
```
|
|
168
|
-
GET https://
|
|
168
|
+
GET https://getskill.work/repo/search?sort=updated&order=desc&q=<关键词>&page=1&limit=20
|
|
169
169
|
```
|
|
170
170
|
|
|
171
171
|
响应格式:
|
|
@@ -178,8 +178,8 @@ GET https://getskills.certer/repo/search?sort=updated&order=desc&q=<关键词>&p
|
|
|
178
178
|
"id": 1,
|
|
179
179
|
"full_name": "skills/commit-helper",
|
|
180
180
|
"description": "帮助生成规范的 git commit 信息",
|
|
181
|
-
"html_url": "https://
|
|
182
|
-
"clone_url": "https://
|
|
181
|
+
"html_url": "https://getskill.work/skills/commit-helper",
|
|
182
|
+
"clone_url": "https://getskill.work/skills/commit-helper.git"
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
]
|
|
@@ -189,7 +189,7 @@ GET https://getskills.certer/repo/search?sort=updated&order=desc&q=<关键词>&p
|
|
|
189
189
|
### 详情 API
|
|
190
190
|
|
|
191
191
|
```
|
|
192
|
-
GET https://
|
|
192
|
+
GET https://getskill.work/repo/<技能名称>
|
|
193
193
|
```
|
|
194
194
|
|
|
195
195
|
响应格式:
|
|
@@ -199,8 +199,8 @@ GET https://getskills.certer/repo/<技能名称>
|
|
|
199
199
|
"id": 1,
|
|
200
200
|
"full_name": "skills/commit-helper",
|
|
201
201
|
"description": "帮助生成规范的 git commit 信息",
|
|
202
|
-
"html_url": "https://
|
|
203
|
-
"clone_url": "https://
|
|
202
|
+
"html_url": "https://getskill.work/skills/commit-helper",
|
|
203
|
+
"clone_url": "https://getskill.work/skills/commit-helper.git"
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
```
|
package/index.js
CHANGED
|
@@ -11,7 +11,7 @@ const { exec } = require('child_process');
|
|
|
11
11
|
* 基础 URL 配置
|
|
12
12
|
* 可以通过环境变量 GETSKILL_BASE_URL 自定义
|
|
13
13
|
*/
|
|
14
|
-
let BASE_URL = process.env.GETSKILL_BASE_URL || 'https://
|
|
14
|
+
let BASE_URL = process.env.GETSKILL_BASE_URL || 'https://getskill.work';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* 设置自定义 BASE_URL
|
|
@@ -219,11 +219,28 @@ function ensureDirectoryExists(dirPath) {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
|
-
* HTTP/HTTPS
|
|
222
|
+
* HTTP/HTTPS 请求封装(支持重定向和错误处理)
|
|
223
|
+
* @param {string} url - 请求 URL
|
|
224
|
+
* @param {Object} options - 请求选项
|
|
225
|
+
* @param {number} redirectCount - 重定向次数(内部使用)
|
|
226
|
+
* @returns {Promise<Object>} 响应对象
|
|
223
227
|
*/
|
|
224
|
-
function request(url, options = {}) {
|
|
228
|
+
function request(url, options = {}, redirectCount = 0) {
|
|
229
|
+
const MAX_REDIRECTS = 5; // 最大重定向次数
|
|
230
|
+
|
|
225
231
|
return new Promise((resolve, reject) => {
|
|
226
|
-
|
|
232
|
+
// 检查重定向次数
|
|
233
|
+
if (redirectCount >= MAX_REDIRECTS) {
|
|
234
|
+
return reject(new Error(`Too many redirects (${MAX_REDIRECTS})`));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let urlObj;
|
|
238
|
+
try {
|
|
239
|
+
urlObj = new URL(url);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
return reject(new Error(`Invalid URL: ${url}`));
|
|
242
|
+
}
|
|
243
|
+
|
|
227
244
|
const protocol = urlObj.protocol === 'https:' ? https : http;
|
|
228
245
|
|
|
229
246
|
const reqOptions = {
|
|
@@ -231,10 +248,33 @@ function request(url, options = {}) {
|
|
|
231
248
|
port: urlObj.port,
|
|
232
249
|
path: urlObj.pathname + urlObj.search,
|
|
233
250
|
method: options.method || 'GET',
|
|
234
|
-
headers: options.headers || {}
|
|
251
|
+
headers: options.headers || {},
|
|
252
|
+
timeout: options.timeout || 30000 // 默认 30 秒超时
|
|
235
253
|
};
|
|
236
254
|
|
|
237
255
|
const req = protocol.request(reqOptions, (res) => {
|
|
256
|
+
// 处理重定向 (301, 302, 303, 307, 308)
|
|
257
|
+
if ([301, 302, 303, 307, 308].includes(res.statusCode)) {
|
|
258
|
+
const redirectUrl = res.headers.location;
|
|
259
|
+
|
|
260
|
+
if (!redirectUrl) {
|
|
261
|
+
return reject(new Error(`Redirect location header missing (${res.statusCode})`));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 解析重定向 URL(可能是相对路径)
|
|
265
|
+
let newUrl;
|
|
266
|
+
try {
|
|
267
|
+
newUrl = new URL(redirectUrl, url).toString();
|
|
268
|
+
} catch (error) {
|
|
269
|
+
return reject(new Error(`Invalid redirect URL: ${redirectUrl}`));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// 递归处理重定向
|
|
273
|
+
return request(newUrl, options, redirectCount + 1)
|
|
274
|
+
.then(resolve)
|
|
275
|
+
.catch(reject);
|
|
276
|
+
}
|
|
277
|
+
|
|
238
278
|
let data = '';
|
|
239
279
|
|
|
240
280
|
res.on('data', (chunk) => {
|
|
@@ -249,13 +289,30 @@ function request(url, options = {}) {
|
|
|
249
289
|
body: data
|
|
250
290
|
});
|
|
251
291
|
} else {
|
|
252
|
-
reject(new Error(`Request failed with status code ${res.statusCode}`));
|
|
292
|
+
reject(new Error(`Request failed with status code ${res.statusCode}: ${data.substring(0, 200)}`));
|
|
253
293
|
}
|
|
254
294
|
});
|
|
295
|
+
|
|
296
|
+
res.on('error', (err) => {
|
|
297
|
+
reject(new Error(`Response error: ${err.message}`));
|
|
298
|
+
});
|
|
255
299
|
});
|
|
256
300
|
|
|
257
301
|
req.on('error', (err) => {
|
|
258
|
-
|
|
302
|
+
if (err.code === 'ECONNREFUSED') {
|
|
303
|
+
reject(new Error(`Connection refused: ${urlObj.hostname}`));
|
|
304
|
+
} else if (err.code === 'ENOTFOUND') {
|
|
305
|
+
reject(new Error(`Host not found: ${urlObj.hostname}`));
|
|
306
|
+
} else if (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT') {
|
|
307
|
+
reject(new Error(`Request timeout: ${url}`));
|
|
308
|
+
} else {
|
|
309
|
+
reject(new Error(`Network error: ${err.message}`));
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
req.on('timeout', () => {
|
|
314
|
+
req.destroy();
|
|
315
|
+
reject(new Error(`Request timeout after ${reqOptions.timeout}ms`));
|
|
259
316
|
});
|
|
260
317
|
|
|
261
318
|
if (options.body) {
|
|
@@ -292,6 +349,12 @@ function executeCommand(command, cwd) {
|
|
|
292
349
|
* @returns {Promise<Array>} 技能列表(包含 git 地址)
|
|
293
350
|
*/
|
|
294
351
|
async function searchSkills(keyword, options = {}) {
|
|
352
|
+
// 参数验证
|
|
353
|
+
if (!keyword || typeof keyword !== 'string') {
|
|
354
|
+
console.error('搜索失败: 关键词无效');
|
|
355
|
+
return [];
|
|
356
|
+
}
|
|
357
|
+
|
|
295
358
|
const {
|
|
296
359
|
sort = 'updated',
|
|
297
360
|
order = 'desc',
|
|
@@ -302,11 +365,45 @@ async function searchSkills(keyword, options = {}) {
|
|
|
302
365
|
const url = `${BASE_URL}/repo/search?sort=${sort}&order=${order}&q=${encodeURIComponent(keyword)}&page=${page}&limit=${limit}`;
|
|
303
366
|
|
|
304
367
|
try {
|
|
305
|
-
const response = await request(url);
|
|
306
|
-
|
|
368
|
+
const response = await request(url, { timeout: 15000 });
|
|
369
|
+
|
|
370
|
+
// 检查响应体是否为空
|
|
371
|
+
if (!response.body || response.body.trim() === '') {
|
|
372
|
+
console.warn('搜索警告: 服务器返回空响应');
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 尝试解析 JSON
|
|
377
|
+
let result;
|
|
378
|
+
try {
|
|
379
|
+
result = JSON.parse(response.body);
|
|
380
|
+
} catch (parseError) {
|
|
381
|
+
console.error('搜索失败: JSON 解析错误', parseError.message);
|
|
382
|
+
console.debug('响应内容:', response.body.substring(0, 200));
|
|
383
|
+
return [];
|
|
384
|
+
}
|
|
307
385
|
|
|
308
386
|
// 解析返回格式: { ok: true, data: [{ repository: {...} }] }
|
|
309
|
-
if (!result
|
|
387
|
+
if (!result) {
|
|
388
|
+
console.warn('搜索警告: 结果为空');
|
|
389
|
+
return [];
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// 检查 API 响应状态
|
|
393
|
+
if (result.ok === false) {
|
|
394
|
+
console.warn('搜索警告: API 返回失败状态', result.message || '');
|
|
395
|
+
return [];
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// 检查 data 字段
|
|
399
|
+
if (!result.data) {
|
|
400
|
+
console.warn('搜索警告: 响应中缺少 data 字段');
|
|
401
|
+
return [];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// 确保 data 是数组
|
|
405
|
+
if (!Array.isArray(result.data)) {
|
|
406
|
+
console.warn('搜索警告: data 不是数组类型');
|
|
310
407
|
return [];
|
|
311
408
|
}
|
|
312
409
|
|
|
@@ -321,10 +418,24 @@ async function searchSkills(keyword, options = {}) {
|
|
|
321
418
|
git_url: repo.html_url ? `${repo.html_url}.git` : '',
|
|
322
419
|
clone_url: repo.clone_url || ''
|
|
323
420
|
};
|
|
324
|
-
});
|
|
421
|
+
}).filter(item => item.full_name); // 过滤掉没有 full_name 的项
|
|
422
|
+
|
|
325
423
|
} catch (error) {
|
|
326
|
-
|
|
327
|
-
|
|
424
|
+
// 友好的错误提示
|
|
425
|
+
if (error.message.includes('Host not found')) {
|
|
426
|
+
console.error('搜索失败: 无法连接到服务器,请检查网络或 API 地址配置');
|
|
427
|
+
} else if (error.message.includes('timeout')) {
|
|
428
|
+
console.error('搜索失败: 请求超时,请稍后重试');
|
|
429
|
+
} else if (error.message.includes('Connection refused')) {
|
|
430
|
+
console.error('搜索失败: 服务器拒绝连接,请检查 API 地址是否正确');
|
|
431
|
+
} else if (error.message.includes('status code')) {
|
|
432
|
+
console.error('搜索失败: 服务器返回错误', error.message);
|
|
433
|
+
} else {
|
|
434
|
+
console.error('搜索失败:', error.message);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// 返回空数组而不是抛出异常,避免程序崩溃
|
|
438
|
+
return [];
|
|
328
439
|
}
|
|
329
440
|
}
|
|
330
441
|
|
|
@@ -334,11 +445,28 @@ async function searchSkills(keyword, options = {}) {
|
|
|
334
445
|
* @returns {Promise<Object>} 技能详情
|
|
335
446
|
*/
|
|
336
447
|
async function getSkillDetail(skillId) {
|
|
448
|
+
// 参数验证
|
|
449
|
+
if (!skillId || typeof skillId !== 'string') {
|
|
450
|
+
throw new Error('技能 ID 或名称无效');
|
|
451
|
+
}
|
|
452
|
+
|
|
337
453
|
const url = `${BASE_URL}/repo/${encodeURIComponent(skillId)}`;
|
|
338
454
|
|
|
339
455
|
try {
|
|
340
|
-
const response = await request(url);
|
|
341
|
-
|
|
456
|
+
const response = await request(url, { timeout: 15000 });
|
|
457
|
+
|
|
458
|
+
// 检查响应体是否为空
|
|
459
|
+
if (!response.body || response.body.trim() === '') {
|
|
460
|
+
throw new Error('服务器返回空响应');
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// 尝试解析 JSON
|
|
464
|
+
let result;
|
|
465
|
+
try {
|
|
466
|
+
result = JSON.parse(response.body);
|
|
467
|
+
} catch (parseError) {
|
|
468
|
+
throw new Error(`JSON 解析错误: ${parseError.message}`);
|
|
469
|
+
}
|
|
342
470
|
|
|
343
471
|
// 如果返回的数据格式类似搜索接口,需要解析 repository
|
|
344
472
|
if (result.repository) {
|
|
@@ -363,8 +491,20 @@ async function getSkillDetail(skillId) {
|
|
|
363
491
|
clone_url: result.clone_url || ''
|
|
364
492
|
};
|
|
365
493
|
} catch (error) {
|
|
366
|
-
|
|
367
|
-
|
|
494
|
+
// 友好的错误提示
|
|
495
|
+
if (error.message.includes('Host not found')) {
|
|
496
|
+
throw new Error('无法连接到服务器,请检查网络或 API 地址配置');
|
|
497
|
+
} else if (error.message.includes('timeout')) {
|
|
498
|
+
throw new Error('请求超时,请稍后重试');
|
|
499
|
+
} else if (error.message.includes('Connection refused')) {
|
|
500
|
+
throw new Error('服务器拒绝连接,请检查 API 地址是否正确');
|
|
501
|
+
} else if (error.message.includes('status code 404')) {
|
|
502
|
+
throw new Error(`技能不存在: ${skillId}`);
|
|
503
|
+
} else if (error.message.includes('status code')) {
|
|
504
|
+
throw new Error(`服务器错误: ${error.message}`);
|
|
505
|
+
} else {
|
|
506
|
+
throw new Error(`获取技能详情失败: ${error.message}`);
|
|
507
|
+
}
|
|
368
508
|
}
|
|
369
509
|
}
|
|
370
510
|
|
|
@@ -547,17 +687,23 @@ async function cli() {
|
|
|
547
687
|
process.exit(1);
|
|
548
688
|
}
|
|
549
689
|
const results = await searchSkills(args[1]);
|
|
550
|
-
|
|
551
|
-
results.
|
|
552
|
-
console.log(
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
console.log(
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
690
|
+
|
|
691
|
+
if (results.length === 0) {
|
|
692
|
+
console.log('未找到相关技能');
|
|
693
|
+
console.log('提示: 尝试使用不同的关键词,或访问 ' + BASE_URL + ' 查看所有可用技能');
|
|
694
|
+
} else {
|
|
695
|
+
console.log(`找到 ${results.length} 个技能:\n`);
|
|
696
|
+
results.forEach((skill, index) => {
|
|
697
|
+
console.log(`${index + 1}. ${skill.full_name}`);
|
|
698
|
+
if (skill.description) {
|
|
699
|
+
console.log(` 描述: ${skill.description}`);
|
|
700
|
+
}
|
|
701
|
+
if (skill.git_url) {
|
|
702
|
+
console.log(` Git: ${skill.git_url}`);
|
|
703
|
+
}
|
|
704
|
+
console.log('');
|
|
705
|
+
});
|
|
706
|
+
}
|
|
561
707
|
break;
|
|
562
708
|
|
|
563
709
|
case 'install':
|