@botskill/cli 1.0.8 → 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.8",
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
@@ -27,7 +34,10 @@ getCommand
27
34
  .option('--api-url <url>', 'API base URL (overrides config for this command)')
28
35
  .action(async (specifier, options, command) => {
29
36
  const apiUrl = command.optsWithGlobals().apiUrl;
30
- const { name, version } = parseSpecifier(specifier);
37
+ const spec = (specifier || '').trim();
38
+ const parsed = parseSpecifier(spec);
39
+ const name = spec.startsWith('@') ? spec : parsed.name;
40
+ const version = spec.startsWith('@') ? undefined : parsed.version;
31
41
  const outputDir = path.resolve(options.output || process.cwd());
32
42
 
33
43
  if (!name) {
@@ -63,12 +73,23 @@ getCommand
63
73
  const buffer = Buffer.from(res.data);
64
74
 
65
75
  const zip = new AdmZip(buffer);
66
- zip.extractAllTo(outputDir, true);
67
-
68
76
  const entries = zip.getEntries();
69
- const skillDir = entries.find(e => e.isDirectory)?.entryName || entries[0]?.entryName?.split('/')[0] || 'skill';
70
- 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;
71
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
+ }
72
93
  console.log(`\nSkill downloaded successfully!`);
73
94
  console.log(`Location: ${targetPath}`);
74
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
  /**