@aiyiran/myclaw 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/index.js +140 -69
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -1,87 +1,143 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* ============================================================================
|
|
5
|
+
* MyClaw - 学生友好的 OpenClaw 工具
|
|
6
|
+
* ============================================================================
|
|
7
|
+
*
|
|
8
|
+
* 跨平台要求 / Cross-Platform Requirements:
|
|
9
|
+
* ----------------------------------------
|
|
10
|
+
* 本脚本支持 macOS、Linux 和 Windows。
|
|
11
|
+
*
|
|
12
|
+
* Windows 支持说明:
|
|
13
|
+
* - Windows 10+ (Build 1053+) 原生支持 ANSI 颜色代码
|
|
14
|
+
* - Windows 7/8/10 旧版本: 颜色代码会被 stripped,避免乱码
|
|
15
|
+
* - 推荐 Windows 用户使用 Windows Terminal 或 PowerShell 7+ 获得最佳体验
|
|
16
|
+
* - Emoji 符号在 Windows 命令行可能显示为方块,属正常现象
|
|
17
|
+
*
|
|
18
|
+
* 测试环境:
|
|
19
|
+
* - macOS: ✅ 完全支持
|
|
20
|
+
* - Linux: ✅ 完全支持
|
|
21
|
+
* - Windows 10/11 (PowerShell/CMD): ✅ 基本支持
|
|
22
|
+
*
|
|
23
|
+
* ============================================================================
|
|
24
|
+
*/
|
|
25
|
+
|
|
3
26
|
const { execSync } = require('child_process');
|
|
4
27
|
const os = require('os');
|
|
5
28
|
|
|
6
29
|
const args = process.argv.slice(2);
|
|
7
30
|
const command = args[0];
|
|
8
31
|
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// 跨平台检测
|
|
34
|
+
// ============================================================================
|
|
35
|
+
|
|
9
36
|
function detectPlatform() {
|
|
10
37
|
const platform = os.platform();
|
|
11
38
|
if (platform === 'win32') return 'windows';
|
|
12
|
-
if (platform === 'darwin' || platform === 'linux') return 'mac';
|
|
39
|
+
if (platform === 'darwin' || platform === 'linux') return 'mac';
|
|
13
40
|
return 'unknown';
|
|
14
41
|
}
|
|
15
42
|
|
|
43
|
+
const isWindows = detectPlatform() === 'windows';
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// 跨平台颜色输出
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 颜色输出函数 - 自动兼容 Windows
|
|
51
|
+
* Windows 旧版本会 stripped ANSI 颜色代码,避免乱码
|
|
52
|
+
*/
|
|
53
|
+
function makeColors() {
|
|
54
|
+
if (isWindows) {
|
|
55
|
+
// Windows: 禁用颜色,strip ANSI codes
|
|
56
|
+
return {
|
|
57
|
+
red: '',
|
|
58
|
+
green: '',
|
|
59
|
+
yellow: '',
|
|
60
|
+
blue: '',
|
|
61
|
+
nc: ''
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// macOS/Linux: 正常 ANSI 颜色
|
|
65
|
+
return {
|
|
66
|
+
red: '\x1b[31m',
|
|
67
|
+
green: '\x1b[32m',
|
|
68
|
+
yellow: '\x1b[33m',
|
|
69
|
+
blue: '\x1b[34m',
|
|
70
|
+
nc: '\x1b[0m'
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const colors = makeColors();
|
|
75
|
+
|
|
76
|
+
// ============================================================================
|
|
77
|
+
// 安装命令
|
|
78
|
+
// ============================================================================
|
|
79
|
+
|
|
16
80
|
function runInstall() {
|
|
17
81
|
const platform = detectPlatform();
|
|
18
82
|
|
|
19
83
|
if (platform === 'windows') {
|
|
20
|
-
console.log('
|
|
84
|
+
console.log('[Windows] 检测到 Windows 系统,正在安装...');
|
|
21
85
|
const cmd = 'powershell -c "irm https://openclaw.ai/install.ps1 | iex"';
|
|
22
|
-
console.log(
|
|
86
|
+
console.log('> ' + cmd);
|
|
23
87
|
try {
|
|
24
88
|
execSync(cmd, { stdio: 'inherit' });
|
|
25
89
|
} catch (err) {
|
|
26
|
-
console.error('
|
|
90
|
+
console.error('[错误] 安装失败:', err.message);
|
|
27
91
|
process.exit(1);
|
|
28
92
|
}
|
|
29
93
|
} else if (platform === 'mac') {
|
|
30
|
-
console.log('
|
|
94
|
+
console.log('[macOS/Linux] 检测到系统,正在安装...');
|
|
31
95
|
const cmd = 'curl -fsSL https://openclaw.ai/install.sh | bash';
|
|
32
|
-
console.log(
|
|
96
|
+
console.log('> ' + cmd);
|
|
33
97
|
try {
|
|
34
98
|
execSync(cmd, { stdio: 'inherit' });
|
|
35
99
|
} catch (err) {
|
|
36
|
-
console.error('
|
|
100
|
+
console.error('[错误] 安装失败:', err.message);
|
|
37
101
|
process.exit(1);
|
|
38
102
|
}
|
|
39
103
|
} else {
|
|
40
|
-
console.error('
|
|
104
|
+
console.error('[错误] 不支持的操作系统:', os.platform());
|
|
41
105
|
process.exit(1);
|
|
42
106
|
}
|
|
43
107
|
}
|
|
44
108
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
green: '\x1b[32m',
|
|
49
|
-
yellow: '\x1b[33m',
|
|
50
|
-
blue: '\x1b[34m',
|
|
51
|
-
nc: '\x1b[0m' // No Color
|
|
52
|
-
};
|
|
109
|
+
// ============================================================================
|
|
110
|
+
// 状态命令
|
|
111
|
+
// ============================================================================
|
|
53
112
|
|
|
54
113
|
function runStatus() {
|
|
114
|
+
const bar = '----------------------------------------';
|
|
115
|
+
|
|
55
116
|
console.log('');
|
|
56
|
-
console.log(colors.blue + '
|
|
57
|
-
console.log(
|
|
58
|
-
console.log(colors.blue + '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' + colors.nc);
|
|
117
|
+
console.log('[' + colors.blue + 'MyClaw' + colors.nc + '] ' + colors.blue + '状态面板' + colors.nc);
|
|
118
|
+
console.log(bar);
|
|
59
119
|
console.log('');
|
|
60
|
-
|
|
120
|
+
|
|
61
121
|
// Gateway 状态
|
|
62
|
-
console.log(
|
|
122
|
+
console.log('[Gateway]');
|
|
63
123
|
try {
|
|
64
124
|
execSync('openclaw health', { stdio: 'pipe' });
|
|
65
|
-
console.log(' 状态: ' + colors.green + '
|
|
125
|
+
console.log(' 状态: ' + colors.green + '[OK] 运行中' + colors.nc);
|
|
66
126
|
try {
|
|
67
127
|
const statusOutput = execSync('openclaw status 2>/dev/null', { encoding: 'utf8' });
|
|
68
128
|
const dashboardMatch = statusOutput.match(/Dashboard[^\n]*?(http:\/\/[^\s]+)/);
|
|
69
|
-
|
|
70
|
-
console.log(' 控制台: ' + dashboardMatch[1]);
|
|
71
|
-
} else {
|
|
72
|
-
console.log(' 控制台: http://127.0.0.1:18789');
|
|
73
|
-
}
|
|
129
|
+
console.log(' 控制台: ' + (dashboardMatch ? dashboardMatch[1] : 'http://127.0.0.1:18789'));
|
|
74
130
|
} catch {
|
|
75
131
|
console.log(' 控制台: http://127.0.0.1:18789');
|
|
76
132
|
}
|
|
77
133
|
} catch (err) {
|
|
78
|
-
console.log(' 状态: ' + colors.red + '
|
|
79
|
-
console.log('
|
|
134
|
+
console.log(' 状态: ' + colors.red + '[ERROR] 未运行' + colors.nc);
|
|
135
|
+
console.log(' 启动命令: ' + colors.yellow + 'openclaw gateway' + colors.nc);
|
|
80
136
|
}
|
|
81
137
|
console.log('');
|
|
82
|
-
|
|
138
|
+
|
|
83
139
|
// Session 数量
|
|
84
|
-
console.log(
|
|
140
|
+
console.log('[Sessions]');
|
|
85
141
|
try {
|
|
86
142
|
const sessionsOutput = execSync('openclaw sessions list 2>/dev/null', { encoding: 'utf8' });
|
|
87
143
|
const sessionCount = (sessionsOutput.match(/agent:/g) || []).length;
|
|
@@ -90,9 +146,9 @@ function runStatus() {
|
|
|
90
146
|
console.log(' 活跃会话: ' + colors.red + '0' + colors.nc + ' 个');
|
|
91
147
|
}
|
|
92
148
|
console.log('');
|
|
93
|
-
|
|
149
|
+
|
|
94
150
|
// Agent 数量
|
|
95
|
-
console.log(
|
|
151
|
+
console.log('[Agents]');
|
|
96
152
|
try {
|
|
97
153
|
const agentsOutput = execSync('openclaw agents list 2>/dev/null', { encoding: 'utf8' });
|
|
98
154
|
const agentCount = (agentsOutput.match(/agent:/g) || []).length;
|
|
@@ -101,9 +157,9 @@ function runStatus() {
|
|
|
101
157
|
console.log(' 已注册 Agent: ' + colors.red + '0' + colors.nc + ' 个');
|
|
102
158
|
}
|
|
103
159
|
console.log('');
|
|
104
|
-
|
|
160
|
+
|
|
105
161
|
// 最近活动
|
|
106
|
-
console.log(
|
|
162
|
+
console.log('[最近活动]');
|
|
107
163
|
try {
|
|
108
164
|
const sessionsOutput = execSync('openclaw sessions list 2>/dev/null', { encoding: 'utf8' });
|
|
109
165
|
const lines = sessionsOutput.split('\n').filter(line =>
|
|
@@ -121,30 +177,34 @@ function runStatus() {
|
|
|
121
177
|
console.log(' 无最近活动');
|
|
122
178
|
}
|
|
123
179
|
console.log('');
|
|
124
|
-
|
|
125
|
-
console.log(
|
|
180
|
+
|
|
181
|
+
console.log(bar);
|
|
126
182
|
console.log('提示: 运行 ' + colors.yellow + 'openclaw status' + colors.nc + ' 查看完整状态');
|
|
127
183
|
console.log(' 运行 ' + colors.yellow + 'myclaw help' + colors.nc + ' 查看所有命令');
|
|
128
184
|
console.log('');
|
|
129
185
|
}
|
|
130
186
|
|
|
187
|
+
// ============================================================================
|
|
188
|
+
// 创建新 Agent
|
|
189
|
+
// ============================================================================
|
|
190
|
+
|
|
131
191
|
function runNew() {
|
|
132
192
|
const agentName = args[1];
|
|
133
193
|
|
|
134
194
|
if (!agentName) {
|
|
135
|
-
console.error('
|
|
195
|
+
console.error('[' + colors.red + '错误' + colors.nc + '] 请提供 Agent 名称');
|
|
136
196
|
console.log('');
|
|
137
197
|
console.log('用法: myclaw new <agent名称>');
|
|
138
198
|
console.log('');
|
|
139
199
|
console.log('示例:');
|
|
140
200
|
console.log(' myclaw new helper # 创建名为 helper 的 Agent');
|
|
141
|
-
console.log(' myclaw new testbot
|
|
201
|
+
console.log(' myclaw new testbot # 创建名为 testbot 的 Agent');
|
|
142
202
|
process.exit(1);
|
|
143
203
|
}
|
|
144
204
|
|
|
145
205
|
// 验证名称格式
|
|
146
206
|
if (!/^[a-z0-9-]+$/.test(agentName)) {
|
|
147
|
-
console.error('
|
|
207
|
+
console.error('[' + colors.red + '错误' + colors.nc + '] Agent 名称只能包含小写字母、数字和连字符(-)');
|
|
148
208
|
console.log('');
|
|
149
209
|
console.log('示例:');
|
|
150
210
|
console.log(' myclaw new helper');
|
|
@@ -152,17 +212,18 @@ function runNew() {
|
|
|
152
212
|
process.exit(1);
|
|
153
213
|
}
|
|
154
214
|
|
|
215
|
+
const bar = '----------------------------------------';
|
|
216
|
+
|
|
155
217
|
console.log('');
|
|
156
|
-
console.log(colors.blue + '
|
|
157
|
-
console.log(
|
|
158
|
-
console.log(colors.blue + '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' + colors.nc);
|
|
218
|
+
console.log('[' + colors.blue + 'MyClaw' + colors.nc + '] ' + colors.blue + '创建新 Agent: ' + agentName + colors.nc);
|
|
219
|
+
console.log(bar);
|
|
159
220
|
console.log('');
|
|
160
221
|
|
|
161
222
|
// 检查是否已存在
|
|
162
223
|
try {
|
|
163
224
|
const agentsOutput = execSync('openclaw agents list 2>/dev/null', { encoding: 'utf8' });
|
|
164
225
|
if (agentsOutput.includes(`agent:${agentName}:`)) {
|
|
165
|
-
console.error('
|
|
226
|
+
console.error('[' + colors.red + '错误' + colors.nc + '] Agent "' + agentName + '" 已存在');
|
|
166
227
|
process.exit(1);
|
|
167
228
|
}
|
|
168
229
|
} catch (e) {
|
|
@@ -172,14 +233,14 @@ function runNew() {
|
|
|
172
233
|
// 查找 yiran-agent-birth 脚本
|
|
173
234
|
const birthScript = '/Users/yiran/.openclaw/workspace/skills/yiran-agent-birth/scripts/create_agent.py';
|
|
174
235
|
|
|
175
|
-
console.log(
|
|
236
|
+
console.log('[创建中] 正在创建 Agent...');
|
|
176
237
|
|
|
177
238
|
try {
|
|
178
239
|
const result = execSync(`python3 "${birthScript}" ${agentName}`, { encoding: 'utf8' });
|
|
179
240
|
const jsonResult = JSON.parse(result);
|
|
180
241
|
|
|
181
242
|
console.log('');
|
|
182
|
-
console.log(colors.green + '
|
|
243
|
+
console.log('[' + colors.green + '成功' + colors.nc + '] Agent 创建成功!');
|
|
183
244
|
console.log('');
|
|
184
245
|
console.log(' 名称: ' + agentName);
|
|
185
246
|
console.log(' Session: ' + jsonResult.sessionKey);
|
|
@@ -187,18 +248,18 @@ function runNew() {
|
|
|
187
248
|
console.log('');
|
|
188
249
|
|
|
189
250
|
if (jsonResult.firstMessageSent) {
|
|
190
|
-
console.log(colors.green + '
|
|
251
|
+
console.log('[' + colors.green + 'OK' + colors.nc + '] 出生消息已发送');
|
|
191
252
|
} else {
|
|
192
|
-
console.log(colors.yellow + '
|
|
253
|
+
console.log('[' + colors.yellow + '警告' + colors.nc + '] 出生消息发送失败,可手动重试');
|
|
193
254
|
}
|
|
194
255
|
|
|
195
256
|
console.log('');
|
|
196
|
-
console.log(
|
|
257
|
+
console.log(bar);
|
|
197
258
|
console.log('下一步: 运行 ' + colors.yellow + `openclaw agent --agent ${agentName} --message "你好"` + colors.nc + ' 与它对话');
|
|
198
259
|
console.log('');
|
|
199
260
|
|
|
200
261
|
} catch (err) {
|
|
201
|
-
console.error('
|
|
262
|
+
console.error('[' + colors.red + '错误' + colors.nc + '] 创建失败:', err.message);
|
|
202
263
|
console.log('');
|
|
203
264
|
console.log('常见问题:');
|
|
204
265
|
console.log(' - Agent 名称已存在');
|
|
@@ -208,27 +269,37 @@ function runNew() {
|
|
|
208
269
|
}
|
|
209
270
|
}
|
|
210
271
|
|
|
272
|
+
// ============================================================================
|
|
273
|
+
// 帮助信息
|
|
274
|
+
// ============================================================================
|
|
275
|
+
|
|
211
276
|
function showHelp() {
|
|
212
|
-
console.log(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
277
|
+
console.log('');
|
|
278
|
+
console.log('MyClaw - 学生友好的 OpenClaw 工具');
|
|
279
|
+
console.log('----------------------------------------');
|
|
280
|
+
console.log('');
|
|
281
|
+
console.log('用法:');
|
|
282
|
+
console.log(' myclaw <command>');
|
|
283
|
+
console.log('');
|
|
284
|
+
console.log('命令:');
|
|
285
|
+
console.log(' install 安装 OpenClaw 服务');
|
|
286
|
+
console.log(' status 简化版状态查看(学生友好)');
|
|
287
|
+
console.log(' new 创建新的 Agent(学生练习用)');
|
|
288
|
+
console.log(' help 显示帮助信息');
|
|
289
|
+
console.log('');
|
|
290
|
+
console.log('示例:');
|
|
291
|
+
console.log(' myclaw install # 安装 OpenClaw');
|
|
292
|
+
console.log(' myclaw status # 查看状态');
|
|
293
|
+
console.log(' myclaw new helper # 创建名为 helper 的 Agent');
|
|
294
|
+
console.log('');
|
|
295
|
+
console.log('跨平台: macOS / Linux / Windows (PowerShell/CMD)');
|
|
296
|
+
console.log('');
|
|
229
297
|
}
|
|
230
298
|
|
|
299
|
+
// ============================================================================
|
|
231
300
|
// 主逻辑
|
|
301
|
+
// ============================================================================
|
|
302
|
+
|
|
232
303
|
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
233
304
|
showHelp();
|
|
234
305
|
} else if (command === 'install') {
|
|
@@ -238,7 +309,7 @@ if (!command || command === 'help' || command === '--help' || command === '-h')
|
|
|
238
309
|
} else if (command === 'new') {
|
|
239
310
|
runNew();
|
|
240
311
|
} else {
|
|
241
|
-
console.error('
|
|
312
|
+
console.error('[' + colors.red + '错误' + colors.nc + '] 未知命令: ' + command);
|
|
242
313
|
showHelp();
|
|
243
314
|
process.exit(1);
|
|
244
|
-
}
|
|
315
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiyiran/myclaw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"myclaw": "index.js"
|
|
7
|
+
"myclaw": "index.js",
|
|
8
|
+
"mc": "index.js"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -12,4 +13,4 @@
|
|
|
12
13
|
"keywords": [],
|
|
13
14
|
"author": "",
|
|
14
15
|
"license": "ISC"
|
|
15
|
-
}
|
|
16
|
+
}
|