param( [string]$SkillsRoot, [string]$SourceRoot = $PSScriptRoot, [switch]$DryRun ) $ErrorActionPreference = "Stop" # Cross-platform home dir: $HOME works on Windows PowerShell 5+ and PowerShell 7 (Linux/Mac) if (-not $SkillsRoot) { $SkillsRoot = Join-Path (Join-Path $HOME ".openclaw") "skills" } $categories = @("wechat") Write-Host "=== OpenClaw WeChat Skill Deploy v1.2.0 ===" Write-Host "Source: $SourceRoot" Write-Host "Target: $SkillsRoot" if ($DryRun) { Write-Host "[DRY RUN]" -ForegroundColor Yellow } if (-not $DryRun -and -not (Test-Path $SkillsRoot)) { New-Item -ItemType Directory -Path $SkillsRoot -Force | Out-Null } $deployed = 0; $skipped = 0; $errors = 0 foreach ($cat in $categories) { $catPath = Join-Path $SourceRoot $cat if (-not (Test-Path $catPath)) { continue } Write-Host "--- $cat ---" -ForegroundColor Cyan foreach ($skillDir in (Get-ChildItem -Directory -Path $catPath)) { $n = $skillDir.Name $sm = Join-Path $skillDir.FullName "SKILL.md" $ac = Join-Path $skillDir.FullName "api-config.json" if (-not (Test-Path $sm)) { $skipped++; continue } # api-config.json is optional reference material in v1.1.0+ if (Test-Path $ac) { try { $null = Get-Content $ac -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $errors++; continue } } $dest = Join-Path $SkillsRoot $n if ($DryRun) { if (Test-Path $dest) { $tag = 'UPDATE' } else { $tag = 'NEW' } Write-Host " [$tag] $n" } else { if (Test-Path $dest) { Remove-Item -Recurse -Force $dest } New-Item -ItemType Directory -Path $dest -Force | Out-Null Get-ChildItem -File -Path $skillDir.FullName | ForEach-Object { Copy-Item $_.FullName -Destination $dest } Write-Host " [OK] $n" -ForegroundColor Green } $deployed++ } } Write-Host "Result: $deployed deployed, $skipped skipped, $errors errors" # Deploy workflows $wfSource = Join-Path $SourceRoot "workflows" $wfTarget = Join-Path (Split-Path $SkillsRoot -Parent) "workflows" if (Test-Path $wfSource) { Write-Host "--- workflows ---" -ForegroundColor Cyan if (-not $DryRun) { if (-not (Test-Path $wfTarget)) { New-Item -ItemType Directory -Path $wfTarget -Force | Out-Null } Get-ChildItem -File -Path $wfSource | ForEach-Object { Copy-Item $_.FullName -Destination $wfTarget -Force Write-Host " [OK] $($_.Name)" -ForegroundColor Green } } else { Get-ChildItem -File -Path $wfSource | ForEach-Object { Write-Host " [WORKFLOW] $($_.Name)" } } } $openclawDir = Split-Path $SkillsRoot -Parent if (-not $DryRun) { # Copy credentials template $tpl = Join-Path (Join-Path $SourceRoot "__config") "wechat-credentials.template.json" $dst = Join-Path $openclawDir "wechat-credentials.template.json" if (Test-Path $tpl) { Copy-Item $tpl -Destination $dst -Force; Write-Host "Template: $dst" } # Create default credentials if not exists $credFile = Join-Path $openclawDir "wechat-credentials.json" if (-not (Test-Path $credFile)) { Copy-Item $tpl -Destination $credFile -Force Write-Host "[!] Created $credFile - please edit wechatApiBase to your server address" -ForegroundColor Yellow } } # ---- Auto-reply daemon + config ---- $daemonSrc = Join-Path (Join-Path $SourceRoot "daemon") "auto-reply-daemon.js" $daemonDst = Join-Path $openclawDir "auto-reply-daemon.js" $cfgTplSrc = Join-Path (Join-Path $SourceRoot "daemon") "wechat-auto-reply-config.template.json" $cfgTplDst = Join-Path $openclawDir "wechat-auto-reply-config.template.json" $cfgDst = Join-Path $openclawDir "wechat-auto-reply-config.json" if (Test-Path $daemonSrc) { Write-Host "--- auto-reply daemon ---" -ForegroundColor Cyan if ($DryRun) { Write-Host " [DAEMON] $daemonDst" Write-Host " [CONFIG-TEMPLATE] $cfgTplDst" if (-not (Test-Path $cfgDst)) { Write-Host " [CONFIG-DEFAULT] $cfgDst" } } else { Copy-Item $daemonSrc -Destination $daemonDst -Force Write-Host " [OK] $daemonDst" -ForegroundColor Green if (Test-Path $cfgTplSrc) { Copy-Item $cfgTplSrc -Destination $cfgTplDst -Force Write-Host " [OK] $cfgTplDst" -ForegroundColor Green if (-not (Test-Path $cfgDst)) { Copy-Item $cfgTplSrc -Destination $cfgDst -Force Write-Host " [!] Created default config: $cfgDst (edit to customize reply rules)" -ForegroundColor Yellow } } } } if (-not $DryRun) { Write-Host "Done!" -ForegroundColor Green }