@aiyiran/myclaw 1.0.47 → 1.0.49

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 (3) hide show
  1. package/README.md +194 -85
  2. package/index.js +46 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,126 +1,235 @@
1
- # MyClaw - 学生友好的 OpenClaw 工具
1
+ # MyClaw CLI
2
2
 
3
- 一个简化 OpenClaw 日常操作的命令行工具,专为教学环境设计。
3
+ OpenClaw 教学环境设计的一站式命令行工具。
4
4
 
5
- ## 跨平台要求 ⚠️
5
+ ```bash
6
+ npm install -g @aiyiran/myclaw
7
+ ```
8
+
9
+ ---
10
+
11
+ ## 命令速查
12
+
13
+ | 命令 | 说明 | 平台 |
14
+ |------|------|------|
15
+ | `myclaw prepare` | 🚀 一键初始化(推荐第一次用) | 全平台 |
16
+ | `myclaw open` | 打开浏览器(自动带 Token) | 全平台 |
17
+ | `myclaw update` `up` | 强制升级 MyClaw 到最新版(无缓存) | 全平台 |
18
+ | `myclaw patch` | 注入 UI 扩展(语音输入等) | Mac/Linux |
19
+ | `myclaw unpatch` | 移除 UI 扩展 | Mac/Linux |
20
+ | `myclaw install` | 安装 OpenClaw | 全平台 |
21
+ | `myclaw status` | 查看 Gateway / Agent 状态 | 全平台 |
22
+ | `myclaw new <name>` | 创建新 Agent | 全平台 |
23
+ | `myclaw restart` | 重启 Gateway | 全平台 |
24
+ | `myclaw bat` | 生成 Windows 桌面快捷启动器 | Windows |
25
+ | `myclaw wsl2` | WSL2 安装向导 | Windows |
26
+ | `myclaw weixin` | 微信绑定向导 | 全平台 |
27
+ | `myclaw rebind` | 微信重绑向导 | 全平台 |
28
+ | `myclaw help` | 显示帮助 | 全平台 |
29
+
30
+ ---
31
+
32
+ ## 核心流程
33
+
34
+ ### `myclaw prepare` — 初始化链条
35
+
36
+ 自动检测环境并按需执行安装、配置、注入:
6
37
 
7
38
  ```
8
- ╔══════════════════════════════════════════════════════════════════════╗
9
- ║ 跨平台兼容性说明 ║
10
- ╠══════════════════════════════════════════════════════════════════════╣
11
- ║ ║
12
- ║ 支持系统: ║
13
- ║ ✅ macOS - 完全支持,包括颜色和 Emoji ║
14
- ║ ✅ Linux - 完全支持,包括颜色和 Emoji ║
15
- ║ ✅ Windows 10/11 - 基本支持,推荐使用 Windows Terminal ║
16
- ║ ⚠️ Windows 7/8 - 支持,但 Emoji 可能显示为方块 ║
17
- ║ ║
18
- ║ Windows 用户建议: ║
19
- ║ • 安装 Windows Terminal (Microsoft Store 免费下载) ║
20
- ║ • 或使用 PowerShell 7+ (https://aka.ms/powershell) ║
21
- ║ ║
22
- ║ 颜色说明: ║
23
- ║ • macOS/Linux: 正常显示 ANSI 颜色 ║
24
- ║ • Windows: 自动禁用颜色输出,避免乱码 ║
25
- ║ ║
26
- ╚══════════════════════════════════════════════════════════════════════╝
39
+ Step 1: 检测环境 (Mac / Windows / Linux / WSL)
40
+ Step 2: 检测 Chrome 浏览器
41
+ Step 3: 检测 OpenClaw → 未装则安装
42
+ Step 4: 执行 Patch(受 AUTO_PATCH 开关控制)
43
+ Step 5: [Windows] 生成桌面快捷启动器
27
44
  ```
28
45
 
