Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
603 lines (575 loc) · 30.1 KB
/
Copy pathinstall.ps1
File metadata and controls
603 lines (575 loc) · 30.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# install.ps1 — MoA 安装脚本(增量合并 opencode.json)
# 用法: pwsh ./install.ps1 [-InstallPwsh]
# 兼容: Windows PowerShell 5.1+ / PowerShell Core 7+ (Linux/macOS)
# 需要: 先将 .opencode/ 复制到当前目录
# -InstallPwsh: Windows 且无 pwsh 时,自动下载官方 PowerShell 7 MSI 静默安装(5.1 下可用 powershell -File install.ps1 -InstallPwsh)
param(
[switch]$InstallPwsh,
[switch]$InstallNode,
[switch]$InstallDeps
)
$ErrorActionPreference = "Stop"
function Write-Step($step, $msg) {
Write-Host "`n[$step] $msg" -ForegroundColor Yellow
}
function Write-Ok($msg) {
Write-Host " ✓ $msg" -ForegroundColor Green
}
function Write-Skip($msg) {
Write-Host " - $msg" -ForegroundColor Gray
}
function Write-Fail($msg) {
Write-Host " ✗ $msg" -ForegroundColor Red
}
Write-Host "`n=== OpenCode MoA 安装 ===" -ForegroundColor Cyan
# -InstallDeps = 全部依赖先检查再安装
if ($InstallDeps) { $InstallPwsh = $true; $InstallNode = $true }
# 0. 可选:自动安装 PowerShell 7(官方 MSI 静默安装)
if ($InstallPwsh) {
Write-Step "0/3" "检查 PowerShell 7.1+ (pwsh)..."
$pwshPath = (Get-Command pwsh -ErrorAction SilentlyContinue).Source
$pwshVer = $null
if ($pwshPath) { $pwshVer = pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>$null }
$pwshOk = $false
if ($pwshVer) {
try { $pwshOk = [version]$pwshVer -ge [version]"7.1" } catch { $pwshOk = $false }
}
if ($pwshOk) {
Write-Skip "已安装 pwsh $pwshVer (>= 7.1),无需安装"
} else {
if ($env:OS -ne "Windows_NT") { Write-Fail "-InstallPwsh 仅支持 Windows(MSI 安装)"; exit 1 }
if ($pwshPath) { Write-Host " 当前 pwsh 版本 $pwshVer < 7.1,自动安装官方 MSI 升级..." -ForegroundColor Yellow }
else { Write-Host " pwsh 未安装,自动下载官方 MSI 静默安装..." -ForegroundColor Yellow }
try {
$rel = Invoke-RestMethod "https://api.github.com/repos/PowerShell/PowerShell/releases/latest" -Headers @{ "User-Agent" = "opencode-moa-installer" }
$ver = $rel.tag_name.TrimStart('v')
$asset = $rel.assets | Where-Object { $_.name -eq "PowerShell-$ver-win-x64.msi" } | Select-Object -First 1
if (-not $asset) { throw "最新版本 $ver 中未找到 win-x64 MSI 资产" }
$msi = Join-Path $env:TEMP $asset.name
Invoke-WebRequest $asset.browser_download_url -OutFile $msi
Write-Ok "已下载 $($asset.name) ($([math]::Round((Get-Item $msi).Length / 1MB, 1)) MB)"
$p = Start-Process msiexec -ArgumentList @("/i", "`"$msi`"", "/qn", "/norestart", "ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=0") -Wait -PassThru
if ($p.ExitCode -ne 0) { throw "msiexec 静默安装失败(退出码 $($p.ExitCode))" }
Remove-Item $msi -Force -ErrorAction SilentlyContinue
Write-Ok "PowerShell 7 ($ver) 已安装,重启终端后可用 pwsh"
} catch {
Write-Fail "自动安装失败: $($_.Exception.Message)"
Write-Host " 手动安装: https://github.com/PowerShell/PowerShell/releases (下载 win-x64 MSI 双击安装)" -ForegroundColor Gray
exit 1
}
}
}
# 0.5 可选:自动安装 Node.js(官方 MSI 静默安装)
if ($InstallNode) {
Write-Step "0/3" "检查 Node.js 14+..."
$nodePath = (Get-Command node -ErrorAction SilentlyContinue).Source
$nodeVer = $null
if ($nodePath) { $nodeVer = node --version 2>$null }
$nodeOk = $false
if ($nodeVer) {
try { $nodeOk = [int](($nodeVer.TrimStart('v') -split '\.')[0]) -ge 14 } catch { $nodeOk = $false }
}
if ($nodeOk) {
Write-Skip "已安装 node $nodeVer (>= 14),无需安装"
} else {
if ($env:OS -ne "Windows_NT") { Write-Fail "-InstallNode 仅支持 Windows(MSI 安装)"; exit 1 }
if ($nodePath) { Write-Host " 当前 node $nodeVer < 14,自动下载官方 MSI 升级..." -ForegroundColor Yellow }
else { Write-Host " node 未安装,自动下载官方 MSI 静默安装..." -ForegroundColor Yellow }
try {
$rel = Invoke-RestMethod "https://nodejs.org/dist/index.json"
$latest = $rel | Where-Object { $_.lts } | Select-Object -First 1
if (-not $latest) { $latest = $rel | Select-Object -First 1 }
$ver = $latest.version
$msiName = "node-$ver-x64.msi"
$msi = Join-Path $env:TEMP $msiName
Invoke-WebRequest "https://nodejs.org/dist/$ver/$msiName" -OutFile $msi
Write-Ok "已下载 $msiName ($([math]::Round((Get-Item $msi).Length / 1MB, 1)) MB)"
$p = Start-Process msiexec -ArgumentList @("/i", "`"$msi`"", "/qn", "/norestart") -Wait -PassThru
if ($p.ExitCode -ne 0) { throw "msiexec 静默安装失败(退出码 $($p.ExitCode))" }
Remove-Item $msi -Force -ErrorAction SilentlyContinue
Write-Ok "Node.js $ver 已安装,重启终端后可用 node"
} catch {
Write-Fail "自动安装失败: $($_.Exception.Message)"
Write-Host " 手动安装: https://nodejs.org (下载官方 MSI 双击安装)" -ForegroundColor Gray
exit 1
}
}
}
$projectDir = Get-Location
$opencodeJson = Join-Path $projectDir.Path "opencode.json"
$moaDir = Join-Path $projectDir.Path ".opencode"
# 1. 检查 .opencode 目录
Write-Step "1/3" "检查 .opencode/ 目录..."
if (Test-Path $moaDir) {
$agentCount = (Get-ChildItem "$moaDir/agents/*.md" -ErrorAction SilentlyContinue).Count
Write-Ok ".opencode/ 存在 ($agentCount agents)"
} else {
Write-Fail ".opencode/ 不存在"
Write-Host " 请先克隆仓库并复制 .opencode/ 到当前目录" -ForegroundColor Gray
Write-Host " git clone https://github.com/ZenHG/opencode-moa.git tmp" -ForegroundColor Gray
if ($IsWindows -or $env:OS -eq "Windows_NT") {
Write-Host " xcopy tmp\.opencode .\.opencode /E /I /Y" -ForegroundColor Gray
} else {
Write-Host " cp -r tmp/.opencode/ ." -ForegroundColor Gray
}
exit 1
}
# 1.5 检查 opencode CLI(缺失给指引,不阻断合并——配置可先行,CLI 后装)
Write-Step "1.5/3" "检查 opencode CLI..."
$oc = Get-Command opencode -ErrorAction SilentlyContinue
if ($oc) {
Write-Ok "opencode: $($oc.Source)"
} else {
Write-Host " ⚠ 未找到 opencode CLI —— MoA 流水线与 LongLoop 都依赖它驱动每轮会话。" -ForegroundColor Yellow
Write-Host " 安装 V2:curl -fsSL https://opencode.ai/v2/install | bash(Windows 用 Git Bash;官方不支持 Windows 包管理器),装后把 ~/.opencode/bin 加入 PATH" -ForegroundColor Cyan
Write-Host " 装好后若仍找不到,设置环境变量 OPENCODE_BIN 指向 opencode 可执行文件。" -ForegroundColor Gray
}
# 2. 合并 opencode.json
Write-Step "2/3" "合并 opencode.json..."
$moaConfig = @'
{
"$schema": "https://opencode.ai/config.json",
"default_agent": "门童",
"experimental": {
"todo": true,
"subagent_depth": 2
},
"permissions": [
{ "action": "*", "resource": "*", "effect": "ask" },
{ "action": "shell", "resource": "*", "effect": "ask" },
{ "action": "moa-loop_*", "resource": "*", "effect": "allow" },
{ "action": "grep", "resource": "*", "effect": "allow" },
{ "action": "glob", "resource": "*", "effect": "allow" },
{ "action": "list", "resource": "*", "effect": "allow" },
{ "action": "shell", "resource": "git status *", "effect": "allow" },
{ "action": "shell", "resource": "git diff *", "effect": "allow" },
{ "action": "shell", "resource": "git log *", "effect": "allow" },
{ "action": "shell", "resource": "grep *", "effect": "allow" },
{ "action": "shell", "resource": "rg *", "effect": "allow" },
{ "action": "shell", "resource": "Select-String *", "effect": "allow" },
{ "action": "shell", "resource": "ls *", "effect": "allow" },
{ "action": "shell", "resource": "Get-ChildItem *", "effect": "allow" },
{ "action": "shell", "resource": "Get-Content *", "effect": "allow" },
{ "action": "shell", "resource": "cd *", "effect": "allow" },
{ "action": "shell", "resource": "npm run test *", "effect": "allow" },
{ "action": "shell", "resource": "npm run build *", "effect": "allow" },
{ "action": "shell", "resource": "pwsh .opencode/tests/*", "effect": "allow" },
{ "action": "shell", "resource": "rm *", "effect": "ask" },
{ "action": "shell", "resource": "del *", "effect": "ask" },
{ "action": "shell", "resource": "Remove-Item *", "effect": "ask" },
{ "action": "shell", "resource": "rd *", "effect": "ask" },
{ "action": "shell", "resource": "rmdir *", "effect": "ask" },
{ "action": "subagent", "resource": "*", "effect": "deny" },
{ "action": "subagent", "resource": "工具人", "effect": "allow" },
{ "action": "subagent", "resource": "工具人-mimo", "effect": "allow" },
{ "action": "subagent", "resource": "闪电侠", "effect": "allow" },
{ "action": "subagent", "resource": "视觉翻译", "effect": "allow" },
{ "action": "subagent", "resource": "中级·工程", "effect": "allow" },
{ "action": "subagent", "resource": "中级·创意", "effect": "allow" },
{ "action": "subagent", "resource": "中级·码农", "effect": "allow" },
{ "action": "subagent", "resource": "中级·融合", "effect": "allow" },
{ "action": "subagent", "resource": "旗舰·架构", "effect": "allow" },
{ "action": "subagent", "resource": "旗舰·规划", "effect": "allow" },
{ "action": "subagent", "resource": "旗舰·工程", "effect": "allow" },
{ "action": "subagent", "resource": "旗舰·融合", "effect": "allow" },
{ "action": "subagent", "resource": "旗舰·执行", "effect": "allow" },
{ "action": "subagent", "resource": "旗舰·质检", "effect": "allow" },
{ "action": "subagent", "resource": "前端·还原", "effect": "allow" },
{ "action": "subagent", "resource": "前端·逻辑", "effect": "allow" },
{ "action": "subagent", "resource": "前端·动效", "effect": "allow" },
{ "action": "subagent", "resource": "前端·总工", "effect": "allow" },
{ "action": "subagent", "resource": "融合·保底", "effect": "allow" },
{ "action": "subagent", "resource": "残差提取", "effect": "allow" },
{ "action": "webfetch", "resource": "*", "effect": "allow" },
{ "action": "read", "resource": "*", "effect": "allow" },
{ "action": "read", "resource": "*.env", "effect": "deny" },
{ "action": "read", "resource": "*.env.*", "effect": "deny" },
{ "action": "read", "resource": "*.env.example", "effect": "allow" },
{ "action": "external_directory", "resource": "*", "effect": "ask" },
{ "action": "shell", "resource": "Get-Content *.env*", "effect": "deny" },
{ "action": "shell", "resource": "Select-String *env*", "effect": "deny" },
{ "action": "shell", "resource": "type *.env*", "effect": "deny" },
{ "action": "shell", "resource": "pwsh *..*", "effect": "deny" },
{ "action": "shell", "resource": "rg *--pre*", "effect": "deny" },
{ "action": "shell", "resource": "git push *", "effect": "deny" }, { "action": "shell", "resource": "git reset --hard *", "effect": "deny" },
{ "action": "shell", "resource": "git clean -*", "effect": "deny" },
{ "action": "shell", "resource": "rm -rf *", "effect": "deny" },
{ "action": "shell", "resource": "rm -fr *", "effect": "deny" },
{ "action": "shell", "resource": "format *", "effect": "deny" },
{ "action": "shell", "resource": "shutdown *", "effect": "deny" }
],
"agents": {
"中级·工程": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"中级·创意": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"中级·码农": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"中级·融合": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"旗舰·架构": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"旗舰·规划": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"旗舰·工程": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"旗舰·融合": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"旗舰·执行": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "moa-loop_*", "resource": "*", "effect": "allow" }
]
},
"旗舰·质检": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "git status *", "effect": "allow" },
{ "action": "shell", "resource": "git diff *", "effect": "allow" },
{ "action": "shell", "resource": "git log *", "effect": "allow" },
{ "action": "shell", "resource": "grep *", "effect": "allow" },
{ "action": "shell", "resource": "rg *", "effect": "allow" },
{ "action": "shell", "resource": "Select-String *", "effect": "allow" },
{ "action": "shell", "resource": "ls *", "effect": "allow" },
{ "action": "shell", "resource": "Get-ChildItem *", "effect": "allow" },
{ "action": "shell", "resource": "Get-Content *", "effect": "allow" },
{ "action": "shell", "resource": "node --check *", "effect": "allow" },
{ "action": "shell", "resource": "pwsh .opencode/tests/*", "effect": "allow" },
{ "action": "subagent", "resource": "工具人", "effect": "allow" }
]
},
"前端·逻辑": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"前端·动效": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"前端·总工": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"融合·保底": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
"残差提取": {
"permissions": [
{ "action": "*_*", "resource": "*", "effect": "deny" },
{ "action": "read", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "grep", "resource": "*", "effect": "deny" },
{ "action": "glob", "resource": "*", "effect": "deny" },
{ "action": "list", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
{ "action": "websearch", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" }
]
},
},
"compaction": {
"auto": true,
"buffer": 15000
},
"mcp": {
"servers": {
"moa-loop": {
"type": "local",
"command": ["node", "longloop/server.js"],
"disabled": false,
"protocol": "legacy"
}
}
},
"share": "manual",
"snapshots": true,
"providers": {
"opencode-go": {
"models": {
"deepseek-v4.1-flash": {
"name": "DeepSeek V4.1 Flash 1017",
"limit": { "context": 1000000, "output": 384000 },
"capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"], "temperature": true },
"variants": [
{ "id": "t0.1-high", "settings": { "temperature": 0.1, "reasoningEffort": "high" } },
{ "id": "t0.2-high", "settings": { "temperature": 0.2, "reasoningEffort": "high" } },
{ "id": "t0.2-max", "settings": { "temperature": 0.2, "reasoningEffort": "max" } },
{ "id": "t0.3-high", "settings": { "temperature": 0.3, "reasoningEffort": "high" } },
{ "id": "t0.3-max", "settings": { "temperature": 0.3, "reasoningEffort": "max" } },
{ "id": "t0.4-max", "settings": { "temperature": 0.4, "reasoningEffort": "max" } },
{ "id": "t0.5-max", "settings": { "temperature": 0.5, "reasoningEffort": "max" } }
]
},
"deepseek-v4-pro": {
"name": "DeepSeek V4 Pro",
"limit": { "context": 1000000, "output": 384000 },
"capabilities": { "tools": true, "input": ["text"], "output": ["text"], "temperature": true },
"variants": [
{ "id": "t0.2-max", "settings": { "temperature": 0.2, "reasoningEffort": "max" } },
{ "id": "t0.3-max", "settings": { "temperature": 0.3, "reasoningEffort": "max" } }
]
},
"kimi-k3.1-pro": {
"name": "Kimi K3.1 Pro",
"limit": { "context": 1048576, "output": 1048576 },
"capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"], "temperature": false },
"variants": [
{ "id": "high", "settings": { "reasoningEffort": "high" } }
]
},
"mimo-v2.6-flash": {
"name": "MiMo-V2.6-Flash",
"limit": { "context": 1048576, "output": 131072 },
"capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"], "temperature": true },
"variants": [
{ "id": "t0.1", "settings": { "temperature": 0.1 } }
]
},
"mimo-v2.6-pro": {
"name": "MiMo-V2.6-Pro",
"limit": { "context": 1048576, "output": 131072 },
"capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"], "temperature": true },
"variants": [
{ "id": "t0.5", "settings": { "temperature": 0.5 } }
]
},
"qwen3.7-plus": {
"name": "Qwen3.7 Plus",
"limit": { "context": 1000000, "output": 65536 },
"capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"], "temperature": true },
"variants": [
{ "id": "t0.2", "settings": { "temperature": 0.2 } },
{ "id": "t0.3", "settings": { "temperature": 0.3 } },
{ "id": "t0.4", "settings": { "temperature": 0.4 } },
{ "id": "t0.5", "settings": { "temperature": 0.5 } }
]
},
"qwen3.8-max": {
"name": "Qwen3.8 Max",
"limit": { "context": 1000000, "output": 131072 },
"capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"], "temperature": true },
"variants": [
{ "id": "t0.4-xhigh", "settings": { "temperature": 0.4, "reasoningEffort": "xhigh" } }
]
}
}
}
}
}
'@ | ConvertFrom-Json
# 平台化:Unix 部署移除 Windows 专有删除禁令,保持生成的 opencode.json 平台纯净
if (-not ($IsWindows -or $env:OS -eq "Windows_NT")) {
$denyRes = @("del *", "Remove-Item *", "rd *", "rmdir *")
$moaConfig.permissions = @($moaConfig.permissions | Where-Object { $_.resource -notin $denyRes })
}
if (Test-Path $opencodeJson) {
Write-Skip "已有 opencode.json,执行增量合并"
try {
$existing = Get-Content $opencodeJson -Raw -Encoding UTF8 | ConvertFrom-Json
if ($existing.providers) {
$moaConfig | Add-Member -NotePropertyName "providers" -NotePropertyValue $existing.providers -Force
Write-Ok "保留 providers 配置"
}
if ($existing.model) {
$moaConfig | Add-Member -NotePropertyName "model" -NotePropertyValue $existing.model -Force
Write-Ok "保留 model 配置"
}
} catch {
Write-Host " ⚠ 无法解析现有配置,将创建新配置" -ForegroundColor Yellow
}
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$backup = "${opencodeJson}.bak.${timestamp}"
Copy-Item $opencodeJson $backup -Force
Write-Ok "已备份到 $(Split-Path $backup -Leaf)"
} else {
Write-Skip "opencode.json 不存在,创建新配置"
}
$moaConfig | ConvertTo-Json -Depth 10 | Set-Content $opencodeJson -Encoding UTF8
Write-Ok "opencode.json 已更新"
# 2.5 检查 opencode-go provider 凭据,缺失则提示输入 key
$needKey = $true
try {
$check = Get-Content $opencodeJson -Raw -Encoding UTF8 | ConvertFrom-Json
if ($check.providers.'opencode-go'.settings.apiKey) { $needKey = $false }
} catch {}
if ($needKey) {
Write-Host "`n⚠️ 未检测到 opencode-go 凭据。21 个 agent 全部使用 opencode-go/<model>,需要 Go API Key。" -ForegroundColor Yellow
Write-Host " 可以在 opencode.ai/auth 创建后输入(非交互环境直接跳过)。" -ForegroundColor Gray
try { $apiKey = Read-Host "`n请输入你的 OpenCode Go API Key(留空写占位符)" } catch { $apiKey = "" }
if (-not $apiKey) { $apiKey = "<YOUR_GO_API_KEY>" }
$merged = Get-Content $opencodeJson -Raw -Encoding UTF8 | ConvertFrom-Json
if (-not $merged.providers) { $merged | Add-Member -NotePropertyName 'providers' -NotePropertyValue @{} -Force }
if ($merged.providers -is [hashtable]) { $merged.providers = [pscustomobject]$merged.providers }
$goProvider = [pscustomobject]@{
settings = [pscustomobject]@{ baseURL = "https://opencode.ai/zen/go/v1"; apiKey = $apiKey }
}
if ($merged.providers.'opencode-go') {
$merged.providers.'opencode-go' | Add-Member -NotePropertyName 'settings' -NotePropertyValue $goProvider.settings -Force
} else {
$merged.providers | Add-Member -NotePropertyName 'opencode-go' -NotePropertyValue $goProvider -Force
}
$merged | ConvertTo-Json -Depth 10 | Set-Content $opencodeJson -Encoding UTF8
if ($apiKey -eq "<YOUR_GO_API_KEY>") {
Write-Host " 已写入占位符 key -> 请编辑 opencode.json 的 providers.opencode-go.settings.apiKey,再重启 OpenCode。" -ForegroundColor Yellow
} else {
Write-Ok "opencode-go 凭据已配置"
}
}
# 3. 验证
Write-Step "3/3" "验证部署..."
$agentFiles = Get-ChildItem "$moaDir/agents/*.md" -ErrorAction SilentlyContinue
$cmdFiles = Get-ChildItem "$moaDir/commands/*.md" -ErrorAction SilentlyContinue
$skillFiles = Get-ChildItem "$moaDir/skills/*/SKILL.md" -ErrorAction SilentlyContinue
$agentCount = if ($agentFiles) { $agentFiles.Count } else { 0 }
$cmdCount = if ($cmdFiles) { $cmdFiles.Count } else { 0 }
$skillCount = if ($skillFiles) { $skillFiles.Count } else { 0 }
if ($agentCount -gt 0) { Write-Ok "Agents: $agentCount" } else { Write-Fail "Agents: $agentCount" }
if ($cmdCount -gt 0) { Write-Ok "Commands: $cmdCount" } else { Write-Fail "Commands: $cmdCount" }
if ($skillCount -gt 0) { Write-Ok "Skills: $skillCount" } else { Write-Fail "Skills: $skillCount" }
Write-Ok "Config: ok"
$nodeVer = node --version 2>$null
if ($nodeVer) {
try {
$nodeMajor = [int](($nodeVer.TrimStart('v') -split '\.')[0])
if ($nodeMajor -ge 14) { Write-Ok "Node.js: ok ($nodeVer)" }
else { Write-Host " ⚠ node $nodeVer < 14 —— moa-loop MCP 需要 >= 14;可加 -InstallNode 自动升级官方 MSI" -ForegroundColor Yellow }
} catch { Write-Host " ⚠ node 版本解析失败($nodeVer)" -ForegroundColor Yellow }
} else {
Write-Host " ⚠ node 未安装 —— moa-loop MCP(长程自完善状态工具)不可用;可加 -InstallNode 自动安装官方 MSI" -ForegroundColor Yellow
}
if (Test-Path (Join-Path $projectDir.Path "longloop/server.js")) {
Write-Ok "LongLoop MCP: ok"
} else {
Write-Host " ⚠ longloop/ 未复制 —— moa-loop MCP(长程自完善状态工具)将不可用" -ForegroundColor Yellow
Write-Host " -> 从仓库复制: cp -r <opencode-moa 路径>/longloop/ ." -ForegroundColor Gray
}
Write-Host "`n=== 安装完成 ===" -ForegroundColor Cyan
Write-Host "重启 OpenCode 使配置生效。" -ForegroundColor Yellow
Write-Host "按 Tab 循环切换 agent(Win 桌面端亦可用 Ctrl+.)切换到「门童」开始使用。" -ForegroundColor Yellow