@aiyiran/myclaw 1.1.193 → 1.1.195

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.
@@ -249,8 +249,7 @@
249
249
  // 展示间跳转(发布按钮左边)
250
250
  var showcaseLink = document.createElement('a');
251
251
  var _scClaw = lastKnownClawName || '';
252
- var _scWs = getWorkspaceId();
253
- showcaseLink.href = 'https://www.yiranlaoshi.com/showcase?claw=' + _scClaw + '&workspace=' + _scWs + '&clawName=' + _scClaw;
252
+ showcaseLink.href = 'https://www.yiranlaoshi.com/studio?claw=' + _scClaw + '&my=' + _scClaw;
254
253
  showcaseLink.target = '_blank';
255
254
  showcaseLink.textContent = '我的项目';
256
255
  showcaseLink.style.cssText = 'cursor:pointer;padding:2px 10px;border-radius:3px;font-size:12px;background:rgba(255,255,255,0.08);transition:background 0.15s;color:#cdd6f4;text-decoration:none;';
package/delete_agents.js CHANGED
@@ -27,7 +27,9 @@ const { spawnSync, execSync } = require('child_process');
27
27
  // ─────────────────────────────────────────────
28
28
 
29
29
  function getOpenclawDir() {
30
- if (process.platform === 'win32' || fs.existsSync('/root/.openclaw')) {
30
+ // Windows 上 '/' 会被解释成当前盘符根目录(如 E:\root\.openclaw),
31
+ // 不是真正的文件系统根,因此 /root/.openclaw 判断只在非 Windows 上有意义。
32
+ if (process.platform !== 'win32' && fs.existsSync('/root/.openclaw')) {
31
33
  return '/root/.openclaw';
32
34
  }
33
35
  return path.join(os.homedir(), '.openclaw');
package/fix-longxia.js ADDED
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * ============================================================================
5
+ * 修复小龙虾 - 注入 ES2023 Array Polyfill
6
+ * ============================================================================
7
+ *
8
+ * 功能:
9
+ * 1. 自动探测 OpenClaw 的 control-ui/index.html
10
+ * 2. 备份原文件为 index.html.bak2
11
+ * 3. 在 <head> 标签内注入 ES2023 Array polyfill
12
+ * (toSorted / toReversed / toSpliced / with)
13
+ * 4. 幂等:已注入时跳过,不会重复注入
14
+ *
15
+ * 使用:
16
+ * myclaw fix-longxia
17
+ * mc fix-longxia
18
+ * ============================================================================
19
+ */
20
+
21
+ const fs = require('fs');
22
+ const path = require('path');
23
+
24
+ const POLYFILL_MARKER = '<!-- myclaw-polyfill -->';
25
+
26
+ const POLYFILL_SCRIPT = `${POLYFILL_MARKER}
27
+ <script>
28
+ // Polyfill for Array.prototype.toSorted (ES2023)
29
+ if (!Array.prototype.toSorted) {
30
+ Array.prototype.toSorted = function(compareFn) {
31
+ // 复制数组并排序(不修改原数组)
32
+ return this.slice().sort(compareFn);
33
+ };
34
+ }
35
+ // Polyfill for Array.prototype.toReversed (ES2023)
36
+ if (!Array.prototype.toReversed) {
37
+ Array.prototype.toReversed = function() {
38
+ return this.slice().reverse();
39
+ };
40
+ }
41
+ // Polyfill for Array.prototype.toSpliced (ES2023)
42
+ if (!Array.prototype.toSpliced) {
43
+ Array.prototype.toSpliced = function(start, deleteCount, ...items) {
44
+ var copy = this.slice();
45
+ copy.splice(start, deleteCount, ...items);
46
+ return copy;
47
+ };
48
+ }
49
+ // Polyfill for Array.prototype.with (ES2023)
50
+ if (!Array.prototype.with) {
51
+ Array.prototype.with = function(index, value) {
52
+ var copy = this.slice();
53
+ copy[index] = value;
54
+ return copy;
55
+ };
56
+ }
57
+ </script>`;
58
+
59
+ function run() {
60
+ const { findControlUiDir } = require('./patches/patch');
61
+
62
+ const bar = '────────────────────────────────────────';
63
+ console.log('');
64
+ console.log(bar);
65
+ console.log(' 🦞 修复小龙虾 — 注入 ES2023 Array Polyfill');
66
+ console.log(bar);
67
+ console.log('');
68
+
69
+ // 1. 探测 control-ui 目录
70
+ console.log('[1/3] 🔍 探测 OpenClaw control-ui 目录...');
71
+ const uiDir = findControlUiDir();
72
+ if (!uiDir) {
73
+ console.log(' ❌ 未找到 OpenClaw control-ui 目录');
74
+ console.log(' 提示: 确保 openclaw 已全局安装 (npm install -g openclaw)');
75
+ process.exit(1);
76
+ }
77
+
78
+ const indexPath = path.join(uiDir, 'index.html');
79
+ console.log(' ✅ 找到: ' + indexPath);
80
+ console.log('');
81
+
82
+ // 2. 备份
83
+ console.log('[2/3] 💾 备份原文件...');
84
+ const backupPath = indexPath + '.bak2';
85
+ try {
86
+ fs.copyFileSync(indexPath, backupPath);
87
+ console.log(' ✅ 备份完成: ' + backupPath);
88
+ } catch (err) {
89
+ console.log(' ❌ 备份失败: ' + err.message);
90
+ process.exit(1);
91
+ }
92
+ console.log('');
93
+
94
+ // 3. 注入 polyfill
95
+ console.log('[3/3] 💉 注入 ES2023 Polyfill...');
96
+ try {
97
+ let html = fs.readFileSync(indexPath, 'utf8');
98
+
99
+ // 幂等检查
100
+ if (html.includes(POLYFILL_MARKER)) {
101
+ console.log(' ⚠️ 已经注入过,跳过(幂等)');
102
+ console.log('');
103
+ console.log('🦞 修复小龙虾完成(无需操作)');
104
+ return;
105
+ }
106
+
107
+ // 在 <head> 之后插入
108
+ if (!html.includes('<head>') && !html.includes('<HEAD>')) {
109
+ console.log(' ❌ 未找到 <head> 标签');
110
+ process.exit(1);
111
+ }
112
+
113
+ html = html.replace(/<head>/i, '<head>\n' + POLYFILL_SCRIPT);
114
+
115
+ fs.writeFileSync(indexPath, html, 'utf8');
116
+ console.log(' ✅ Polyfill 注入成功!');
117
+ } catch (err) {
118
+ console.log(' ❌ 注入失败: ' + err.message);
119
+ console.log(' 正在从备份恢复...');
120
+ try {
121
+ fs.copyFileSync(backupPath, indexPath);
122
+ console.log(' ✅ 已恢复');
123
+ } catch (e2) {
124
+ console.log(' ❌ 恢复也失败: ' + e2.message);
125
+ }
126
+ process.exit(1);
127
+ }
128
+
129
+ console.log('');
130
+ console.log('🦞 修复小龙虾完成!');
131
+ }
132
+
133
+ module.exports = { run };
package/gateway.js CHANGED
@@ -16,6 +16,13 @@ const { execSync } = require('child_process');
16
16
  const PORT = 18789;
17
17
  const isWin = process.platform === 'win32';
18
18
 
19
+ // 跨平台同步等待:用 Atomics.wait 阻塞当前线程,不 spawn 子进程、不碰 shell。
20
+ // 早期用 `timeout /t N /nobreak >nul`,但 Windows 的 timeout.exe 要求 stdin 是真正的
21
+ // 控制台句柄,被 Node 的 execSync 调用(stdin 非控制台)时必定报错退出,反而会误伤调用方。
22
+ function sleepSync(seconds) {
23
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.round(seconds * 1000));
24
+ }
25
+
19
26
  // ANSI 颜色
20
27
  const colors = {
21
28
  green: '\x1b[32m',
@@ -38,7 +45,7 @@ function stop() {
38
45
  }
39
46
 
40
47
  // 等 2 秒让优雅关闭执行
41
- execSync(isWin ? 'timeout /t 2 /nobreak >nul' : 'sleep 2', { stdio: 'ignore' });
48
+ sleepSync(2);
42
49
 
43
50
  // Step 2: 检查残留进程并强杀
44
51
  console.log('[停止] Step 2 — 清理残留进程...');
@@ -101,6 +108,9 @@ function stop() {
101
108
  let portFree = false;
102
109
 
103
110
  for (let i = 0; i < MAX_WAIT; i++) {
111
+ // 端口探测:命令成功(exit 0)=端口仍被监听;命令抛错(非零/无匹配)=端口已释放。
112
+ // 注意:sleep 必须放在 try/catch 之外,否则等待命令一旦失败会被误判成“端口已释放”。
113
+ let stillListening = false;
104
114
  try {
105
115
  if (isWin) {
106
116
  execSync('netstat -ano | findstr :' + PORT + ' | findstr LISTENING', {
@@ -109,12 +119,18 @@ function stop() {
109
119
  } else {
110
120
  execSync('lsof -i :' + PORT + ' -t 2>/dev/null', { stdio: 'pipe', timeout: 2000 });
111
121
  }
112
- process.stdout.write('[等待] 端口 ' + PORT + ' 释放中... (' + (i + 1) + '/' + MAX_WAIT + 's)\r');
113
- execSync(isWin ? 'timeout /t 1 /nobreak >nul' : 'sleep 1', { stdio: 'ignore' });
122
+ stillListening = true;
114
123
  } catch {
124
+ // 未查到监听 = 端口已释放
125
+ }
126
+
127
+ if (!stillListening) {
115
128
  portFree = true;
116
129
  break;
117
130
  }
131
+
132
+ process.stdout.write('[等待] 端口 ' + PORT + ' 释放中... (' + (i + 1) + '/' + MAX_WAIT + 's)\r');
133
+ sleepSync(1);
118
134
  }
119
135
 
120
136
  if (portFree) {
@@ -143,7 +159,7 @@ function start() {
143
159
  }
144
160
 
145
161
  // 等待启动完成
146
- execSync(isWin ? 'timeout /t 3 /nobreak >nul' : 'sleep 3', { stdio: 'ignore' });
162
+ sleepSync(3);
147
163
 
148
164
  // 注册 LaunchAgent(仅 macOS,Docker/Linux 无 systemd 跳过)
149
165
  if (process.platform === 'darwin') {
package/index.js CHANGED
@@ -462,6 +462,11 @@ function runFix() {
462
462
  fix.run();
463
463
  }
464
464
 
465
+ function runFixLongxia() {
466
+ const fixLongxia = require('./fix-longxia');
467
+ fixLongxia.run();
468
+ }
469
+
465
470
  // ============================================================================
466
471
  // WSL2 安装 (独立模块)
467
472
  // ============================================================================
@@ -1424,8 +1429,8 @@ function runUpdate() {
1424
1429
  if (attempt < maxRetries) {
1425
1430
  console.log('');
1426
1431
  console.log('[' + colors.yellow + '重试' + colors.nc + '] 8 秒后重试 (' + attempt + '/' + maxRetries + ')...');
1427
- const waitCmd = require('os').platform() === 'win32' ? 'timeout /t 8 >nul' : 'sleep 8';
1428
- try { execSync(waitCmd, { stdio: 'ignore' }); } catch { }
1432
+ // Atomics.wait 同步阻塞 8 秒,跨平台且不依赖 timeout.exe(后者被 execSync 调用时会立即报错)
1433
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 8000);
1429
1434
  } else {
1430
1435
  console.log('');
1431
1436
  console.log('[' + colors.red + '错误' + colors.nc + '] 升级失败: ' + err.message);
@@ -2589,6 +2594,7 @@ function showHelp() {
2589
2594
  console.log(' list-agents 列出所有 Agent(--json 输出机器可读)');
2590
2595
  console.log(' trash-paths <p1> <p2> 将路径移入回收站(跨平台)');
2591
2596
  console.log(' fix 兜底修复(自动补装 WSL + Chrome,仅限 Windows)');
2597
+ console.log(' fix-longxia 🦞 修复小龙虾(注入 ES2023 Array Polyfill 到首页)');
2592
2598
  console.log(' wsl2 WSL2 一键安装/修复 (仅限 Windows, 可选: --cli, --remote)');
2593
2599
  console.log(' safe 开启虚拟机屏蔽 (禁止自动挂载 Windows 盘符)');
2594
2600
  console.log(' bat 在桌面生成一键启动脚本 (仅限 Windows)');
@@ -2713,6 +2719,8 @@ if (!command) {
2713
2719
  runTrashPaths();
2714
2720
  } else if (command === 'fix') {
2715
2721
  runFix();
2722
+ } else if (command === 'fix-longxia' || command === '修复小龙虾') {
2723
+ runFixLongxia();
2716
2724
  } else if (command === 'wsl2') {
2717
2725
  runWsl2();
2718
2726
  } else if (command === 'safe') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.1.193",
3
+ "version": "1.1.195",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/patches/patch.js CHANGED
@@ -38,6 +38,14 @@ const BACKUP_SUFFIX = '.myclaw-backup';
38
38
  function findControlUiDir() {
39
39
  const candidates = [];
40
40
 
41
+ const isWin = process.platform === 'win32';
42
+ // 用 stdio 抑制 stderr,避免在 Windows cmd 上写 `2>/dev/null`
43
+ // (cmd 会把 /dev/null 当成路径 \dev\null,重定向失败并中断命令执行)
44
+ const runQuiet = (cmd) => {
45
+ const { execSync } = require('child_process');
46
+ return execSync(cmd, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] }).trim();
47
+ };
48
+
41
49
  // 1. 通过 require.resolve 查找
42
50
  const globalPaths = [
43
51
  '/usr/lib/node_modules',
@@ -46,9 +54,10 @@ function findControlUiDir() {
46
54
 
47
55
  // 加上当前 npm prefix
48
56
  try {
49
- const { execSync } = require('child_process');
50
- const prefix = execSync('npm config get prefix 2>/dev/null', { encoding: 'utf8' }).trim();
57
+ const prefix = runQuiet('npm config get prefix');
51
58
  if (prefix) {
59
+ // Windows: 全局包在 <prefix>\node_modules;Unix: 在 <prefix>/lib/node_modules
60
+ globalPaths.push(path.join(prefix, 'node_modules'));
52
61
  globalPaths.push(path.join(prefix, 'lib', 'node_modules'));
53
62
  }
54
63
  } catch {}
@@ -62,8 +71,7 @@ function findControlUiDir() {
62
71
  }
63
72
  // 也尝试通过命令动态获取(如果 pnpm 在 PATH 里)
64
73
  try {
65
- const { execSync } = require('child_process');
66
- const pnpmRoot = execSync('pnpm root -g 2>/dev/null', { encoding: 'utf8' }).trim();
74
+ const pnpmRoot = runQuiet('pnpm root -g');
67
75
  if (pnpmRoot) globalPaths.push(pnpmRoot);
68
76
  } catch {}
69
77
 
@@ -71,10 +79,10 @@ function findControlUiDir() {
71
79
  candidates.push(path.join(globalPath, 'openclaw', 'dist', 'control-ui'));
72
80
  }
73
81
 
74
- // 2. 通过 which openclaw 推断
82
+ // 2. 通过 which/where openclaw 推断
75
83
  try {
76
- const { execSync } = require('child_process');
77
- const bin = execSync('which openclaw 2>/dev/null', { encoding: 'utf8' }).trim();
84
+ // Windows 没有 which,用 where;可能返回多行(.ps1/.cmd),取第一行
85
+ const bin = runQuiet(isWin ? 'where openclaw' : 'which openclaw').split(/\r?\n/)[0].trim();
78
86
  if (bin) {
79
87
  const real = fs.realpathSync(bin);
80
88
  // openclaw.mjs → 包根目录
@@ -0,0 +1,33 @@
1
+ #!/bin/bash
2
+ # 注入 ES2023 Array Polyfill 到 OpenClaw 首页
3
+ # 使用方法: bash inject_polyfill.sh
4
+
5
+ TARGET="/root/.npm-global/lib/node_modules/openclaw/dist/control-ui/index.html"
6
+
7
+ # 第一步:备份原文件
8
+ echo ">>> 第一步:备份原文件..."
9
+ cp "$TARGET" "${TARGET}.bak2"
10
+ if [ $? -eq 0 ]; then
11
+ echo " 备份成功: ${TARGET}.bak2"
12
+ else
13
+ echo " 备份失败,退出。"
14
+ exit 1
15
+ fi
16
+
17
+ # 第二步:注入 polyfill 到 <head> 标签内
18
+ echo ">>> 第二步:注入 polyfill..."
19
+
20
+ POLYFILL='<script>\n// Polyfill for Array.prototype.toSorted (ES2023)\nif (!Array.prototype.toSorted) {\n Array.prototype.toSorted = function(compareFn) {\n return this.slice().sort(compareFn);\n };\n}\n// Polyfill for Array.prototype.toReversed (ES2023)\nif (!Array.prototype.toReversed) {\n Array.prototype.toReversed = function() {\n return this.slice().reverse();\n };\n}\n// Polyfill for Array.prototype.toSpliced (ES2023)\nif (!Array.prototype.toSpliced) {\n Array.prototype.toSpliced = function(start, deleteCount, ...items) {\n var copy = this.slice();\n copy.splice(start, deleteCount, ...items);\n return copy;\n };\n}\n// Polyfill for Array.prototype.with (ES2023)\nif (!Array.prototype.with) {\n Array.prototype.with = function(index, value) {\n var copy = this.slice();\n copy[index] = value;\n return copy;\n };\n}\n<\/script>'
21
+
22
+ # 在 <head> 之后插入 polyfill
23
+ sed -i "s|<head>|<head>\n${POLYFILL}|" "$TARGET"
24
+
25
+ if [ $? -eq 0 ]; then
26
+ echo " polyfill 注入成功!"
27
+ else
28
+ echo " 注入失败,从备份恢复..."
29
+ cp "${TARGET}.bak2" "$TARGET"
30
+ exit 1
31
+ fi
32
+
33
+ echo ">>> 完成!"
@@ -15,6 +15,11 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
15
15
  from urllib.parse import urlparse, parse_qs, unquote
16
16
  from qiniu import Auth, put_file_v2, put_data, CdnManager, BucketManager
17
17
 
18
+ # Windows 控制台默认用 GBK,print emoji(如 ✅)会抛 UnicodeEncodeError,强制标准流走 UTF-8
19
+ if hasattr(sys.stdout, 'reconfigure'):
20
+ sys.stdout.reconfigure(encoding='utf-8')
21
+ sys.stderr.reconfigure(encoding='utf-8')
22
+
18
23
  # 确保同目录的共享模块可导入
19
24
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
20
25
  from artifacts_schema import ARTIFACTS_FILENAME, create_empty_artifacts, now_iso as _now_iso
@@ -22,7 +27,9 @@ import debug_record
22
27
 
23
28
  # 跨平台获取 openclaw 目录
24
29
  def get_openclaw_path():
25
- if platform.system() == 'Windows' or os.path.exists('/root/.openclaw'):
30
+ # Windows 上 '/' 会被解释成当前盘符根目录(如 E:\root\.openclaw),
31
+ # 不是真正的文件系统根,因此 /root/.openclaw 判断只在非 Windows 上有意义。
32
+ if platform.system() != 'Windows' and os.path.exists('/root/.openclaw'):
26
33
  return '/root/.openclaw'
27
34
  return os.path.expanduser('~/.openclaw')
28
35