29
- ## 安装
46
+ **触发方式:**
47
+ - 手动运行 `myclaw prepare`
48
+ - `npm install -g @aiyiran/myclaw` 时通过 `postinstall` 自动触发
30
49
 
31
- ```bash
32
- # 方式一: 直接运行
33
- node myclaw/index.js <command>
50
+ **postinstall 模式(无交互):**
51
+ - OpenClaw 已装 → 自动 patch
52
+ - OpenClaw 未装 → 跳过,提示手动安装
53
+ - 不会弹出 y/n 询问
34
54
 
35
- # 方式二: 添加到 PATH (macOS/Linux)
36
- ln -s /path/to/myclaw/index.js /usr/local/bin/myclaw
37
- chmod +x /usr/local/bin/myclaw
55
+ ---
38
56
 
39
- # 方式三: Windows PowerShell
40
- # 将 myclaw/index.js 路径添加到系统 PATH
57
+ ### `myclaw bat` — Windows 桌面启动器
58
+
59
+ 生成一个 `.bat` 启动脚本 + 桌面快捷方式,双击即可智能启动。
60
+
61
+ **快捷方式命名规则:**
62
+ ```
63
+ 版本号_OpenClaw_MM-DD_HH-MM-SS.lnk
64
+ 例: 1.0.46_OpenClaw_04-01_00-36-19.lnk
41
65
  ```
42
66
 
43
- ## 使用方法
67
+ > 通过桌面图标名称可验证 prepare 是否执行过,以及执行的版本和时间。
68
+
69
+ **双击后的完整流程:**
44
70
 
45
- ### 查看状态
46
- ```bash
47
- myclaw status
48
71
  ```
49
- 简化版的 OpenClaw 状态面板,一眼看清 Gateway、Agents、Sessions 状态。
72
+ Gateway 未运行:
73
+ [1/5] WSL → 检测/安装 WSL2
74
+ [2/5] OpenClaw Linux → 检测/导入 WSL 发行版
75
+ [3/5] Gateway → 未运行 → 更新 myclaw
76
+ [4/5] Patch → 注入 UI 扩展
77
+ [5/5] Browser → myclaw open(带 Token)
78
+ → 启动 openclaw gateway(保持窗口)
79
+
80
+ Gateway 已运行:
81
+ [1/4] WSL
82
+ [2/4] OpenClaw Linux
83
+ [3/4] Gateway → 已运行
84
+ [4/4] Browser → myclaw open(带 Token)
85
+ → 进入 WSL 终端(cd /root/.openclaw)
86
+ ```
87
+
88
+ ---
89
+
90
+ ### `myclaw patch` — UI 扩展注入
91
+
92
+ 向 OpenClaw 的 control-ui 注入自定义功能:
93
+ - `myclaw-inject.js` — 自定义 UI 逻辑
94
+ - `voice-input.js` — 语音输入 SDK
95
+
96
+ **原理:** 修改 `control-ui/index.html`,在 `</body>` 前插入 `<script>` 标签。
50
97
 
51
- ### 创建新 Agent
52
98
  ```bash
53
- myclaw new <agent名称>
99
+ myclaw patch # 注入
100
+ myclaw unpatch # 还原
54
101
  ```
55
- 快速创建一个新的 OpenClaw Agent,自动完成:
56
- - 创建 workspace 目录
57
- - 配置 agent 文件
58
- - 发送出生消息
59
102
 
