@aiyiran/myclaw 1.0.167 → 1.0.169

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/package.json +1 -1
  2. package/restrict.js +12 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.167",
3
+ "version": "1.0.169",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/restrict.js CHANGED
@@ -49,7 +49,7 @@ function printError(msg) { console.error(C.r + '[错误]' + C.nc + ' ' + msg); }
49
49
  // 在 WSL 中执行命令,返回 stdout
50
50
  function wslExec(cmd) {
51
51
  try {
52
- return execSync('wsl -d ' + DISTRO_NAME + ' -- ' + cmd, {
52
+ return execSync('wsl -d ' + DISTRO_NAME + ' -- bash -c "' + cmd + '"', {
53
53
  encoding: 'utf8',
54
54
  stdio: ['pipe', 'pipe', 'pipe'],
55
55
  }).trim();
@@ -58,26 +58,24 @@ function wslExec(cmd) {
58
58
  }
59
59
  }
60
60
 
61
- // 写临时 shell 脚本到 WSL 内,然后以 root 执行
62
- // 这样避免 Windows cmd.exe 对管道/重定向的干扰
61
+ // 写临时 shell 脚本到 Windows,然后让 WSL 执行
62
+ // 避免 cmd.exe 转义问题:脚本内容通过文件传递,不走命令行
63
63
  function wslRunScriptAsRoot(scriptContent) {
64
- // 把脚本写到 WSL /tmp
65
- const tmpScript = '/tmp/myclaw_safe_setup.sh';
66
- const b64 = Buffer.from(scriptContent).toString('base64');
64
+ const tmpDir = path.join(process.env.LOCALAPPDATA || os.tmpdir(), 'myclaw');
65
+ try { fs.mkdirSync(tmpDir, { recursive: true }); } catch {}
66
+ const scriptFile = path.join(tmpDir, 'safe-setup.sh');
67
+ fs.writeFileSync(scriptFile, scriptContent, 'utf8');
68
+
69
+ // Windows 路径转 WSL 路径: C:\Users\... → /mnt/c/Users/...
70
+ const wslPath = '/mnt/' + scriptFile.charAt(0).toLowerCase() + scriptFile.slice(2).replace(/\\/g, '/');
67
71
 
68
72
  try {
69
- // 写入脚本
70
- execSync('wsl -d ' + DISTRO_NAME + ' -u root -- bash -c "echo ' + b64 + ' | base64 -d > ' + tmpScript + '"', {
71
- encoding: 'utf8',
72
- stdio: 'pipe',
73
- });
74
- // 执行脚本
75
- execSync('wsl -d ' + DISTRO_NAME + ' -u root -- bash ' + tmpScript, {
73
+ execSync('wsl -d ' + DISTRO_NAME + ' -u root -- bash ' + wslPath, {
76
74
  encoding: 'utf8',
77
75
  stdio: 'pipe',
78
76
  });
79
77
  return true;
80
- } catch (err) {
78
+ } catch {
81
79
  return false;
82
80
  }
83
81
  }