@catcuts-skills/hello-world 1.0.3 → 1.0.5
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/scripts/install-skill.js +122 -0
- package/scripts/uninstall-skill.js +100 -36
package/package.json
CHANGED
package/scripts/install-skill.js
CHANGED
|
@@ -16,11 +16,30 @@
|
|
|
16
16
|
const { execSync } = require('child_process');
|
|
17
17
|
const path = require('path');
|
|
18
18
|
const fs = require('fs');
|
|
19
|
+
const os = require('os');
|
|
19
20
|
const { printUsageGuide } = require('./usage-guide');
|
|
20
21
|
|
|
21
22
|
// 获取包根目录
|
|
22
23
|
const packageRoot = path.resolve(__dirname, '..');
|
|
23
24
|
|
|
25
|
+
// 获取用户主目录
|
|
26
|
+
const homeDir = os.homedir();
|
|
27
|
+
|
|
28
|
+
// 技能名称
|
|
29
|
+
const skillName = 'hello-world';
|
|
30
|
+
|
|
31
|
+
// 需要清理的路径列表
|
|
32
|
+
const pathsToClean = {
|
|
33
|
+
// skills CLI 的规范副本目录(这是问题的根源)
|
|
34
|
+
canonical: path.join(homeDir, '.agents', 'skills', skillName),
|
|
35
|
+
|
|
36
|
+
// Claude Code 全局技能目录(符号链接)
|
|
37
|
+
claudeGlobal: path.join(homeDir, '.claude', 'skills', skillName),
|
|
38
|
+
|
|
39
|
+
// Claude Code 项目级技能目录(如果存在)
|
|
40
|
+
claudeLocal: path.join(process.cwd(), '.claude', 'skills', skillName),
|
|
41
|
+
};
|
|
42
|
+
|
|
24
43
|
// 解析命令行参数
|
|
25
44
|
const args = process.argv.slice(2);
|
|
26
45
|
const dryRun = args.includes('--dry-run');
|
|
@@ -52,6 +71,106 @@ function log(message, type = 'info') {
|
|
|
52
71
|
console.log(`${prefix} ${message}`);
|
|
53
72
|
}
|
|
54
73
|
|
|
74
|
+
// 检查路径是否为符号链接
|
|
75
|
+
function isSymlink(filePath) {
|
|
76
|
+
try {
|
|
77
|
+
return fs.lstatSync(filePath).isSymbolicLink();
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 安全删除路径(支持符号链接、文件、目录)
|
|
84
|
+
function safeRemovePath(filePath, description) {
|
|
85
|
+
try {
|
|
86
|
+
if (!fs.existsSync(filePath)) {
|
|
87
|
+
return { success: true, removed: false, message: '不存在' };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const stats = fs.lstatSync(filePath);
|
|
91
|
+
const isLink = stats.isSymbolicLink();
|
|
92
|
+
const isDir = stats.isDirectory();
|
|
93
|
+
|
|
94
|
+
if (isLink) {
|
|
95
|
+
fs.unlinkSync(filePath);
|
|
96
|
+
return {
|
|
97
|
+
success: true,
|
|
98
|
+
removed: true,
|
|
99
|
+
message: `已删除符号链接: ${description}`
|
|
100
|
+
};
|
|
101
|
+
} else if (isDir) {
|
|
102
|
+
fs.rmSync(filePath, { recursive: true, force: true });
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
removed: true,
|
|
106
|
+
message: `已删除目录: ${description}`
|
|
107
|
+
};
|
|
108
|
+
} else {
|
|
109
|
+
fs.unlinkSync(filePath);
|
|
110
|
+
return {
|
|
111
|
+
success: true,
|
|
112
|
+
removed: true,
|
|
113
|
+
message: `已删除文件: ${description}`
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
removed: false,
|
|
120
|
+
message: `删除失败: ${error.message}`
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 清理旧的安装文件
|
|
126
|
+
function cleanOldInstallations() {
|
|
127
|
+
log('\n正在清理旧的安装文件...', 'info');
|
|
128
|
+
|
|
129
|
+
const results = [];
|
|
130
|
+
|
|
131
|
+
// 1. 清理规范副本目录(.agents/skills/hello-world)
|
|
132
|
+
const canonicalResult = safeRemovePath(
|
|
133
|
+
pathsToClean.canonical,
|
|
134
|
+
'规范副本'
|
|
135
|
+
);
|
|
136
|
+
results.push({ path: pathsToClean.canonical, ...canonicalResult });
|
|
137
|
+
|
|
138
|
+
// 2. 清理 Claude Code 全局符号链接
|
|
139
|
+
const globalResult = safeRemovePath(
|
|
140
|
+
pathsToClean.claudeGlobal,
|
|
141
|
+
'全局技能链接'
|
|
142
|
+
);
|
|
143
|
+
results.push({ path: pathsToClean.claudeGlobal, ...globalResult });
|
|
144
|
+
|
|
145
|
+
// 3. 清理 Claude Code 项目级安装(如果存在)
|
|
146
|
+
const localResult = safeRemovePath(
|
|
147
|
+
pathsToClean.claudeLocal,
|
|
148
|
+
'项目级技能'
|
|
149
|
+
);
|
|
150
|
+
results.push({ path: pathsToClean.claudeLocal, ...localResult });
|
|
151
|
+
|
|
152
|
+
// 输出清理结果
|
|
153
|
+
let removedCount = 0;
|
|
154
|
+
results.forEach((result) => {
|
|
155
|
+
if (result.removed) {
|
|
156
|
+
log(` ✓ ${result.message}`, 'success');
|
|
157
|
+
removedCount++;
|
|
158
|
+
} else if (result.success) {
|
|
159
|
+
log(` ⊗ ${result.message} (跳过)`, 'info');
|
|
160
|
+
} else {
|
|
161
|
+
log(` ✗ ${result.message}`, 'warning');
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (removedCount > 0) {
|
|
166
|
+
log(`\n已清理 ${removedCount} 个旧安装文件`, 'success');
|
|
167
|
+
} else {
|
|
168
|
+
log('未发现需要清理的文件', 'info');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return removedCount > 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
55
174
|
// 错误处理
|
|
56
175
|
function handleError(error) {
|
|
57
176
|
log(`安装失败: ${error.message}`, 'error');
|
|
@@ -64,6 +183,9 @@ try {
|
|
|
64
183
|
log(`开始安装 Hello World Skill...`, 'info');
|
|
65
184
|
log(`安装范围: ${isGlobal ? '全局(GLOBAL)' : '项目级(LOCAL)'}`, 'info');
|
|
66
185
|
|
|
186
|
+
// 清理旧的安装文件(解决增量更新导致的文件残留问题)
|
|
187
|
+
cleanOldInstallations();
|
|
188
|
+
|
|
67
189
|
// 构建 skills 命令
|
|
68
190
|
const commandParts = [
|
|
69
191
|
'npx',
|
|
@@ -16,6 +16,9 @@ const path = require('path');
|
|
|
16
16
|
const fs = require('fs');
|
|
17
17
|
const os = require('os');
|
|
18
18
|
|
|
19
|
+
// 技能名称
|
|
20
|
+
const skillName = 'hello-world';
|
|
21
|
+
|
|
19
22
|
// 解析命令行参数
|
|
20
23
|
const args = process.argv.slice(2);
|
|
21
24
|
const forceGlobal = args.includes('--global');
|
|
@@ -46,18 +49,49 @@ function log(message, type = 'info') {
|
|
|
46
49
|
console.log(`${prefix} ${message}`);
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
//
|
|
50
|
-
function
|
|
51
|
-
if (!fs.existsSync(dirPath)) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
|
|
52
|
+
// 安全删除路径(支持符号链接、文件、目录)
|
|
53
|
+
function safeRemovePath(filePath, description) {
|
|
55
54
|
try {
|
|
56
|
-
fs.
|
|
57
|
-
|
|
55
|
+
if (!fs.existsSync(filePath)) {
|
|
56
|
+
return { success: true, removed: false, message: '不存在' };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const stats = fs.lstatSync(filePath);
|
|
60
|
+
const isLink = stats.isSymbolicLink();
|
|
61
|
+
const isDir = stats.isDirectory();
|
|
62
|
+
|
|
63
|
+
if (isLink) {
|
|
64
|
+
fs.unlinkSync(filePath);
|
|
65
|
+
return {
|
|
66
|
+
success: true,
|
|
67
|
+
removed: true,
|
|
68
|
+
message: `已删除符号链接: ${description}`
|
|
69
|
+
};
|
|
70
|
+
} else if (isDir) {
|
|
71
|
+
fs.rmSync(filePath, { recursive: true, force: true });
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
removed: true,
|
|
75
|
+
message: `已删除目录: ${description}`
|
|
76
|
+
};
|
|
77
|
+
} else {
|
|
78
|
+
fs.unlinkSync(filePath);
|
|
79
|
+
return {
|
|
80
|
+
success: true,
|
|
81
|
+
removed: true,
|
|
82
|
+
message: `已删除文件: ${description}`
|
|
83
|
+
};
|
|
84
|
+
}
|
|
58
85
|
} catch (error) {
|
|
59
|
-
|
|
60
|
-
|
|
86
|
+
// 忽略"文件不存在"错误,可能已被并发删除
|
|
87
|
+
if (error.code === 'ENOENT') {
|
|
88
|
+
return { success: true, removed: false, message: '已不存在' };
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
removed: false,
|
|
93
|
+
message: `删除失败: ${error.message}`
|
|
94
|
+
};
|
|
61
95
|
}
|
|
62
96
|
}
|
|
63
97
|
|
|
@@ -65,42 +99,72 @@ try {
|
|
|
65
99
|
log(`开始卸载 Hello World Skill...`, 'info');
|
|
66
100
|
log(`卸载范围: ${isGlobal ? '全局(GLOBAL)' : '项目级(LOCAL)'}`, 'info');
|
|
67
101
|
|
|
68
|
-
|
|
102
|
+
log('\n正在清理技能文件...', 'info');
|
|
103
|
+
|
|
104
|
+
const results = [];
|
|
69
105
|
|
|
70
106
|
if (isGlobal) {
|
|
71
107
|
// 全局卸载
|
|
72
108
|
const homeDir = os.homedir();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
109
|
+
|
|
110
|
+
// 1. 清理规范副本目录(.agents/skills/hello-world)
|
|
111
|
+
const canonicalResult = safeRemovePath(
|
|
112
|
+
path.join(homeDir, '.agents', 'skills', skillName),
|
|
113
|
+
'规范副本'
|
|
114
|
+
);
|
|
115
|
+
results.push(canonicalResult);
|
|
116
|
+
|
|
117
|
+
// 2. 清理 Claude Code 全局符号链接
|
|
118
|
+
const globalResult = safeRemovePath(
|
|
119
|
+
path.join(homeDir, '.claude', 'skills', skillName),
|
|
120
|
+
'全局技能链接'
|
|
121
|
+
);
|
|
122
|
+
results.push(globalResult);
|
|
84
123
|
} else {
|
|
85
124
|
// 项目级卸载
|
|
86
125
|
const cwd = process.cwd();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
126
|
+
|
|
127
|
+
// 1. 清理项目级规范副本(如果存在)
|
|
128
|
+
const canonicalResult = safeRemovePath(
|
|
129
|
+
path.join(cwd, '.agents', 'skills', skillName),
|
|
130
|
+
'项目级规范副本'
|
|
131
|
+
);
|
|
132
|
+
results.push(canonicalResult);
|
|
133
|
+
|
|
134
|
+
// 2. 清理 Claude Code 项目级技能
|
|
135
|
+
const localResult = safeRemovePath(
|
|
136
|
+
path.join(cwd, '.claude', 'skills', skillName),
|
|
137
|
+
'项目级技能'
|
|
138
|
+
);
|
|
139
|
+
results.push(localResult);
|
|
98
140
|
}
|
|
99
141
|
|
|
142
|
+
// 输出清理结果
|
|
143
|
+
let removedCount = 0;
|
|
144
|
+
let errorCount = 0;
|
|
145
|
+
|
|
146
|
+
results.forEach((result) => {
|
|
147
|
+
if (result.removed) {
|
|
148
|
+
log(` ✓ ${result.message}`, 'success');
|
|
149
|
+
removedCount++;
|
|
150
|
+
} else if (result.success) {
|
|
151
|
+
log(` ⊗ ${result.message} (跳过)`, 'info');
|
|
152
|
+
} else {
|
|
153
|
+
log(` ✗ ${result.message}`, 'error');
|
|
154
|
+
errorCount++;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// 总结
|
|
100
159
|
if (removedCount > 0) {
|
|
101
|
-
log(`\n卸载成功! 已删除 ${removedCount}
|
|
102
|
-
} else {
|
|
103
|
-
log('\n
|
|
160
|
+
log(`\n✓ 卸载成功! 已删除 ${removedCount} 个文件/目录`, 'success');
|
|
161
|
+
} else if (errorCount === 0) {
|
|
162
|
+
log('\n⊗ 未找到需要卸载的文件', 'warning');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (errorCount > 0) {
|
|
166
|
+
log(`\n⚠ 有 ${errorCount} 个项目删除失败,请手动清理`, 'warning');
|
|
167
|
+
process.exit(1);
|
|
104
168
|
}
|
|
105
169
|
} catch (error) {
|
|
106
170
|
log(`卸载失败: ${error.message}`, 'error');
|