deploy-to-openclaw.ps1 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # OpenClaw Skill Deploy Script v1.3.0
  2. # Flatten 41 skills into ~/.openclaw/skills/
  3. # 批量将voc技能部署在龙虾skills目录下脚本
  4. # 需要将.openclaw的路径更换后使用
  5. # Usage:
  6. # .\deploy-to-openclaw.ps1 -DryRun # Preview only
  7. # .\deploy-to-openclaw.ps1 # Actual deploy
  8. # .\deploy-to-openclaw.ps1 -SkillsRoot "D:\custom\skills"
  9. param(
  10. [string]$SkillsRoot = "$env:USERPROFILE\.openclaw\skills",
  11. [string]$SourceRoot = $PSScriptRoot,
  12. [switch]$DryRun
  13. )
  14. $ErrorActionPreference = "Stop"
  15. $categories = @(
  16. "voc",
  17. "social-media",
  18. "competitor-analysis",
  19. "review-analysis",
  20. "synthesis",
  21. "social-voc",
  22. "douyin",
  23. "video-creation"
  24. )
  25. Write-Host "========================================"
  26. Write-Host " OpenClaw Skill Deploy v1.3.0"
  27. Write-Host "========================================"
  28. Write-Host ""
  29. Write-Host "Source: $SourceRoot"
  30. Write-Host "Target: $SkillsRoot"
  31. if ($DryRun) { Write-Host "[DRY RUN] Preview only, no files copied" -ForegroundColor Yellow }
  32. Write-Host ""
  33. if (-not $DryRun) {
  34. if (-not (Test-Path $SkillsRoot)) {
  35. New-Item -ItemType Directory -Path $SkillsRoot -Force | Out-Null
  36. Write-Host "Created target dir: $SkillsRoot" -ForegroundColor Green
  37. }
  38. }
  39. $deployed = 0
  40. $skipped = 0
  41. $errors = 0
  42. foreach ($cat in $categories) {
  43. $catPath = Join-Path $SourceRoot $cat
  44. if (-not (Test-Path $catPath)) {
  45. Write-Host "SKIP category (not found): $cat" -ForegroundColor DarkGray
  46. continue
  47. }
  48. Write-Host "--- $cat ---" -ForegroundColor Cyan
  49. $skillDirs = Get-ChildItem -Directory -Path $catPath
  50. foreach ($skillDir in $skillDirs) {
  51. $skillName = $skillDir.Name
  52. $skillMd = Join-Path $skillDir.FullName "SKILL.md"
  53. $apiConfig = Join-Path $skillDir.FullName "api-config.json"
  54. if (-not (Test-Path $skillMd)) {
  55. Write-Host " [SKIP] $skillName - missing SKILL.md" -ForegroundColor DarkYellow
  56. $skipped++
  57. continue
  58. }
  59. if (-not (Test-Path $apiConfig)) {
  60. Write-Host " [SKIP] $skillName - missing api-config.json" -ForegroundColor DarkYellow
  61. $skipped++
  62. continue
  63. }
  64. $mdContent = Get-Content $skillMd -Raw -Encoding UTF8
  65. if ($mdContent -notmatch "^---\s*\r?\n") {
  66. Write-Host " [WARN] $skillName - SKILL.md missing YAML frontmatter" -ForegroundColor Yellow
  67. }
  68. try {
  69. $null = Get-Content $apiConfig -Raw -Encoding UTF8 | ConvertFrom-Json
  70. } catch {
  71. Write-Host " [ERROR] $skillName - invalid JSON in api-config.json" -ForegroundColor Red
  72. $errors++
  73. continue
  74. }
  75. $destDir = Join-Path $SkillsRoot $skillName
  76. if ($DryRun) {
  77. $tag = if (Test-Path $destDir) { "UPDATE" } else { "NEW" }
  78. Write-Host " [$tag] $skillName" -ForegroundColor White
  79. } else {
  80. if (Test-Path $destDir) {
  81. Remove-Item -Recurse -Force $destDir
  82. }
  83. New-Item -ItemType Directory -Path $destDir -Force | Out-Null
  84. Get-ChildItem -File -Path $skillDir.FullName | ForEach-Object {
  85. Copy-Item $_.FullName -Destination $destDir
  86. }
  87. Write-Host " [OK] $skillName" -ForegroundColor Green
  88. }
  89. $deployed++
  90. }
  91. }
  92. Write-Host ""
  93. Write-Host "========================================"
  94. Write-Host " Result: $deployed deployed, $skipped skipped, $errors errors"
  95. Write-Host "========================================"
  96. if ($DryRun) {
  97. Write-Host "Remove -DryRun to execute actual deployment." -ForegroundColor Yellow
  98. } else {
  99. # 复制凭证模板(不覆盖已有凭证文件)
  100. $credTemplate = Join-Path $SourceRoot "__config\voc-credentials.template.json"
  101. $credTarget = Join-Path (Split-Path $SkillsRoot -Parent) "voc-credentials.template.json"
  102. $credFile = Join-Path (Split-Path $SkillsRoot -Parent) "voc-credentials.json"
  103. if (Test-Path $credTemplate) {
  104. Copy-Item $credTemplate -Destination $credTarget -Force
  105. Write-Host ""
  106. Write-Host "Credentials template: $credTarget" -ForegroundColor Cyan
  107. if (-not (Test-Path $credFile)) {
  108. Write-Host " → No voc-credentials.json found. Copy template and fill in vocToken to enable per-user tokens." -ForegroundColor Yellow
  109. } else {
  110. Write-Host " → voc-credentials.json already exists, not overwritten." -ForegroundColor Green
  111. }
  112. }
  113. Write-Host ""
  114. Write-Host "Done! Refresh OpenClaw skill list to verify." -ForegroundColor Green
  115. Write-Host " openclaw skills list"
  116. }