60
- 示例:
61
- ```bash
62
- myclaw new helper # 创建名为 helper 的 Agent
63
- myclaw new testbot # 创建名为 testbot 的 Agent
103
+ > 注意:每次 OpenClaw 更新后需要重新 patch(index.html 会被覆盖)。
104
+
105
+ ---
106
+
107
+ ### `myclaw open` — 打开浏览器
108
+
109
+ 自动检测 Chrome 路径,拼接 Token 打开:
110
+
111
+ ```
112
+ http://127.0.0.1:18789?token=aiyiran
64
113
  ```
65
114
 
66
- ### 安装 OpenClaw
67
- ```bash
68
- myclaw install
115
+ 支持的 Chrome 路径:
116
+ - **Mac:** `/Applications/Google Chrome.app`
117
+ - **Windows:** `C:\Program Files\Google\Chrome\Application\chrome.exe`
118
+ - **Linux:** `google-chrome` / `chromium-browser`
119
+
120
+ ---
121
+
122
+ ### `myclaw wsl2` — WSL2 安装向导
123
+
124
+ Windows 专用,分两阶段:
125
+
126
+ | 阶段 | 内容 |
127
+ |------|------|
128
+ | Phase 1 | 启用 WSL 功能 + 安装 WSL2(需要重启) |
129
+ | Phase 2 | 下载并导入 OpenClaw rootfs.tar |
130
+
131
+ 已安装时会提示:
132
+ ```
133
+ 是否要重新安装 Linux 环境? (y/N):
69
134
  ```
70
- 自动检测操作系统并执行对应的安装命令。
71
135
 
72
- ### 帮助
73
- ```bash
74
- myclaw help
136
+ ---
137
+
138
+ ## 配置文件
139
+
140
+ ### `config.js`
141
+
142
+ ```js
143
+ module.exports = {
144
+ TOKEN: 'aiyiran', // Gateway 认证 Token
145
+ DEFAULT_URL: 'http://127.0.0.1:18789', // 默认地址
146
+ AUTO_PATCH: true, // prepare 时是否自动 patch
147
+ };
75
148
  ```
76
149
 
150
+ | 配置项 | 说明 |
151
+ |--------|------|
152
+ | `TOKEN` | 所有 open 命令和 bat 启动器使用的认证令牌 |
153
+ | `DEFAULT_URL` | Gateway 地址 |
154
+ | `AUTO_PATCH` | `true` = prepare/postinstall 自动 patch;`false` = 跳过 |
155
+
156
+ ---
157
+
77
158
  ## 文件结构
78
159
 
79
160
  ```
80
161
  myclaw/
81
- ├── index.js # 主入口,命令解析和输出
82
- ├── create_agent.js # Agent 创建逻辑模块
83
- └── README.md # 本文件
162
+ ├── index.js # CLI 主入口 + 命令路由 + bat 模板
163
+ ├── config.js # 全局配置(Token、URL、开关)
164
+ ├── prepare.js # 初始化链条
165
+ ├── patch.js # UI 扩展注入逻辑
166
+ ├── wsl2.js # WSL2 安装向导
167
+ ├── create_agent.js # Agent 创建
168
+ ├── package.json # npm 包配置(含 postinstall)
169
+ ├── publish.sh # 一键发布脚本
170
+ ├── assets/
171
+ │ ├── myclaw-inject.js # 注入到 control-ui 的 JS
172
+ │ └── detect-browser.sh # Chrome 检测脚本
173
+ ├── voice-input/
174
+ │ ├── index.html # 语音输入独立页
175
+ │ └── voice-input.js # 语音 SDK
176
+ └── wizards/ # 交互式向导系统
177
+ ├── index.js # 向导入口
178
+ ├── runner/ # 向导运行引擎
179
+ ├── configs/ # 向导配置文件
180
+ ├── scripts/ # Python 后端脚本
181
+ └── commons/ # 共享步骤定义
84
182
  ```
85
183
 
86
- ### 模块说明
184
+ ---
87
185
 
88
- | 文件 | 职责 |
89
- |------|------|
90
- | `index.js` | 主入口,解析命令、颜色输出、调用模块 |
91
- | `create_agent.js` | Agent 创建的完整逻辑,可独立使用 |
186
+ ## 调试
187
+
188
+ ### 查看 prepare 执行日志
92
189
 
93
- ## 开发说明
190
+ prepare 运行时会写入日志文件:
191
+ - **Mac/Linux:** `/tmp/myclaw-prepare.log`
192
+ - **Windows WSL:** `/tmp/myclaw-prepare.log`
193
+
194
+ ```bash
195
+ cat /tmp/myclaw-prepare.log
196
+ ```
94
197
 
95
- ### 代码规范
198
+ 示例输出:
199
+ ```
200
+ [2026-04-01T00:30:00.000Z] === prepare start (postinstall=true, version=1.0.46)
201
+ [2026-04-01T00:30:00.100Z] Step 1: env=linux
202
+ [2026-04-01T00:30:00.200Z] Step 2: chrome=true
203
+ [2026-04-01T00:30:00.300Z] Step 3: openclaw=installed
204
+ [2026-04-01T00:30:00.400Z] Step 4: AUTO_PATCH=true, env=linux
205
+ [2026-04-01T00:30:01.000Z] Step 4: patch executed
206
+ [2026-04-01T00:30:01.100Z] === prepare end (success)
207
+ ```
96
208
 
97
- 1. **跨平台兼容性** - 必须考虑 Windows 用户体验
98
- - 使用 `os.platform()` 检测系统
99
- - Windows 下禁用 ANSI 颜色输出
100
- - 避免使用只在 Unix 系统有效的命令
209
+ ### npm 缓存问题
101
210
 
102
- 2. **错误处理**
103
- - 所有 `execSync` 调用必须使用 `try-catch`
104
- - 失败时提供清晰的错误信息和解决方案
211
+ 如果 `npm install -g @aiyiran/myclaw` 拿到旧版本:
105
212
 
106
- 3. **模块化**
107
- - 业务逻辑放入独立模块
108
- - 主入口只做命令解析和输出
213
+ ```bash
214
+ # 方案 1: 强制最新
215
+ npm install -g @aiyiran/myclaw@latest --prefer-online
109
216
 
110
- ### 测试清单
217
+ # 方案 2: 清缓存
218
+ npm cache clean --force
219
+ npm install -g @aiyiran/myclaw
111
220
 
112
- 发布前请在以下环境测试:
113
- - [ ] macOS (Terminal)
114
- - [ ] Linux (bash)
115
- - [ ] Windows 10/11 (PowerShell)
116
- - [ ] Windows 10/11 (CMD)
117
- - [ ] Windows Terminal (如果可用)
221
+ # 方案 3: 先 view 刷新元数据
222
+ npm view @aiyiran/myclaw version
223
+ npm install -g @aiyiran/myclaw
224
+ ```
118
225
 
119
- ## 依赖
226
+ ---
120
227
 
121
- - Node.js 14+
122
- - OpenClaw CLI (用于实际命令执行)
228
+ ## 发布
123
229
 
124
- ## 许可证
230
+ ```bash
231
+ cd myclaw
232
+ sh publish.sh
233
+ ```
125
234
 
126
- 内部教学工具
235
+ 自动完成:git commit → 版本号 +1 → git push + tag → npm publish
package/index.js CHANGED
@@ -404,7 +404,7 @@ pause
404
404
  // 写入 bat 文件(Windows CMD 需要 CRLF 换行符)
405
405
  fs.writeFileSync(batPath, batContent.replace(/\n/g, '\r\n'), 'utf8');
406
406
 
407
- // 用 PowerShell 创建带图标的桌面快捷方式
407
+ // 用 PowerShell 创建带图标的桌面快捷方式 + 刷新桌面
408
408
  const psScript = `
409
409
  $ws = New-Object -ComObject WScript.Shell
410
410
  $sc = $ws.CreateShortcut('${lnkPath.replace(/\\/g, '\\\\')}')
@@ -412,8 +412,10 @@ $sc.TargetPath = '${batPath.replace(/\\/g, '\\\\')}'
412
412
  $sc.WorkingDirectory = '${myClawDir.replace(/\\/g, '\\\\')}'
413
413
  $sc.WindowStyle = 1
414
414
  $sc.IconLocation = '%SystemRoot%\\System32\\shell32.dll,176'
415
- $sc.Description = 'OpenClaw 智能启动器'
415
+ $sc.Description = 'OpenClaw'
416
416
  $sc.Save()
417
+ Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public class Shell { [DllImport("shell32.dll")] public static extern void SHChangeNotify(int e, int f, IntPtr i1, IntPtr i2); }' -ErrorAction SilentlyContinue
418
+ [Shell]::SHChangeNotify(0x08000000, 0, [IntPtr]::Zero, [IntPtr]::Zero)
417
419
  `;
418
420
 
419
421
  try {
@@ -660,6 +662,45 @@ function runRestart() {
660
662
  console.log('');
661
663
  }
662
664
 
665
+ // ============================================================================
666
+ // 强制更新命令
667
+ // ============================================================================
668
+
669
+ function runUpdate() {
670
+ const bar = '----------------------------------------';
671
+ console.log('');
672
+ console.log('[' + colors.blue + 'MyClaw' + colors.nc + '] ' + colors.blue + '强制升级 MyClaw' + colors.nc);
673
+ console.log(bar);
674
+ console.log('');
675
+ console.log('正在执行全量强制升级 (绕过缓存)...');
676
+ console.log('');
677
+
678
+ try {
679
+ const { execSync } = require('child_process');
680
+ // 第一步:清空缓存,防患于未然
681
+ console.log('> ' + colors.yellow + 'npm cache clean --force' + colors.nc);
682
+ execSync('npm cache clean --force', { stdio: 'inherit' });
683
+ console.log('');
684
+
685
+ // 第二步:强制拉最新版本
686
+ console.log('> ' + colors.yellow + 'npm install -g @aiyiran/myclaw@latest --prefer-online' + colors.nc);
687
+ execSync('npm install -g @aiyiran/myclaw@latest --prefer-online', { stdio: 'inherit' });
688
+
689
+ console.log('');
690
+ console.log('[' + colors.green + '成功' + colors.nc + '] MyClaw 升级完成!');
691
+
692
+ if (detectPlatform() === 'wsl' || detectPlatform() === 'linux' || detectPlatform() === 'mac') {
693
+ console.log('');
694
+ console.log('如果需要同时升级 OpenClaw 核心,请运行:');
695
+ console.log(' ' + colors.yellow + 'myclaw install' + colors.nc);
696
+ }
697
+ } catch (err) {
698
+ console.log('');
699
+ console.log('[' + colors.red + '错误' + colors.nc + '] 升级失败: ' + err.message);
700
+ }
701
+ console.log('');
702
+ }
703
+
663
704
  // ============================================================================
664
705
  // 帮助信息
665
706
  // ============================================================================
@@ -681,6 +722,7 @@ function showHelp() {
681
722
  console.log(' install 安装 OpenClaw 服务');
682
723
  console.log(' status 简化版状态查看(学生友好)');
683
724
  console.log(' new 创建新的 Agent(学生练习用)');
725
+ console.log(' update 强制升级 MyClaw 到最新版本 (别名: up)');
684
726
  console.log(' open 打开浏览器控制台(自动带 token)');
685
727
  console.log(' wsl2 WSL2 一键安装/修复 (仅限 Windows)');
686
728
  console.log(' bat 在桌面生成一键启动脚本 (仅限 Windows)');
@@ -725,6 +767,8 @@ if (!command || command === 'help' || command === '--help' || command === '-h')
725
767
  runStatus();
726
768
  } else if (command === 'new') {
727
769
  runNew();
770
+ } else if (command === 'update' || command === 'up') {
771
+ runUpdate();
728
772
  } else if (command === 'open') {
729
773
  runOpen();
730
774
  } else if (command === 'wsl2') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {