@aiyiran/myclaw 1.0.125 → 1.0.126
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/package.json +1 -1
- package/patch-manifest.json +1 -1
- package/wsl2.js +77 -58
package/package.json
CHANGED
package/patch-manifest.json
CHANGED
package/wsl2.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* MyClaw WSL2 一键安装器
|
|
6
6
|
* ============================================================================
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* 采用"固定流程 + 状态标记"机制,避免使用容易出错的环境嗅探(wsl --status)。
|
|
9
9
|
* 标记文件:~/.myclaw_wsl_state
|
|
10
10
|
*
|
|
11
|
-
* Phase 1:
|
|
12
|
-
* Phase 2:
|
|
11
|
+
* Phase 1: 启用底层功能 + 安装 WSL + 下载 Linux 镜像 → 需要重启
|
|
12
|
+
* Phase 2: 导入已下载的 Linux 环境 → 自动启动 Gateway(极快)
|
|
13
13
|
* ============================================================================
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -34,6 +34,7 @@ const C = isWindows
|
|
|
34
34
|
: { r: '\x1b[31m', g: '\x1b[32m', y: '\x1b[33m', b: '\x1b[34m', nc: '\x1b[0m' };
|
|
35
35
|
|
|
36
36
|
const STATE_FILE = path.join(os.homedir(), '.myclaw_wsl_state');
|
|
37
|
+
const MARKER_PATH_PS = STATE_FILE.replace(/\\/g, '\\\\');
|
|
37
38
|
|
|
38
39
|
// ============================================================================
|
|
39
40
|
// 工具函数
|
|
@@ -51,7 +52,6 @@ function setState(state) {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
function launchElevatedPS(script) {
|
|
54
|
-
// 把脚本写到临时文件(避免 Windows 命令行长度限制)
|
|
55
55
|
const tmpDir = process.env.LOCALAPPDATA
|
|
56
56
|
? path.join(process.env.LOCALAPPDATA, 'myclaw')
|
|
57
57
|
: path.join(os.tmpdir(), 'myclaw');
|
|
@@ -62,7 +62,6 @@ function launchElevatedPS(script) {
|
|
|
62
62
|
const BOM = '\uFEFF';
|
|
63
63
|
fs.writeFileSync(scriptPath, BOM + script, 'utf8');
|
|
64
64
|
|
|
65
|
-
// 用 -NoExit 确保即使脚本出错窗口也不会关闭
|
|
66
65
|
const escaped = scriptPath.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
67
66
|
const cmd = `powershell -Command "Start-Process powershell -ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-NoExit','-File','${escaped}') -Verb RunAs"`;
|
|
68
67
|
|
|
@@ -135,10 +134,10 @@ if ($resolved) {
|
|
|
135
134
|
Write-Host ' ⚠️ 如果你觉得进度条卡住不动了,请在键盘上按一下【回车键】即可解冻!'
|
|
136
135
|
Write-Host ' ============================================================='
|
|
137
136
|
try {
|
|
138
|
-
Start-BitsTransfer -Source '${cdnUrl}' -Destination ${destVar} -Description '下载
|
|
137
|
+
Start-BitsTransfer -Source '${cdnUrl}' -Destination ${destVar} -Description '下载 ${desc}' -DisplayName 'OpenClaw'
|
|
139
138
|
Write-Host ' 下载完成!'
|
|
140
139
|
} catch {
|
|
141
|
-
Write-Host ' [失败] 下载失败,请检查网络后重试
|
|
140
|
+
Write-Host ' [失败] 下载失败,请检查网络后重试'
|
|
142
141
|
throw '下载失败'
|
|
143
142
|
}
|
|
144
143
|
}
|
|
@@ -146,16 +145,17 @@ if ($resolved) {
|
|
|
146
145
|
}
|
|
147
146
|
|
|
148
147
|
// ============================================================================
|
|
149
|
-
// Phase 1: 启用功能 + 安装 WSL
|
|
148
|
+
// Phase 1: 启用功能 + 安装 WSL + 下载 Linux 镜像(全部在重启前完成)
|
|
150
149
|
// ============================================================================
|
|
151
150
|
|
|
152
151
|
function runPhase1() {
|
|
153
152
|
console.log('');
|
|
154
|
-
console.log('[当前进度] WSL 功能
|
|
155
|
-
console.log(' WSL 组件
|
|
156
|
-
console.log(' Linux
|
|
153
|
+
console.log('[当前进度] WSL 功能 ' + C.y + '[安装/覆盖]' + C.nc);
|
|
154
|
+
console.log(' WSL 组件 ' + C.y + '[安装/重置]' + C.nc);
|
|
155
|
+
console.log(' Linux 镜像 ' + C.y + '[待下载]' + C.nc);
|
|
156
|
+
console.log(' Linux 环境 ' + C.r + '[未安装]' + C.nc);
|
|
157
157
|
console.log('');
|
|
158
|
-
console.log('阶段 1/2:
|
|
158
|
+
console.log('阶段 1/2: 配置系统组件 + 下载全部安装素材');
|
|
159
159
|
console.log(' 完成后需要 ' + C.y + '重启电脑' + C.nc);
|
|
160
160
|
console.log('');
|
|
161
161
|
console.log('[' + C.y + '注意' + C.nc + '] 请在 UAC 弹窗中点击【是】');
|
|
@@ -169,6 +169,14 @@ function runPhase1() {
|
|
|
169
169
|
'wsl_full.msi'
|
|
170
170
|
);
|
|
171
171
|
|
|
172
|
+
const askTar = makeAskLocalOrCDN(
|
|
173
|
+
'拖拽 tar 包或回车下载',
|
|
174
|
+
'$tarPath',
|
|
175
|
+
WSL_CDN.rootfs,
|
|
176
|
+
'Linux 环境包 (openclaw-rootfs.tar)',
|
|
177
|
+
'openclaw-rootfs.tar'
|
|
178
|
+
);
|
|
179
|
+
|
|
172
180
|
const ps = `
|
|
173
181
|
$ErrorActionPreference = 'Continue'
|
|
174
182
|
$Host.UI.RawUI.WindowTitle = 'MyClaw WSL2 Installer - Phase 1'
|
|
@@ -176,14 +184,16 @@ try {
|
|
|
176
184
|
Write-Host ''
|
|
177
185
|
Write-Host '========================================'
|
|
178
186
|
Write-Host ' MyClaw WSL2 安装 - 阶段 1/2'
|
|
187
|
+
Write-Host ' 配置系统 + 下载全部安装素材'
|
|
179
188
|
Write-Host '========================================'
|
|
180
189
|
Write-Host ''
|
|
181
190
|
|
|
182
|
-
$dir = "$env:LOCALAPPDATA
|
|
191
|
+
$dir = "$env:LOCALAPPDATA\\\\myclaw"
|
|
183
192
|
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
|
184
|
-
$msi = "$dir
|
|
193
|
+
$msi = "$dir\\\\wsl_full.msi"
|
|
194
|
+
$tarPath = "$dir\\\\openclaw-rootfs.tar"
|
|
185
195
|
|
|
186
|
-
Write-Host '[1/
|
|
196
|
+
Write-Host '[1/5] 启用 Windows Subsystem for Linux...'
|
|
187
197
|
try {
|
|
188
198
|
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart | Out-Null
|
|
189
199
|
Write-Host ' [OK]'
|
|
@@ -192,7 +202,7 @@ try {
|
|
|
192
202
|
}
|
|
193
203
|
Write-Host ''
|
|
194
204
|
|
|
195
|
-
Write-Host '[2/
|
|
205
|
+
Write-Host '[2/5] 启用虚拟机平台...'
|
|
196
206
|
try {
|
|
197
207
|
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart | Out-Null
|
|
198
208
|
Write-Host ' [OK]'
|
|
@@ -201,14 +211,13 @@ try {
|
|
|
201
211
|
}
|
|
202
212
|
Write-Host ''
|
|
203
213
|
|
|
204
|
-
Write-Host '[3/
|
|
205
|
-
# 移除文件以保证不做本地缓存
|
|
214
|
+
Write-Host '[3/5] 获取 WSL 安装包...'
|
|
206
215
|
if (Test-Path $msi) { Remove-Item $msi -Force }
|
|
207
216
|
|
|
208
217
|
${askMsi}
|
|
209
218
|
|
|
210
219
|
Write-Host ''
|
|
211
|
-
Write-Host '[4/
|
|
220
|
+
Write-Host '[4/5] 强制覆盖安装 WSL...'
|
|
212
221
|
try {
|
|
213
222
|
Start-Process msiexec.exe -ArgumentList @('/i', $msi, '/quiet', '/norestart') -Wait -NoNewWindow
|
|
214
223
|
if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne 3010) {
|
|
@@ -221,20 +230,27 @@ try {
|
|
|
221
230
|
throw 'MSI 安装失败'
|
|
222
231
|
}
|
|
223
232
|
|
|
224
|
-
#
|
|
233
|
+
# MSI 装完立即删除
|
|
225
234
|
if (Test-Path $msi) { Remove-Item $msi -Force }
|
|
235
|
+
Write-Host ''
|
|
226
236
|
|
|
227
|
-
|
|
228
|
-
|
|
237
|
+
Write-Host '[5/5] 下载 Linux 环境镜像...'
|
|
238
|
+
Write-Host ' (此文件较大,下载完成后会保留到重启后使用)'
|
|
239
|
+
if (Test-Path $tarPath) { Remove-Item $tarPath -Force }
|
|
240
|
+
|
|
241
|
+
${askTar}
|
|
242
|
+
|
|
243
|
+
# 写入状态标记(使用普通用户路径)
|
|
244
|
+
$markerPath = "${MARKER_PATH_PS}"
|
|
229
245
|
Out-File -FilePath "$markerPath" -InputObject "phase1-done" -Encoding utf8 -Force
|
|
230
246
|
|
|
231
247
|
Write-Host ''
|
|
232
248
|
Write-Host '========================================'
|
|
233
|
-
Write-Host ' 阶段 1/2 完成!'
|
|
249
|
+
Write-Host ' 阶段 1/2 完成! 所有文件已准备就绪!'
|
|
234
250
|
Write-Host ''
|
|
235
251
|
Write-Host ' >>> 请立即 [重启电脑] <<<'
|
|
236
252
|
Write-Host ''
|
|
237
|
-
Write-Host '
|
|
253
|
+
Write-Host ' 重启后请点击桌面上的 [龙虾图标] 继续安装'
|
|
238
254
|
Write-Host '========================================'
|
|
239
255
|
|
|
240
256
|
} catch {
|
|
@@ -253,33 +269,26 @@ Write-Host '========================================'
|
|
|
253
269
|
if (launchElevatedPS(ps)) {
|
|
254
270
|
console.log('[' + C.g + '已启动' + C.nc + '] 请查看新弹出的蓝色窗口');
|
|
255
271
|
console.log('');
|
|
256
|
-
console.log('执行完请 ' + C.y + '重启电脑' + C.nc + '
|
|
272
|
+
console.log('执行完请 ' + C.y + '重启电脑' + C.nc + ',然后点击桌面上的 ' + C.y + '龙虾图标' + C.nc + ' 继续安装');
|
|
257
273
|
console.log('');
|
|
258
274
|
}
|
|
259
275
|
}
|
|
260
276
|
|
|
261
277
|
// ============================================================================
|
|
262
|
-
// Phase 2:
|
|
278
|
+
// Phase 2: 导入已下载的 Linux 环境(重启后,纯本地操作,极快)
|
|
263
279
|
// ============================================================================
|
|
264
280
|
|
|
265
281
|
function runPhase2() {
|
|
266
282
|
console.log('');
|
|
267
|
-
console.log('[当前进度] WSL 功能
|
|
268
|
-
console.log(' WSL 组件
|
|
269
|
-
console.log(' Linux
|
|
283
|
+
console.log('[当前进度] WSL 功能 ' + C.g + '[已就绪]' + C.nc);
|
|
284
|
+
console.log(' WSL 组件 ' + C.g + '[已就绪]' + C.nc);
|
|
285
|
+
console.log(' Linux 镜像 ' + C.g + '[已下载]' + C.nc);
|
|
286
|
+
console.log(' Linux 环境 ' + C.y + '[待导入]' + C.nc);
|
|
270
287
|
console.log('');
|
|
271
|
-
console.log('即将导入预制 Linux
|
|
288
|
+
console.log('即将导入预制 Linux 环境(纯本地操作,很快)...');
|
|
272
289
|
console.log('[' + C.y + '注意' + C.nc + '] 请在 UAC 弹窗中点击【是】');
|
|
273
290
|
console.log('');
|
|
274
291
|
|
|
275
|
-
const askTar = makeAskLocalOrCDN(
|
|
276
|
-
'拖拽 tar 包或回车下载',
|
|
277
|
-
'$tarPath',
|
|
278
|
-
WSL_CDN.rootfs,
|
|
279
|
-
'Linux 环境包 (openclaw-rootfs.tar)',
|
|
280
|
-
'openclaw-rootfs.tar'
|
|
281
|
-
);
|
|
282
|
-
|
|
283
292
|
const ps = `
|
|
284
293
|
$ErrorActionPreference = 'Continue'
|
|
285
294
|
$Host.UI.RawUI.WindowTitle = 'MyClaw WSL2 Installer - Phase 2'
|
|
@@ -291,27 +300,37 @@ Write-Host ' 导入预制 Linux 环境'
|
|
|
291
300
|
Write-Host '========================================'
|
|
292
301
|
Write-Host ''
|
|
293
302
|
|
|
294
|
-
$dir = "$env:LOCALAPPDATA
|
|
303
|
+
$dir = "$env:LOCALAPPDATA\\\\myclaw"
|
|
295
304
|
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
|
296
|
-
$tarPath = "$dir
|
|
305
|
+
$tarPath = "$dir\\\\openclaw-rootfs.tar"
|
|
306
|
+
$distroName = 'OpenClaw'
|
|
307
|
+
$installDir = "$dir\\\\OpenClaw"
|
|
308
|
+
$installed = $false
|
|
297
309
|
|
|
298
|
-
Write-Host '[1/
|
|
310
|
+
Write-Host '[1/4] 设置 WSL2 为默认版本...'
|
|
299
311
|
try { wsl --set-default-version 2 2>$null } catch {}
|
|
300
312
|
Write-Host ' [OK]'
|
|
301
313
|
Write-Host ''
|
|
302
314
|
|
|
303
|
-
Write-Host '[2/
|
|
304
|
-
$
|
|
305
|
-
$
|
|
306
|
-
$
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
${
|
|
312
|
-
|
|
313
|
-
|
|
315
|
+
Write-Host '[2/4] 检查 Linux 镜像文件...'
|
|
316
|
+
if (Test-Path $tarPath) {
|
|
317
|
+
$size = (Get-Item $tarPath).Length / 1MB
|
|
318
|
+
Write-Host " 找到本地镜像 ($([math]::Round($size, 1)) MB)"
|
|
319
|
+
Write-Host ' [OK]'
|
|
320
|
+
} else {
|
|
321
|
+
Write-Host ' [警告] 未找到已下载的镜像文件,需要重新获取...'
|
|
322
|
+
Write-Host ''
|
|
323
|
+
${makeAskLocalOrCDN(
|
|
324
|
+
'拖拽 tar 包或回车下载',
|
|
325
|
+
'$tarPath',
|
|
326
|
+
WSL_CDN.rootfs,
|
|
327
|
+
'Linux 环境包 (openclaw-rootfs.tar)',
|
|
328
|
+
'openclaw-rootfs.tar'
|
|
329
|
+
)}
|
|
330
|
+
}
|
|
331
|
+
Write-Host ''
|
|
314
332
|
|
|
333
|
+
Write-Host '[3/4] 导入 Linux 环境 (可能需要几分钟)...'
|
|
315
334
|
Write-Host ' 清理旧版本...'
|
|
316
335
|
try { wsl --unregister $distroName 2>$null } catch {}
|
|
317
336
|
Write-Host ' [OK]'
|
|
@@ -330,10 +349,10 @@ try {
|
|
|
330
349
|
}
|
|
331
350
|
Write-Host ''
|
|
332
351
|
|
|
333
|
-
# 导入完毕清理
|
|
352
|
+
# 导入完毕清理 tar 文件
|
|
334
353
|
if (Test-Path $tarPath) { Remove-Item $tarPath -Force }
|
|
335
354
|
|
|
336
|
-
Write-Host '[
|
|
355
|
+
Write-Host '[4/4] 验证安装结果...'
|
|
337
356
|
try {
|
|
338
357
|
$result = wsl -l -v 2>&1 | Out-String
|
|
339
358
|
Write-Host $result
|
|
@@ -348,7 +367,7 @@ if ($installed) {
|
|
|
348
367
|
Write-Host '========================================'
|
|
349
368
|
Write-Host ''
|
|
350
369
|
|
|
351
|
-
$markerPath = "${
|
|
370
|
+
$markerPath = "${MARKER_PATH_PS}"
|
|
352
371
|
Out-File -FilePath "$markerPath" -InputObject "phase2-done" -Encoding utf8 -Force
|
|
353
372
|
|
|
354
373
|
Write-Host '[镜像信息]'
|
|
@@ -362,7 +381,7 @@ if ($installed) {
|
|
|
362
381
|
|
|
363
382
|
wsl -d $distroName -- myclaw launch
|
|
364
383
|
} else {
|
|
365
|
-
Write-Host ' [失败]
|
|
384
|
+
Write-Host ' [失败] 请截图此窗口并联系老师'
|
|
366
385
|
Write-Host '========================================'
|
|
367
386
|
}
|
|
368
387
|
|
|
@@ -397,7 +416,7 @@ function run() {
|
|
|
397
416
|
process.exit(0);
|
|
398
417
|
}
|
|
399
418
|
|
|
400
|
-
//
|
|
419
|
+
// 隐藏的高级玩家后门
|
|
401
420
|
if (process.argv.includes('--force-phase1')) {
|
|
402
421
|
setState('needs-features');
|
|
403
422
|
}
|
|
@@ -423,7 +442,7 @@ function run() {
|
|
|
423
442
|
console.log('(运行 wsl -l -v 查看详情)');
|
|
424
443
|
}
|
|
425
444
|
console.log('');
|
|
426
|
-
console.log('
|
|
445
|
+
console.log('点击桌面上的 ' + C.y + '龙虾图标' + C.nc + ' 即可启动。');
|
|
427
446
|
console.log('');
|
|
428
447
|
|
|
429
448
|
const readline = require('readline');
|