@yottameta/yotta-chain 0.1.2 → 0.1.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/CHANGELOG.md +15 -0
- package/LICENSE +20 -20
- package/README.md +7 -5
- package/README.zh-CN.md +7 -5
- package/SKILL.md +9 -7
- package/bin/install.js +336 -163
- package/install.sh +327 -132
- package/package.json +5 -2
- package/references/rules.md +10 -5
- package/scripts/yotta_chain.py +307 -24
- package/scripts/test_yotta_chain.py +0 -616
package/bin/install.js
CHANGED
|
@@ -1,163 +1,336 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* yotta-chain 跨平台安装器(YottaSkills)
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* npx -y @yottameta/yotta-chain --
|
|
7
|
-
* npx -y @yottameta/yotta-chain
|
|
8
|
-
* npx -y @yottameta/yotta-chain
|
|
9
|
-
* npx -y @yottameta/yotta-chain
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
'.
|
|
142
|
-
'.
|
|
143
|
-
'.
|
|
144
|
-
'.
|
|
145
|
-
'.
|
|
146
|
-
'.
|
|
147
|
-
'
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
'
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* yotta-chain 跨平台安装器(YottaSkills)
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* npx -y @yottameta/yotta-chain --agent <name> # 按智能体默认用户级目录安装(推荐)
|
|
7
|
+
* npx -y @yottameta/yotta-chain --dir <path> # 装到指定目录(用户改了目录的智能体)
|
|
8
|
+
* npx -y @yottameta/yotta-chain -g # 安装到全部已知智能体用户级目录
|
|
9
|
+
* npx -y @yottameta/yotta-chain # 安装到检测到的项目级目录
|
|
10
|
+
* npx -y @yottameta/yotta-chain --list # 列出智能体 -> 默认目录
|
|
11
|
+
* npx -y @yottameta/yotta-chain --dry-run # 只显示将写入的目标,不写文件
|
|
12
|
+
* npx -y @yottameta/yotta-chain --version # 显示版本
|
|
13
|
+
* npx -y @yottameta/yotta-chain --help # 显示帮助
|
|
14
|
+
*
|
|
15
|
+
* 退出码: 0 成功 / 1 安装失败 / 2 用法错误 / 4 目标错误
|
|
16
|
+
*/
|
|
17
|
+
'use strict';
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const os = require('os');
|
|
21
|
+
|
|
22
|
+
const SKILL_NAME = 'yotta-chain';
|
|
23
|
+
const PKG_ROOT = path.join(__dirname, '..');
|
|
24
|
+
|
|
25
|
+
// 顶层开发文件 / 目录:只在安装包顶层跳过;技能包内嵌套同名载荷必须保留。
|
|
26
|
+
// 与 install.sh 同口径:开发件与运行时不相关目录一律不落目标。
|
|
27
|
+
const TOP_SKIP = [
|
|
28
|
+
'package.json', 'package-lock.json', 'bin', 'lib', 'test',
|
|
29
|
+
'.github', '.git', '.gitignore', '.npmignore', '.gitattributes',
|
|
30
|
+
'.yotta', '.tmp', 'install.sh', 'node_modules',
|
|
31
|
+
];
|
|
32
|
+
const TOP_SKIP_SET = new Set(TOP_SKIP);
|
|
33
|
+
// 缓存 / 编译产物:任意层级跳过,安装时同样清理。
|
|
34
|
+
const CACHE_DIRS = new Set(['__pycache__', '.pytest_cache', '.mypy_cache']);
|
|
35
|
+
|
|
36
|
+
class UsageError extends Error {}
|
|
37
|
+
class TargetError extends Error {}
|
|
38
|
+
class InstallError extends Error {}
|
|
39
|
+
|
|
40
|
+
// 智能体 -> 用户级默认技能目录(dirs 按优先级排列;--agent 装到第一个)
|
|
41
|
+
// 依据官方文档:.agents/skills 并非通用目录,被 OpenCode / Cursor / Cline / Amp /
|
|
42
|
+
// Kimi / Gemini CLI / GitHub Copilot 等读取;Claude Code 与 Codex 默认不读 .agents。
|
|
43
|
+
const AGENT_DIRS = {
|
|
44
|
+
claude: { label: 'Claude Code', dirs: ['.claude/skills'] },
|
|
45
|
+
cursor: { label: 'Cursor', dirs: ['.cursor/skills', '.agents/skills'] },
|
|
46
|
+
codex: { label: 'Codex', dirs: ['.codex/skills'] }, // 特判:$CODEX_HOME/skills
|
|
47
|
+
gemini: { label: 'Gemini CLI', dirs: ['.gemini/skills', '.agents/skills'] },
|
|
48
|
+
goose: { label: 'Goose', dirs: ['.config/goose/skills', '.agents/skills'] },
|
|
49
|
+
amp: { label: 'Amp', dirs: ['.config/agents/skills', '.agents/skills'] },
|
|
50
|
+
opencode: { label: 'OpenCode', dirs: ['.config/opencode/skills'] }, // 特判:$XDG_CONFIG_HOME
|
|
51
|
+
windsurf: { label: 'Windsurf', dirs: ['.codeium/windsurf/skills'] },
|
|
52
|
+
workbuddy: { label: 'WorkBuddy', dirs: ['.workbuddy/skills'] },
|
|
53
|
+
kiro: { label: 'Kiro', dirs: ['.kiro/skills'] },
|
|
54
|
+
trae: { label: 'Trae Code CLI', dirs: ['.traecli/skills'] },
|
|
55
|
+
'trae-cn': { label: 'Trae IDE(国内)', dirs: ['.trae-cn/skills'] },
|
|
56
|
+
qwen: { label: 'Qwen Code', dirs: ['.qwen/skills'] },
|
|
57
|
+
comate: { label: 'Comate 文心快码', dirs: ['.comate/skills'] },
|
|
58
|
+
codebuddy: { label: 'CodeBuddy Code', dirs: ['.codebuddy/skills'] },
|
|
59
|
+
kimi: { label: 'Kimi Code CLI', dirs: ['.kimi/skills'] },
|
|
60
|
+
agents: { label: '通用 AGENTS.md', dirs: ['.agents/skills'] },
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const PROJECT_DIRS = [
|
|
64
|
+
'.claude/skills',
|
|
65
|
+
'.cursor/skills',
|
|
66
|
+
'.codex/skills',
|
|
67
|
+
'.config/goose/skills',
|
|
68
|
+
'.config/agents/skills',
|
|
69
|
+
'.opencode/skills',
|
|
70
|
+
'.codeium/windsurf/skills',
|
|
71
|
+
'.workbuddy/skills',
|
|
72
|
+
'.kiro/skills',
|
|
73
|
+
'.traecli/skills',
|
|
74
|
+
'.gemini/skills',
|
|
75
|
+
'.trae-cn/skills',
|
|
76
|
+
'.qwen/skills',
|
|
77
|
+
'.comate/skills',
|
|
78
|
+
'.codebuddy/skills',
|
|
79
|
+
'.kimi/skills',
|
|
80
|
+
'.agents/skills',
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
// Codex 用户级目录特判:优先 $CODEX_HOME/skills,否则 ~/.codex/skills
|
|
84
|
+
function codexUserDir() {
|
|
85
|
+
const base = process.env.CODEX_HOME || path.join(os.homedir(), '.codex');
|
|
86
|
+
return path.join(base, 'skills');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// OpenCode 用户级目录特判:优先 $XDG_CONFIG_HOME/opencode/skills,否则 ~/.config/opencode/skills
|
|
90
|
+
function opencodeUserDir() {
|
|
91
|
+
const base = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config');
|
|
92
|
+
return path.join(base, 'opencode', 'skills');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function resolveUserDir(rel) {
|
|
96
|
+
if (rel === '.codex/skills') return codexUserDir();
|
|
97
|
+
if (rel === '.config/opencode/skills') return opencodeUserDir();
|
|
98
|
+
return path.join(os.homedir(), rel);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function displayDir(rel) {
|
|
102
|
+
if (process.platform === 'win32') return '%USERPROFILE%\\' + rel.replace(/\//g, '\\');
|
|
103
|
+
return '~/' + rel;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function skillVersion() {
|
|
107
|
+
try {
|
|
108
|
+
const data = JSON.parse(fs.readFileSync(path.join(PKG_ROOT, 'package.json'), 'utf8'));
|
|
109
|
+
return data.version || null;
|
|
110
|
+
} catch (_) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function usage() {
|
|
116
|
+
console.log(SKILL_NAME + ' 安装器(YottaSkills)');
|
|
117
|
+
console.log('');
|
|
118
|
+
console.log('用法:');
|
|
119
|
+
console.log(' node bin/install.js --agent <name> 按智能体默认用户级目录安装(推荐)');
|
|
120
|
+
console.log(' node bin/install.js --dir <path> 装到指定目录(用户改了目录的智能体)');
|
|
121
|
+
console.log(' node bin/install.js -g 安装到全部已知智能体用户级目录');
|
|
122
|
+
console.log(' node bin/install.js 安装到检测到的项目级目录');
|
|
123
|
+
console.log('');
|
|
124
|
+
console.log('参数:');
|
|
125
|
+
console.log(' --agent <name> 智能体键名,见 --list');
|
|
126
|
+
console.log(' --dir <path> 自定义技能目录');
|
|
127
|
+
console.log(' -g, --global 安装到全部已知用户级目录');
|
|
128
|
+
console.log(' --list, -l 列出支持的智能体目录');
|
|
129
|
+
console.log(' --dry-run 只显示将写入的目标,不写文件');
|
|
130
|
+
console.log(' --version, -v 显示版本');
|
|
131
|
+
console.log(' --help, -h 显示帮助');
|
|
132
|
+
console.log(' --yes, -y 兼容参数(-g 不再强制要求)');
|
|
133
|
+
console.log('');
|
|
134
|
+
console.log('退出码: 0 成功 / 1 安装失败 / 2 用法错误 / 4 目标错误');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function parseArgs(argv) {
|
|
138
|
+
const opts = { help: false, version: false, list: false, global: false, dryRun: false, yes: false, dir: null, agent: null };
|
|
139
|
+
for (let i = 0; i < argv.length; i++) {
|
|
140
|
+
const arg = argv[i];
|
|
141
|
+
if (arg === '--help' || arg === '-h') opts.help = true;
|
|
142
|
+
else if (arg === '--version' || arg === '-v') opts.version = true;
|
|
143
|
+
else if (arg === '--list' || arg === '-l') opts.list = true;
|
|
144
|
+
else if (arg === '--global' || arg === '-g') opts.global = true;
|
|
145
|
+
else if (arg === '--dry-run') opts.dryRun = true;
|
|
146
|
+
else if (arg === '--yes' || arg === '-y') opts.yes = true;
|
|
147
|
+
else if (arg === '--dir') {
|
|
148
|
+
const value = argv[++i];
|
|
149
|
+
if (!value) throw new UsageError('--dir 需要一个非空路径');
|
|
150
|
+
opts.dir = value;
|
|
151
|
+
} else if (arg === '--agent') {
|
|
152
|
+
const value = argv[++i];
|
|
153
|
+
if (!value) throw new UsageError('--agent 需要一个非空名称');
|
|
154
|
+
opts.agent = String(value).toLowerCase();
|
|
155
|
+
} else {
|
|
156
|
+
throw new UsageError('未知参数: ' + arg);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (!opts.help && !opts.version) {
|
|
160
|
+
const selected = [opts.dir, opts.agent, opts.global].filter(Boolean).length;
|
|
161
|
+
if (selected > 1) throw new UsageError('--dir / --agent / -g 只能选一个');
|
|
162
|
+
}
|
|
163
|
+
return opts;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function printList() {
|
|
167
|
+
console.log('智能体 -> 默认技能目录(--agent <name> 装到第一个,用户级):');
|
|
168
|
+
for (const [key, value] of Object.entries(AGENT_DIRS)) {
|
|
169
|
+
const resolved = value.dirs.map(displayDir);
|
|
170
|
+
console.log(' ' + key.padEnd(10) + value.label.padEnd(18) + resolved.join('、'));
|
|
171
|
+
}
|
|
172
|
+
console.log('\n说明:Windows 用 %USERPROFILE%,Linux/macOS 用 ~;仅收录有官方默认目录的智能体。');
|
|
173
|
+
console.log('改了目录的请用 --dir <路径>,不要依赖默认位置;若设置了 CODEX_HOME / XDG_CONFIG_HOME,安装自动以该变量为准。');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function assertSafeTarget(target) {
|
|
177
|
+
const rel = path.relative(PKG_ROOT, target);
|
|
178
|
+
if (rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel))) {
|
|
179
|
+
throw new UsageError('目标目录不能在技能源目录内(防止自装自毁)');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function shouldSkipCache(name, isFile) {
|
|
184
|
+
if (CACHE_DIRS.has(name)) return true;
|
|
185
|
+
if (isFile && (name.endsWith('.pyc') || name.endsWith('.pyo'))) return true;
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function copyDir(src, dst, topLevel) {
|
|
190
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
191
|
+
// 只跳过安装包顶层开发文件;template/ 等嵌套同名载荷必须保留。
|
|
192
|
+
if (topLevel && TOP_SKIP_SET.has(entry.name)) continue;
|
|
193
|
+
if (shouldSkipCache(entry.name, entry.isFile())) continue;
|
|
194
|
+
const s = path.join(src, entry.name);
|
|
195
|
+
const d = path.join(dst, entry.name);
|
|
196
|
+
if (entry.isDirectory()) {
|
|
197
|
+
fs.mkdirSync(d, { recursive: true });
|
|
198
|
+
copyDir(s, d, false);
|
|
199
|
+
} else if (entry.isFile()) {
|
|
200
|
+
fs.copyFileSync(s, d);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 清理旧版安装残留(fail-closed 白名单):
|
|
206
|
+
// 仅在目标目录已存在且含 SKILL.md 时触发;只删顶层开发项 + 任意层级缓存;
|
|
207
|
+
// 不整目录删除、不跟随符号链接。
|
|
208
|
+
function cleanResidue(target) {
|
|
209
|
+
const removed = [];
|
|
210
|
+
let stat = null;
|
|
211
|
+
try { stat = fs.statSync(target); } catch (_) { return removed; }
|
|
212
|
+
if (!stat.isDirectory()) return removed;
|
|
213
|
+
if (!fs.existsSync(path.join(target, 'SKILL.md'))) return removed;
|
|
214
|
+
for (const name of TOP_SKIP) {
|
|
215
|
+
const p = path.join(target, name);
|
|
216
|
+
let entry = null;
|
|
217
|
+
try { entry = fs.lstatSync(p); } catch (_) { continue; }
|
|
218
|
+
if (entry.isSymbolicLink()) continue;
|
|
219
|
+
fs.rmSync(p, { recursive: true, force: true });
|
|
220
|
+
removed.push(name);
|
|
221
|
+
}
|
|
222
|
+
const walk = (dir) => {
|
|
223
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
224
|
+
const p = path.join(dir, entry.name);
|
|
225
|
+
if (entry.isSymbolicLink()) continue;
|
|
226
|
+
if (entry.isDirectory()) {
|
|
227
|
+
if (CACHE_DIRS.has(entry.name)) {
|
|
228
|
+
fs.rmSync(p, { recursive: true, force: true });
|
|
229
|
+
removed.push(path.relative(target, p));
|
|
230
|
+
} else {
|
|
231
|
+
walk(p);
|
|
232
|
+
}
|
|
233
|
+
} else if (entry.isFile() && (entry.name.endsWith('.pyc') || entry.name.endsWith('.pyo'))) {
|
|
234
|
+
fs.unlinkSync(p);
|
|
235
|
+
removed.push(path.relative(target, p));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
walk(target);
|
|
240
|
+
return removed;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function installTo(dest, opts) {
|
|
244
|
+
if (!dest || typeof dest !== 'string') throw new UsageError('目标目录不能为空');
|
|
245
|
+
const target = path.resolve(dest, SKILL_NAME);
|
|
246
|
+
assertSafeTarget(target);
|
|
247
|
+
if (opts.dryRun) {
|
|
248
|
+
console.log('[dry-run] 将安装到 -> ' + target);
|
|
249
|
+
return target;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
for (const rel of cleanResidue(target)) console.log('已清理残留: ' + rel);
|
|
253
|
+
fs.mkdirSync(target, { recursive: true });
|
|
254
|
+
copyDir(PKG_ROOT, target, true);
|
|
255
|
+
if (!fs.existsSync(path.join(target, 'SKILL.md'))) {
|
|
256
|
+
throw new InstallError('安装结果缺少 SKILL.md');
|
|
257
|
+
}
|
|
258
|
+
} catch (err) {
|
|
259
|
+
if (err instanceof UsageError || err instanceof TargetError || err instanceof InstallError) throw err;
|
|
260
|
+
throw new InstallError('安装到 ' + target + ' 失败: ' + err.message);
|
|
261
|
+
}
|
|
262
|
+
console.log('installed -> ' + target);
|
|
263
|
+
return target;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function run() {
|
|
267
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
268
|
+
if (opts.help) { usage(); return; }
|
|
269
|
+
if (opts.version) {
|
|
270
|
+
const version = skillVersion();
|
|
271
|
+
if (!version) {
|
|
272
|
+
console.error(SKILL_NAME + ' 版本未知(未找到 package.json)');
|
|
273
|
+
process.exitCode = 1;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
console.log(SKILL_NAME + ' v' + version);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (opts.list) { printList(); return; }
|
|
280
|
+
|
|
281
|
+
if (opts.dir) { installTo(opts.dir, opts); return; }
|
|
282
|
+
|
|
283
|
+
if (opts.agent) {
|
|
284
|
+
const info = AGENT_DIRS[opts.agent];
|
|
285
|
+
if (!info) {
|
|
286
|
+
throw new UsageError('未收录智能体: ' + opts.agent + '。可用: ' + Object.keys(AGENT_DIRS).join(', ') + ';自定义目录请用 --dir <路径>。');
|
|
287
|
+
}
|
|
288
|
+
installTo(resolveUserDir(info.dirs[0]), opts);
|
|
289
|
+
console.log('完成。');
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (opts.global) {
|
|
294
|
+
const seen = new Set();
|
|
295
|
+
for (const value of Object.values(AGENT_DIRS)) {
|
|
296
|
+
for (const rel of value.dirs) {
|
|
297
|
+
if (seen.has(rel)) continue;
|
|
298
|
+
seen.add(rel);
|
|
299
|
+
installTo(resolveUserDir(rel), opts);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (!opts.dryRun) console.log('完成。');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const dirs = PROJECT_DIRS.filter((d) => fs.existsSync(d));
|
|
307
|
+
if (!dirs.length) {
|
|
308
|
+
throw new TargetError('未检测到项目级智能体目录。可用 --agent <name> 装到用户级,或用 --dir <路径> 指定目录。');
|
|
309
|
+
}
|
|
310
|
+
for (const dir of dirs) installTo(dir, opts);
|
|
311
|
+
if (!opts.dryRun) console.log('完成。');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function main() {
|
|
315
|
+
try {
|
|
316
|
+
run();
|
|
317
|
+
} catch (err) {
|
|
318
|
+
if (err instanceof UsageError) {
|
|
319
|
+
console.error('用法错误: ' + err.message);
|
|
320
|
+
usage();
|
|
321
|
+
process.exitCode = 2;
|
|
322
|
+
} else if (err instanceof TargetError) {
|
|
323
|
+
console.error('目标错误: ' + err.message);
|
|
324
|
+
process.exitCode = 4;
|
|
325
|
+
} else if (err instanceof InstallError) {
|
|
326
|
+
console.error('安装失败: ' + err.message);
|
|
327
|
+
console.error('修复建议: 检查目录权限与磁盘空间后重试,或用 --dir 换一个目录。');
|
|
328
|
+
process.exitCode = 1;
|
|
329
|
+
} else {
|
|
330
|
+
console.error('未知错误: ' + (err && err.message ? err.message : String(err)));
|
|
331
|
+
process.exitCode = 1;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
main();
|