@aiyiran/myclaw 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/index.js +243 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,2 +1,244 @@
1
1
  #!/usr/bin/env node
2
- console.log("Hello,I Am The Child, I Am The World! :)")
2
+
3
+ const { execSync } = require('child_process');
4
+ const os = require('os');
5
+
6
+ const args = process.argv.slice(2);
7
+ const command = args[0];
8
+
9
+ function detectPlatform() {
10
+ const platform = os.platform();
11
+ if (platform === 'win32') return 'windows';
12
+ if (platform === 'darwin' || platform === 'linux') return 'mac'; // mac/linux 都用 bash
13
+ return 'unknown';
14
+ }
15
+
16
+ function runInstall() {
17
+ const platform = detectPlatform();
18
+
19
+ if (platform === 'windows') {
20
+ console.log('🪟 检测到 Windows 系统,正在安装...');
21
+ const cmd = 'powershell -c "irm https://openclaw.ai/install.ps1 | iex"';
22
+ console.log(`> ${cmd}`);
23
+ try {
24
+ execSync(cmd, { stdio: 'inherit' });
25
+ } catch (err) {
26
+ console.error('❌ 安装失败:', err.message);
27
+ process.exit(1);
28
+ }
29
+ } else if (platform === 'mac') {
30
+ console.log('🍎 检测到 macOS/Linux 系统,正在安装...');
31
+ const cmd = 'curl -fsSL https://openclaw.ai/install.sh | bash';
32
+ console.log(`> ${cmd}`);
33
+ try {
34
+ execSync(cmd, { stdio: 'inherit' });
35
+ } catch (err) {
36
+ console.error('❌ 安装失败:', err.message);
37
+ process.exit(1);
38
+ }
39
+ } else {
40
+ console.error('❌ 不支持的操作系统:', os.platform());
41
+ process.exit(1);
42
+ }
43
+ }
44
+
45
+ // 颜色输出
46
+ const colors = {
47
+ red: '\x1b[31m',
48
+ green: '\x1b[32m',
49
+ yellow: '\x1b[33m',
50
+ blue: '\x1b[34m',
51
+ nc: '\x1b[0m' // No Color
52
+ };
53
+
54
+ function runStatus() {
55
+ console.log('');
56
+ console.log(colors.blue + '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' + colors.nc);
57
+ console.log(colors.blue + ' 🦞 MyClaw 状态面板' + colors.nc);
58
+ console.log(colors.blue + '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' + colors.nc);
59
+ console.log('');
60
+
61
+ // Gateway 状态
62
+ console.log(colors.yellow + '▸ Gateway' + colors.nc);
63
+ try {
64
+ execSync('openclaw health', { stdio: 'pipe' });
65
+ console.log(' 状态: ' + colors.green + '✓ 运行中' + colors.nc);
66
+ try {
67
+ const statusOutput = execSync('openclaw status 2>/dev/null', { encoding: 'utf8' });
68
+ const dashboardMatch = statusOutput.match(/Dashboard[^\n]*?(http:\/\/[^\s]+)/);
69
+ if (dashboardMatch) {
70
+ console.log(' 控制台: ' + dashboardMatch[1]);
71
+ } else {
72
+ console.log(' 控制台: http://127.0.0.1:18789');
73
+ }
74
+ } catch {
75
+ console.log(' 控制台: http://127.0.0.1:18789');
76
+ }
77
+ } catch (err) {
78
+ console.log(' 状态: ' + colors.red + '✗ 未运行' + colors.nc);
79
+ console.log(' 启动: ' + colors.yellow + 'openclaw gateway' + colors.nc);
80
+ }
81
+ console.log('');
82
+
83
+ // Session 数量
84
+ console.log(colors.yellow + '▸ Sessions' + colors.nc);
85
+ try {
86
+ const sessionsOutput = execSync('openclaw sessions list 2>/dev/null', { encoding: 'utf8' });
87
+ const sessionCount = (sessionsOutput.match(/agent:/g) || []).length;
88
+ console.log(' 活跃会话: ' + colors.green + sessionCount + colors.nc + ' 个');
89
+ } catch {
90
+ console.log(' 活跃会话: ' + colors.red + '0' + colors.nc + ' 个');
91
+ }
92
+ console.log('');
93
+
94
+ // Agent 数量
95
+ console.log(colors.yellow + '▸ Agents' + colors.nc);
96
+ try {
97
+ const agentsOutput = execSync('openclaw agents list 2>/dev/null', { encoding: 'utf8' });
98
+ const agentCount = (agentsOutput.match(/agent:/g) || []).length;
99
+ console.log(' 已注册 Agent: ' + colors.green + agentCount + colors.nc + ' 个');
100
+ } catch {
101
+ console.log(' 已注册 Agent: ' + colors.red + '0' + colors.nc + ' 个');
102
+ }
103
+ console.log('');
104
+
105
+ // 最近活动
106
+ console.log(colors.yellow + '▸ 最近活动' + colors.nc);
107
+ try {
108
+ const sessionsOutput = execSync('openclaw sessions list 2>/dev/null', { encoding: 'utf8' });
109
+ const lines = sessionsOutput.split('\n').filter(line =>
110
+ line.includes('just now') || /\d+m ago/.test(line) || /\d+h ago/.test(line)
111
+ ).slice(0, 3);
112
+
113
+ if (lines.length > 0) {
114
+ lines.forEach(line => {
115
+ console.log(' ' + line.trim());
116
+ });
117
+ } else {
118
+ console.log(' 无最近活动');
119
+ }
120
+ } catch {
121
+ console.log(' 无最近活动');
122
+ }
123
+ console.log('');
124
+
125
+ console.log(colors.blue + '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' + colors.nc);
126
+ console.log('提示: 运行 ' + colors.yellow + 'openclaw status' + colors.nc + ' 查看完整状态');
127
+ console.log(' 运行 ' + colors.yellow + 'myclaw help' + colors.nc + ' 查看所有命令');
128
+ console.log('');
129
+ }
130
+
131
+ function runNew() {
132
+ const agentName = args[1];
133
+
134
+ if (!agentName) {
135
+ console.error('\x1b[31m❌ 请提供 Agent 名称\x1b[0m');
136
+ console.log('');
137
+ console.log('用法: myclaw new <agent名称>');
138
+ console.log('');
139
+ console.log('示例:');
140
+ console.log(' myclaw new helper # 创建名为 helper 的 Agent');
141
+ console.log(' myclaw new testbot # 创建名为 testbot 的 Agent');
142
+ process.exit(1);
143
+ }
144
+
145
+ // 验证名称格式
146
+ if (!/^[a-z0-9-]+$/.test(agentName)) {
147
+ console.error('\x1b[31m❌ Agent 名称只能包含小写字母、数字和连字符(-)\x1b[0m');
148
+ console.log('');
149
+ console.log('示例:');
150
+ console.log(' myclaw new helper');
151
+ console.log(' myclaw new my-bot');
152
+ process.exit(1);
153
+ }
154
+
155
+ console.log('');
156
+ console.log(colors.blue + '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' + colors.nc);
157
+ console.log(colors.blue + ' 🦞 创建新 Agent: ' + agentName + colors.nc);
158
+ console.log(colors.blue + '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' + colors.nc);
159
+ console.log('');
160
+
161
+ // 检查是否已存在
162
+ try {
163
+ const agentsOutput = execSync('openclaw agents list 2>/dev/null', { encoding: 'utf8' });
164
+ if (agentsOutput.includes(`agent:${agentName}:`)) {
165
+ console.error('\x1b[31m❌ Agent "' + agentName + '" 已存在\x1b[0m');
166
+ process.exit(1);
167
+ }
168
+ } catch (e) {
169
+ // 继续创建
170
+ }
171
+
172
+ // 查找 yiran-agent-birth 脚本
173
+ const birthScript = '/Users/yiran/.openclaw/workspace/skills/yiran-agent-birth/scripts/create_agent.py';
174
+
175
+ console.log(colors.yellow + '▸ 正在创建 Agent...' + colors.nc);
176
+
177
+ try {
178
+ const result = execSync(`python3 "${birthScript}" ${agentName}`, { encoding: 'utf8' });
179
+ const jsonResult = JSON.parse(result);
180
+
181
+ console.log('');
182
+ console.log(colors.green + '✓ Agent 创建成功!' + colors.nc);
183
+ console.log('');
184
+ console.log(' 名称: ' + agentName);
185
+ console.log(' Session: ' + jsonResult.sessionKey);
186
+ console.log(' Workspace: ' + jsonResult.workspace);
187
+ console.log('');
188
+
189
+ if (jsonResult.firstMessageSent) {
190
+ console.log(colors.green + '✓ 出生消息已发送' + colors.nc);
191
+ } else {
192
+ console.log(colors.yellow + '⚠ 出生消息发送失败,可手动重试' + colors.nc);
193
+ }
194
+
195
+ console.log('');
196
+ console.log(colors.blue + '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' + colors.nc);
197
+ console.log('下一步: 运行 ' + colors.yellow + `openclaw agent --agent ${agentName} --message "你好"` + colors.nc + ' 与它对话');
198
+ console.log('');
199
+
200
+ } catch (err) {
201
+ console.error('\x1b[31m❌ 创建失败: ' + err.message + '\x1b[0m');
202
+ console.log('');
203
+ console.log('常见问题:');
204
+ console.log(' - Agent 名称已存在');
205
+ console.log(' - 权限不足');
206
+ console.log(' - OpenClaw 未运行');
207
+ process.exit(1);
208
+ }
209
+ }
210
+
211
+ function showHelp() {
212
+ console.log(`
213
+ myclaw - OpenClaw CLI 工具
214
+
215
+ 用法:
216
+ myclaw <command>
217
+
218
+ 命令:
219
+ install 安装 OpenClaw 服务
220
+ status 简化版状态查看(学生友好)
221
+ new 创建新的 Agent(学生练习用)
222
+ help 显示帮助信息
223
+
224
+ 示例:
225
+ myclaw install # 安装 OpenClaw
226
+ myclaw status # 查看状态
227
+ myclaw new helper # 创建名为 helper 的 Agent
228
+ `);
229
+ }
230
+
231
+ // 主逻辑
232
+ if (!command || command === 'help' || command === '--help' || command === '-h') {
233
+ showHelp();
234
+ } else if (command === 'install') {
235
+ runInstall();
236
+ } else if (command === 'status') {
237
+ runStatus();
238
+ } else if (command === 'new') {
239
+ runNew();
240
+ } else {
241
+ console.error('\x1b[31m❌ 未知命令: ' + command + '\x1b[0m');
242
+ showHelp();
243
+ process.exit(1);
244
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {