@aiyiran/myclaw 1.0.46 → 1.0.48

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 +193 -85
  2. package/index.js +23 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,126 +1,234 @@
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 patch` | 注入 UI 扩展(语音输入等) | Mac/Linux |
18
+ | `myclaw unpatch` | 移除 UI 扩展 | Mac/Linux |
19
+ | `myclaw install` | 安装 OpenClaw | 全平台 |
20
+ | `myclaw status` | 查看 Gateway / Agent 状态 | 全平台 |
21
+ | `myclaw new <name>` | 创建新 Agent | 全平台 |
22
+ | `myclaw restart` | 重启 Gateway | 全平台 |
23
+ | `myclaw bat` | 生成 Windows 桌面快捷启动器 | Windows |
24
+ | `myclaw wsl2` | WSL2 安装向导 | Windows |
25
+ | `myclaw weixin` | 微信绑定向导 | 全平台 |
26
+ | `myclaw rebind` | 微信重绑向导 | 全平台 |
27
+ | `myclaw help` | 显示帮助 | 全平台 |
28
+
29
+ ---
30
+
31
+ ## 核心流程
32
+
33
+ ### `myclaw prepare` — 初始化链条
34
+
35
+ 自动检测环境并按需执行安装、配置、注入:
6
36
 
7
37
  ```
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
- ╚══════════════════════════════════════════════════════════════════════╝
38
+ Step 1: 检测环境 (Mac / Windows / Linux / WSL)
39
+ Step 2: 检测 Chrome 浏览器
40
+ Step 3: 检测 OpenClaw → 未装则安装
41
+ Step 4: 执行 Patch(受 AUTO_PATCH 开关控制)
42
+ Step 5: [Windows] 生成桌面快捷启动器
27
43
  ```
28
44
 
29
- ## 安装
45
+ **触发方式:**
46
+ - 手动运行 `myclaw prepare`
47
+ - `npm install -g @aiyiran/myclaw` 时通过 `postinstall` 自动触发
30
48
 
31
- ```bash
32
- # 方式一: 直接运行
33
- node myclaw/index.js <command>
49
+ **postinstall 模式(无交互):**
50
+ - OpenClaw 已装 → 自动 patch
51
+ - OpenClaw 未装 → 跳过,提示手动安装
52
+ - 不会弹出 y/n 询问
34
53
 
35
- # 方式二: 添加到 PATH (macOS/Linux)
36
- ln -s /path/to/myclaw/index.js /usr/local/bin/myclaw
37
- chmod +x /usr/local/bin/myclaw
54
+ ---
38
55
 
39
- # 方式三: Windows PowerShell
40
- # 将 myclaw/index.js 路径添加到系统 PATH
56
+ ### `myclaw bat` — Windows 桌面启动器
57
+
58
+ 生成一个 `.bat` 启动脚本 + 桌面快捷方式,双击即可智能启动。
59
+
60
+ **快捷方式命名规则:**
61
+ ```
62
+ 版本号_OpenClaw_MM-DD_HH-MM-SS.lnk
63
+ 例: 1.0.46_OpenClaw_04-01_00-36-19.lnk
41
64
  ```
42
65
 
43
- ## 使用方法
66
+ > 通过桌面图标名称可验证 prepare 是否执行过,以及执行的版本和时间。
67
+
68
+ **双击后的完整流程:**
44
69
 
45
- ### 查看状态
46
- ```bash
47
- myclaw status
48
70
  ```
49
- 简化版的 OpenClaw 状态面板,一眼看清 Gateway、Agents、Sessions 状态。
71
+ Gateway 未运行:
72
+ [1/5] WSL → 检测/安装 WSL2
73
+ [2/5] OpenClaw Linux → 检测/导入 WSL 发行版
74
+ [3/5] Gateway → 未运行 → 更新 myclaw
75
+ [4/5] Patch → 注入 UI 扩展
76
+ [5/5] Browser → myclaw open(带 Token)
77
+ → 启动 openclaw gateway(保持窗口)
78
+
79
+ Gateway 已运行:
80
+ [1/4] WSL
81
+ [2/4] OpenClaw Linux
82
+ [3/4] Gateway → 已运行
83
+ [4/4] Browser → myclaw open(带 Token)
84
+ → 进入 WSL 终端(cd /root/.openclaw)
85
+ ```
86
+
87
+ ---
88
+
89
+ ### `myclaw patch` — UI 扩展注入
90
+
91
+ 向 OpenClaw 的 control-ui 注入自定义功能:
92
+ - `myclaw-inject.js` — 自定义 UI 逻辑
93
+ - `voice-input.js` — 语音输入 SDK
94
+
95
+ **原理:** 修改 `control-ui/index.html`,在 `</body>` 前插入 `<script>` 标签。
50
96
 
51
- ### 创建新 Agent
52
97
  ```bash
53
- myclaw new <agent名称>
98
+ myclaw patch # 注入
99
+ myclaw unpatch # 还原
54
100
  ```
55
- 快速创建一个新的 OpenClaw Agent,自动完成:
56
- - 创建 workspace 目录
57
- - 配置 agent 文件
58
- - 发送出生消息
59
101
 
60
- 示例:
61
- ```bash
62
- myclaw new helper # 创建名为 helper 的 Agent
63
- myclaw new testbot # 创建名为 testbot 的 Agent
102
+ > 注意:每次 OpenClaw 更新后需要重新 patch(index.html 会被覆盖)。
103
+
104
+ ---
105
+
106
+ ### `myclaw open` — 打开浏览器
107
+
108
+ 自动检测 Chrome 路径,拼接 Token 打开:
109
+
110
+ ```
111
+ http://127.0.0.1:18789?token=aiyiran
64
112
  ```
65
113
 
66
- ### 安装 OpenClaw
67
- ```bash
68
- myclaw install
114
+ 支持的 Chrome 路径:
115
+ - **Mac:** `/Applications/Google Chrome.app`
116
+ - **Windows:** `C:\Program Files\Google\Chrome\Application\chrome.exe`
117
+ - **Linux:** `google-chrome` / `chromium-browser`
118
+
119
+ ---
120
+
121
+ ### `myclaw wsl2` — WSL2 安装向导
122
+
123
+ Windows 专用,分两阶段:
124
+
125
+ | 阶段 | 内容 |
126
+ |------|------|
127
+ | Phase 1 | 启用 WSL 功能 + 安装 WSL2(需要重启) |
128
+ | Phase 2 | 下载并导入 OpenClaw rootfs.tar |
129
+
130
+ 已安装时会提示:
131
+ ```
132
+ 是否要重新安装 Linux 环境? (y/N):
69
133
  ```
70
- 自动检测操作系统并执行对应的安装命令。
71
134
 
72
- ### 帮助
73
- ```bash
74
- myclaw help
135
+ ---
136
+
137
+ ## 配置文件
138
+
139
+ ### `config.js`
140
+
141
+ ```js
142
+ module.exports = {
143
+ TOKEN: 'aiyiran', // Gateway 认证 Token
144
+ DEFAULT_URL: 'http://127.0.0.1:18789', // 默认地址
145
+ AUTO_PATCH: true, // prepare 时是否自动 patch
146
+ };
75
147
  ```
76
148
 
149
+ | 配置项 | 说明 |
150
+ |--------|------|
151
+ | `TOKEN` | 所有 open 命令和 bat 启动器使用的认证令牌 |
152
+ | `DEFAULT_URL` | Gateway 地址 |
153
+ | `AUTO_PATCH` | `true` = prepare/postinstall 自动 patch;`false` = 跳过 |
154
+
155
+ ---
156
+
77
157
  ## 文件结构
78
158
 
79
159
  ```
80
160
  myclaw/
81
- ├── index.js # 主入口,命令解析和输出
82
- ├── create_agent.js # Agent 创建逻辑模块
83
- └── README.md # 本文件
161
+ ├── index.js # CLI 主入口 + 命令路由 + bat 模板
162
+ ├── config.js # 全局配置(Token、URL、开关)
163
+ ├── prepare.js # 初始化链条
164
+ ├── patch.js # UI 扩展注入逻辑
165
+ ├── wsl2.js # WSL2 安装向导
166
+ ├── create_agent.js # Agent 创建
167
+ ├── package.json # npm 包配置(含 postinstall)
168
+ ├── publish.sh # 一键发布脚本
169
+ ├── assets/
170
+ │ ├── myclaw-inject.js # 注入到 control-ui 的 JS
171
+ │ └── detect-browser.sh # Chrome 检测脚本
172
+ ├── voice-input/
173
+ │ ├── index.html # 语音输入独立页
174
+ │ └── voice-input.js # 语音 SDK
175
+ └── wizards/ # 交互式向导系统
176
+ ├── index.js # 向导入口
177
+ ├── runner/ # 向导运行引擎
178
+ ├── configs/ # 向导配置文件
179
+ ├── scripts/ # Python 后端脚本
180
+ └── commons/ # 共享步骤定义
84
181
  ```
85
182
 
86
- ### 模块说明
183
+ ---
87
184
 
88
- | 文件 | 职责 |
89
- |------|------|
90
- | `index.js` | 主入口,解析命令、颜色输出、调用模块 |
91
- | `create_agent.js` | Agent 创建的完整逻辑,可独立使用 |
185
+ ## 调试
186
+
187
+ ### 查看 prepare 执行日志
92
188
 
93
- ## 开发说明
189
+ prepare 运行时会写入日志文件:
190
+ - **Mac/Linux:** `/tmp/myclaw-prepare.log`
191
+ - **Windows WSL:** `/tmp/myclaw-prepare.log`
192
+
193
+ ```bash
194
+ cat /tmp/myclaw-prepare.log
195
+ ```
94
196
 
95
- ### 代码规范
197
+ 示例输出:
198
+ ```
199
+ [2026-04-01T00:30:00.000Z] === prepare start (postinstall=true, version=1.0.46)
200
+ [2026-04-01T00:30:00.100Z] Step 1: env=linux
201
+ [2026-04-01T00:30:00.200Z] Step 2: chrome=true
202
+ [2026-04-01T00:30:00.300Z] Step 3: openclaw=installed
203
+ [2026-04-01T00:30:00.400Z] Step 4: AUTO_PATCH=true, env=linux
204
+ [2026-04-01T00:30:01.000Z] Step 4: patch executed
205
+ [2026-04-01T00:30:01.100Z] === prepare end (success)
206
+ ```
96
207
 
97
- 1. **跨平台兼容性** - 必须考虑 Windows 用户体验
98
- - 使用 `os.platform()` 检测系统
99
- - Windows 下禁用 ANSI 颜色输出
100
- - 避免使用只在 Unix 系统有效的命令
208
+ ### npm 缓存问题
101
209
 
102
- 2. **错误处理**
103
- - 所有 `execSync` 调用必须使用 `try-catch`
104
- - 失败时提供清晰的错误信息和解决方案
210
+ 如果 `npm install -g @aiyiran/myclaw` 拿到旧版本:
105
211
 
106
- 3. **模块化**
107
- - 业务逻辑放入独立模块
108
- - 主入口只做命令解析和输出
212
+ ```bash
213
+ # 方案 1: 强制最新
214
+ npm install -g @aiyiran/myclaw@latest --prefer-online
109
215
 
110
- ### 测试清单
216
+ # 方案 2: 清缓存
217
+ npm cache clean --force
218
+ npm install -g @aiyiran/myclaw
111
219
 
112
- 发布前请在以下环境测试:
113
- - [ ] macOS (Terminal)
114
- - [ ] Linux (bash)
115
- - [ ] Windows 10/11 (PowerShell)
116
- - [ ] Windows 10/11 (CMD)
117
- - [ ] Windows Terminal (如果可用)
220
+ # 方案 3: 先 view 刷新元数据
221
+ npm view @aiyiran/myclaw version
222
+ npm install -g @aiyiran/myclaw
223
+ ```
118
224
 
119
- ## 依赖
225
+ ---
120
226
 
121
- - Node.js 14+
122
- - OpenClaw CLI (用于实际命令执行)
227
+ ## 发布
123
228
 
124
- ## 许可证
229
+ ```bash
230
+ cd myclaw
231
+ sh publish.sh
232
+ ```
125
233
 
126
- 内部教学工具
234
+ 自动完成:git commit → 版本号 +1 → git push + tag → npm publish
package/index.js CHANGED
@@ -290,7 +290,25 @@ function runBat() {
290
290
 
291
291
  const batPath = path.join(myClawDir, 'openclaw-launcher.bat');
292
292
  const desktopPath = path.join(os.homedir(), 'Desktop');
293
- const lnkPath = path.join(desktopPath, 'OpenClaw.lnk');
293
+
294
+ // 生成时间戳
295
+ const now = new Date();
296
+ const mm = String(now.getMonth() + 1).padStart(2, '0');
297
+ const dd = String(now.getDate()).padStart(2, '0');
298
+ const hh = String(now.getHours()).padStart(2, '0');
299
+ const mi = String(now.getMinutes()).padStart(2, '0');
300
+ const ss = String(now.getSeconds()).padStart(2, '0');
301
+ const ver = require('./package.json').version;
302
+
303
+ // 删除旧的 OpenClaw*.lnk
304
+ try {
305
+ const oldLinks = fs.readdirSync(desktopPath).filter(f => f.endsWith('.lnk') && (f.includes('OpenClaw') || f.match(/^\d+\.\d+\.\d+_OpenClaw/)));
306
+ for (const old of oldLinks) {
307
+ try { fs.unlinkSync(path.join(desktopPath, old)); } catch {}
308
+ }
309
+ } catch {}
310
+
311
+ const lnkPath = path.join(desktopPath, ver + '_OpenClaw_' + mm + '-' + dd + '_' + hh + '-' + mi + '-' + ss + '.lnk');
294
312
 
295
313
  // === 智能启动器 bat 内容(用 goto 标签避免中文在 if 块内的编码问题) ===
296
314
  const batContent = `@echo off
@@ -386,7 +404,7 @@ pause
386
404
  // 写入 bat 文件(Windows CMD 需要 CRLF 换行符)
387
405
  fs.writeFileSync(batPath, batContent.replace(/\n/g, '\r\n'), 'utf8');
388
406
 
389
- // 用 PowerShell 创建带图标的桌面快捷方式
407
+ // 用 PowerShell 创建带图标的桌面快捷方式 + 刷新桌面
390
408
  const psScript = `
391
409
  $ws = New-Object -ComObject WScript.Shell
392
410
  $sc = $ws.CreateShortcut('${lnkPath.replace(/\\/g, '\\\\')}')
@@ -394,8 +412,10 @@ $sc.TargetPath = '${batPath.replace(/\\/g, '\\\\')}'
394
412
  $sc.WorkingDirectory = '${myClawDir.replace(/\\/g, '\\\\')}'
395
413
  $sc.WindowStyle = 1
396
414
  $sc.IconLocation = '%SystemRoot%\\System32\\shell32.dll,176'
397
- $sc.Description = 'OpenClaw 智能启动器'
415
+ $sc.Description = 'OpenClaw'
398
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)
399
419
  `;
400
420
 
401
421
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {