@aiyiran/myclaw 1.0.156 → 1.0.159
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.
- package/.claude/settings.local.json +7 -0
- package/index.js +8 -0
- package/package.json +1 -1
- package/patch-manifest.json +5 -0
- package/restrict.js +123 -0
- package/scripts/restrict-wsl-access.sh +170 -0
package/index.js
CHANGED
|
@@ -361,6 +361,11 @@ function runWsl2() {
|
|
|
361
361
|
wsl2.run();
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
function runRestrict() {
|
|
365
|
+
const restrict = require('./restrict');
|
|
366
|
+
restrict.run();
|
|
367
|
+
}
|
|
368
|
+
|
|
364
369
|
async function runLaunch() {
|
|
365
370
|
const launch = require('./launch');
|
|
366
371
|
await launch.run();
|
|
@@ -1127,6 +1132,7 @@ function showHelp() {
|
|
|
1127
1132
|
console.log(' open 打开浏览器控制台(自动带 token)');
|
|
1128
1133
|
console.log(' fix 兜底修复(自动补装 WSL + Chrome,仅限 Windows)');
|
|
1129
1134
|
console.log(' wsl2 WSL2 一键安装/修复 (仅限 Windows, 可选: --cli)');
|
|
1135
|
+
console.log(' restrict WSL2 权限封锁 (禁止自动挂载 Windows 盘符)');
|
|
1130
1136
|
console.log(' bat 在桌面生成一键启动脚本 (仅限 Windows)');
|
|
1131
1137
|
console.log(' list 查看注入资源管理列表(智能体/技能/配置)');
|
|
1132
1138
|
console.log(' pull 从 ~/.openclaw 拉取最新资源到源目录(开发用)');
|
|
@@ -1201,6 +1207,8 @@ if (!command) {
|
|
|
1201
1207
|
runFix();
|
|
1202
1208
|
} else if (command === 'wsl2') {
|
|
1203
1209
|
runWsl2();
|
|
1210
|
+
} else if (command === 'restrict') {
|
|
1211
|
+
runRestrict();
|
|
1204
1212
|
} else if (command === 'launch') {
|
|
1205
1213
|
runLaunch();
|
|
1206
1214
|
} else if (command === 'bat') {
|
package/package.json
CHANGED
package/patch-manifest.json
CHANGED
package/restrict.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ============================================================================
|
|
5
|
+
* MyClaw WSL2 权限封锁
|
|
6
|
+
* ============================================================================
|
|
7
|
+
*
|
|
8
|
+
* 功能:逐步封锁 WSL2 对 Windows 文件系统的访问权限
|
|
9
|
+
*
|
|
10
|
+
* 使用方法:
|
|
11
|
+
* myclaw restrict
|
|
12
|
+
* ============================================================================
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const { execSync } = require('child_process');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// 配置
|
|
21
|
+
// ============================================================================
|
|
22
|
+
|
|
23
|
+
const isWindows = os.platform() === 'win32';
|
|
24
|
+
|
|
25
|
+
const C = isWindows
|
|
26
|
+
? { r: '', g: '', y: '', b: '', nc: '' }
|
|
27
|
+
: { r: '\x1b[31m', g: '\x1b[32m', y: '\x1b[33m', b: '\x1b[34m', nc: '\x1b[0m' };
|
|
28
|
+
|
|
29
|
+
const SCRIPT_PATH = path.join(__dirname, 'scripts', 'restrict-wsl-access.sh');
|
|
30
|
+
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// 工具函数
|
|
33
|
+
// ============================================================================
|
|
34
|
+
|
|
35
|
+
function printStep(msg) {
|
|
36
|
+
console.log(C.g + '===>' + C.nc + ' ' + msg);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function printInfo(msg) {
|
|
40
|
+
console.log(C.b + '[信息]' + C.nc + ' ' + msg);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function printSuccess(msg) {
|
|
44
|
+
console.log(C.g + '[成功]' + C.nc + ' ' + msg);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function printWarning(msg) {
|
|
48
|
+
console.log(C.y + '[警告]' + C.nc + ' ' + msg);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function printError(msg) {
|
|
52
|
+
console.error(C.r + '[错误]' + C.nc + ' ' + msg);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 检查是否在 WSL 环境中
|
|
56
|
+
function isWSL() {
|
|
57
|
+
try {
|
|
58
|
+
const version = require('fs').readFileSync('/proc/version', 'utf8');
|
|
59
|
+
return /microsoft|wsl/i.test(version);
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 在 WSL 中执行脚本
|
|
66
|
+
function runInWSL(scriptPath) {
|
|
67
|
+
try {
|
|
68
|
+
const cmd = `bash "${scriptPath}"`;
|
|
69
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
70
|
+
return true;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
printError('执行失败: ' + err.message);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// 主函数
|
|
79
|
+
// ============================================================================
|
|
80
|
+
|
|
81
|
+
function run() {
|
|
82
|
+
console.log('');
|
|
83
|
+
console.log('========================================');
|
|
84
|
+
console.log(' MyClaw WSL2 权限封锁');
|
|
85
|
+
console.log('========================================');
|
|
86
|
+
console.log('');
|
|
87
|
+
|
|
88
|
+
// 如果在 Windows 上,提示需要在 WSL 中运行
|
|
89
|
+
if (isWindows) {
|
|
90
|
+
printWarning('此命令需要在 WSL2 环境中运行');
|
|
91
|
+
console.log('');
|
|
92
|
+
console.log('请按以下步骤操作:');
|
|
93
|
+
console.log(' 1. 打开 WSL2 终端(在 Windows Terminal 中选择 OpenClaw)');
|
|
94
|
+
console.log(' 2. 在 WSL2 终端中运行: ' + C.y + 'myclaw restrict' + C.nc);
|
|
95
|
+
console.log('');
|
|
96
|
+
console.log('或者,在 Windows PowerShell 中运行:');
|
|
97
|
+
console.log(' ' + C.y + 'wsl -d OpenClaw -- myclaw restrict' + C.nc);
|
|
98
|
+
console.log(' (将 OpenClaw 替换为你的 WSL 发行版名称)');
|
|
99
|
+
console.log('');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 检查是否在 WSL 环境中
|
|
104
|
+
if (!isWSL()) {
|
|
105
|
+
printError('此脚本只能在 WSL2 环境中运行');
|
|
106
|
+
console.log('');
|
|
107
|
+
console.log('如果你在 Windows 上,请先安装 WSL2:');
|
|
108
|
+
console.log(' ' + C.y + 'myclaw wsl2' + C.nc);
|
|
109
|
+
console.log('');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
printSuccess('检测到 WSL2 环境');
|
|
114
|
+
console.log('');
|
|
115
|
+
|
|
116
|
+
// 执行权限封锁脚本
|
|
117
|
+
printStep('启动权限封锁脚本...');
|
|
118
|
+
console.log('');
|
|
119
|
+
|
|
120
|
+
runInWSL(SCRIPT_PATH);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = { run };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
###############################################################################
|
|
4
|
+
# MyClaw WSL2 权限封锁脚本
|
|
5
|
+
#
|
|
6
|
+
# 功能:逐步封锁 WSL2 对 Windows 文件系统的访问权限
|
|
7
|
+
#
|
|
8
|
+
# 使用方法:
|
|
9
|
+
# bash scripts/restrict-wsl-access.sh
|
|
10
|
+
#
|
|
11
|
+
###############################################################################
|
|
12
|
+
|
|
13
|
+
set -e
|
|
14
|
+
|
|
15
|
+
# 颜色定义
|
|
16
|
+
RED='\033[0;31m'
|
|
17
|
+
GREEN='\033[0;32m'
|
|
18
|
+
YELLOW='\033[1;33m'
|
|
19
|
+
BLUE='\033[0;34m'
|
|
20
|
+
NC='\033[0m' # No Color
|
|
21
|
+
|
|
22
|
+
WSL_CONF="/etc/wsl.conf"
|
|
23
|
+
BACKUP_DIR="/tmp/wsl_conf_backup_$(date +%Y%m%d_%H%M%S)"
|
|
24
|
+
|
|
25
|
+
# 打印带颜色的消息
|
|
26
|
+
print_info() {
|
|
27
|
+
echo -e "${BLUE}[信息]${NC} $1"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
print_success() {
|
|
31
|
+
echo -e "${GREEN}[成功]${NC} $1"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
print_warning() {
|
|
35
|
+
echo -e "${YELLOW}[警告]${NC} $1"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
print_error() {
|
|
39
|
+
echo -e "${RED}[错误]${NC} $1"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
print_step() {
|
|
43
|
+
echo -e "${GREEN}==>${NC} $1"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# 检查是否在 WSL 环境中运行
|
|
47
|
+
check_wsl_environment() {
|
|
48
|
+
if [[ ! -f /proc/version ]] || ! grep -qi "microsoft\|wsl" /proc/version 2>/dev/null; then
|
|
49
|
+
print_error "此脚本必须在 WSL2 环境中运行"
|
|
50
|
+
exit 1
|
|
51
|
+
fi
|
|
52
|
+
print_success "检测到 WSL2 环境"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# 备份现有配置
|
|
56
|
+
backup_existing_config() {
|
|
57
|
+
if [[ -f "$WSL_CONF" ]]; then
|
|
58
|
+
print_info "备份现有配置到: $BACKUP_DIR"
|
|
59
|
+
mkdir -p "$BACKUP_DIR"
|
|
60
|
+
sudo cp "$WSL_CONF" "$BACKUP_DIR/wsl.conf.bak"
|
|
61
|
+
print_success "配置已备份"
|
|
62
|
+
else
|
|
63
|
+
print_info "没有现有配置需要备份"
|
|
64
|
+
fi
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# 步骤 A: 禁止自动挂载整个盘
|
|
68
|
+
step_a_disable_automount() {
|
|
69
|
+
print_step "步骤 A: 禁止自动挂载 Windows 盘符"
|
|
70
|
+
|
|
71
|
+
echo ""
|
|
72
|
+
echo "此操作将:"
|
|
73
|
+
echo " 1. 编辑 /etc/wsl.conf"
|
|
74
|
+
echo " 2. 设置 [automount] enabled = false"
|
|
75
|
+
echo " 3. 使 Linux 默认看不到 /mnt/c 等盘符"
|
|
76
|
+
echo ""
|
|
77
|
+
|
|
78
|
+
# 创建临时文件
|
|
79
|
+
local temp_file=$(mktemp)
|
|
80
|
+
|
|
81
|
+
# 如果原文件存在,保留非 automount 部分的内容
|
|
82
|
+
if [[ -f "$WSL_CONF" ]]; then
|
|
83
|
+
# 移除现有的 [automount] 部分
|
|
84
|
+
awk '
|
|
85
|
+
BEGIN { in_automount = 0; skip = 0 }
|
|
86
|
+
/^\[automount\]/ { in_automount = 1; skip = 1; next }
|
|
87
|
+
/^\[/ { if (in_automount) { in_automount = 0; skip = 0 } }
|
|
88
|
+
{ if (!skip) print }
|
|
89
|
+
' "$WSL_CONF" > "$temp_file"
|
|
90
|
+
fi
|
|
91
|
+
|
|
92
|
+
# 添加 automount 配置
|
|
93
|
+
cat >> "$temp_file" << EOF
|
|
94
|
+
|
|
95
|
+
[automount]
|
|
96
|
+
enabled = false
|
|
97
|
+
EOF
|
|
98
|
+
|
|
99
|
+
# 写入配置文件
|
|
100
|
+
print_info "写入配置到 $WSL_CONF"
|
|
101
|
+
sudo mv "$temp_file" "$WSL_CONF"
|
|
102
|
+
sudo chmod 644 "$WSL_CONF"
|
|
103
|
+
|
|
104
|
+
print_success "配置已写入"
|
|
105
|
+
echo ""
|
|
106
|
+
print_warning "需要重启 WSL2 才能生效!"
|
|
107
|
+
echo ""
|
|
108
|
+
|
|
109
|
+
# 显示当前配置
|
|
110
|
+
print_info "当前 /etc/wsl.conf 内容:"
|
|
111
|
+
echo "----------------------------------------"
|
|
112
|
+
sudo cat "$WSL_CONF"
|
|
113
|
+
echo "----------------------------------------"
|
|
114
|
+
echo ""
|
|
115
|
+
|
|
116
|
+
return 0
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
# 显示重启说明
|
|
120
|
+
show_restart_instructions() {
|
|
121
|
+
echo ""
|
|
122
|
+
echo "========================================"
|
|
123
|
+
print_warning "重要提示"
|
|
124
|
+
echo "========================================"
|
|
125
|
+
echo ""
|
|
126
|
+
echo "配置已完成,但需要重启 WSL2 才能生效!"
|
|
127
|
+
echo ""
|
|
128
|
+
echo "重启方法:"
|
|
129
|
+
echo ""
|
|
130
|
+
echo " 方法 1 (推荐): 在 Windows PowerShell 中运行"
|
|
131
|
+
echo -e " ${YELLOW}wsl --shutdown${NC}"
|
|
132
|
+
echo " 然后重新打开 WSL2 终端"
|
|
133
|
+
echo ""
|
|
134
|
+
echo " 方法 2: 在 Windows 命令提示符中运行"
|
|
135
|
+
echo -e " ${YELLOW}wsl --terminate OpenClaw${NC}"
|
|
136
|
+
echo " (替换 OpenClaw 为你的发行版名称)"
|
|
137
|
+
echo ""
|
|
138
|
+
echo "重启后验证:"
|
|
139
|
+
echo " - ls /mnt/c 应该显示目录不存在或为空"
|
|
140
|
+
echo " - Windows 文件系统对 Linux 不可见"
|
|
141
|
+
echo ""
|
|
142
|
+
echo "========================================"
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# 主函数
|
|
146
|
+
main() {
|
|
147
|
+
echo ""
|
|
148
|
+
echo "========================================"
|
|
149
|
+
echo " MyClaw WSL2 权限封锁脚本"
|
|
150
|
+
echo "========================================"
|
|
151
|
+
echo ""
|
|
152
|
+
|
|
153
|
+
# 检查环境
|
|
154
|
+
check_wsl_environment
|
|
155
|
+
|
|
156
|
+
# 备份现有配置
|
|
157
|
+
backup_existing_config
|
|
158
|
+
|
|
159
|
+
# 执行步骤 A
|
|
160
|
+
step_a_disable_automount
|
|
161
|
+
|
|
162
|
+
# 显示重启说明
|
|
163
|
+
show_restart_instructions
|
|
164
|
+
|
|
165
|
+
print_success "步骤 A 配置完成!"
|
|
166
|
+
echo ""
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# 运行主函数
|
|
170
|
+
main "$@"
|