@botskill/cli 1.0.9 → 1.0.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botskill/cli",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "CLI tool for BotSkill - AI agent skills platform",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1,9 +1,16 @@
1
1
  import { Command } from 'commander';
2
2
  import path from 'path';
3
+ import os from 'os';
4
+ import fs from 'fs-extra';
3
5
  import AdmZip from 'adm-zip';
4
6
  import { createApiClient } from '../lib/auth.js';
5
7
  import { printApiError } from '../lib/formatError.js';
6
8
 
9
+ /** 从技能名提取目录名(@author/name -> name) */
10
+ function toDirName(name) {
11
+ return String(name || 'skill').replace(/^@[^/]+\//, '').trim() || 'skill';
12
+ }
13
+
7
14
  /**
8
15
  * Parse specifier: name@version or name
9
16
  * Returns { name, version } for API
@@ -66,12 +73,23 @@ getCommand
66
73
  const buffer = Buffer.from(res.data);
67
74
 
68
75
  const zip = new AdmZip(buffer);
69
- zip.extractAllTo(outputDir, true);
70
-
71
76
  const entries = zip.getEntries();
72
- const skillDir = entries.find(e => e.isDirectory)?.entryName || entries[0]?.entryName?.split('/')[0] || 'skill';
73
- const targetPath = path.join(outputDir, skillDir);
77
+ const rootDir = entries.find((e) => e.isDirectory)?.entryName?.replace(/\/$/, '') || (entries[0]?.entryName?.includes('/') ? entries[0].entryName.split('/')[0] : null);
78
+ const hasParentDir = rootDir != null;
74
79
 
80
+ const skillDirName = toDirName(skill.name);
81
+ const targetPath = path.join(outputDir, skillDirName);
82
+
83
+ if (hasParentDir) {
84
+ zip.extractAllTo(outputDir, true);
85
+ const extractedPath = path.join(outputDir, rootDir);
86
+ if (rootDir !== skillDirName) {
87
+ await fs.move(extractedPath, targetPath, { overwrite: true });
88
+ }
89
+ } else {
90
+ await fs.ensureDir(targetPath);
91
+ zip.extractAllTo(targetPath, true);
92
+ }
75
93
  console.log(`\nSkill downloaded successfully!`);
76
94
  console.log(`Location: ${targetPath}`);
77
95
  } catch (err) {
@@ -51,14 +51,25 @@ export async function downloadSkillToDir(api, name, version, outputDir) {
51
51
 
52
52
  const zip = new AdmZip(buffer);
53
53
  const entries = zip.getEntries();
54
- const rootEntry = entries.find(e => e.isDirectory)?.entryName || entries[0]?.entryName?.split('/')[0] || 'skill';
55
- const skillDirName = rootEntry.replace(/\/$/, '');
56
-
54
+ const rootDir = entries.find((e) => e.isDirectory)?.entryName?.replace(/\/$/, '') || (entries[0]?.entryName?.includes('/') ? entries[0].entryName.split('/')[0] : null);
55
+ const hasParentDir = rootDir != null;
56
+ const skillDirName = String(skill.name || 'skill').replace(/^@[^/]+\//, '').trim() || 'skill';
57
57
  const targetPath = path.join(outputDir, skillDirName);
58
+
58
59
  await fs.remove(targetPath).catch(() => {});
59
- zip.extractAllTo(outputDir, true);
60
60
 
61
- return path.join(outputDir, skillDirName);
61
+ if (hasParentDir) {
62
+ zip.extractAllTo(outputDir, true);
63
+ const extractedPath = path.join(outputDir, rootDir);
64
+ if (rootDir !== skillDirName) {
65
+ await fs.move(extractedPath, targetPath, { overwrite: true });
66
+ }
67
+ } else {
68
+ await fs.ensureDir(targetPath);
69
+ zip.extractAllTo(targetPath, true);
70
+ }
71
+
72
+ return targetPath;
62
73
  }
63
74
 
64
75
  /**