deploy-to-openclaw.ps1 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. "jimeng",
  25. "test"
  26. )
  27. Write-Host "========================================"
  28. Write-Host " OpenClaw Skill Deploy v1.3.0"
  29. Write-Host "========================================"
  30. Write-Host ""
  31. Write-Host "Source: $SourceRoot"
  32. Write-Host "Target: $SkillsRoot"
  33. if ($DryRun) { Write-Host "[DRY RUN] Preview only, no files copied" -ForegroundColor Yellow }
  34. Write-Host ""
  35. if (-not $DryRun) {
  36. if (-not (Test-Path $SkillsRoot)) {
  37. New-Item -ItemType Directory -Path $SkillsRoot -Force | Out-Null
  38. Write-Host "Created target dir: $SkillsRoot" -ForegroundColor Green
  39. }
  40. }
  41. $deployed = 0
  42. $skipped = 0
  43. $errors = 0
  44. foreach ($cat in $categories) {
  45. $catPath = Join-Path $SourceRoot $cat
  46. if (-not (Test-Path $catPath)) {
  47. Write-Host "SKIP category (not found): $cat" -ForegroundColor DarkGray
  48. continue
  49. }
  50. Write-Host "--- $cat ---" -ForegroundColor Cyan
  51. $skillDirs = Get-ChildItem -Directory -Path $catPath
  52. foreach ($skillDir in $skillDirs) {
  53. $skillName = $skillDir.Name
  54. $skillMd = Join-Path $skillDir.FullName "SKILL.md"
  55. $apiConfig = Join-Path $skillDir.FullName "api-config.json"
  56. if (-not (Test-Path $skillMd)) {
  57. Write-Host " [SKIP] $skillName - missing SKILL.md" -ForegroundColor DarkYellow
  58. $skipped++
  59. continue
  60. }
  61. if (-not (Test-Path $apiConfig)) {
  62. Write-Host " [SKIP] $skillName - missing api-config.json" -ForegroundColor DarkYellow
  63. $skipped++
  64. continue
  65. }
  66. $mdContent = Get-Content $skillMd -Raw -Encoding UTF8
  67. if ($mdContent -notmatch "^---\s*\r?\n") {
  68. Write-Host " [WARN] $skillName - SKILL.md missing YAML frontmatter" -ForegroundColor Yellow
  69. }
  70. try {
  71. $null = Get-Content $apiConfig -Raw -Encoding UTF8 | ConvertFrom-Json
  72. } catch {
  73. Write-Host " [ERROR] $skillName - invalid JSON in api-config.json" -ForegroundColor Red
  74. $errors++
  75. continue
  76. }
  77. $destDir = Join-Path $SkillsRoot $skillName
  78. if ($DryRun) {
  79. $tag = if (Test-Path $destDir) { "UPDATE" } else { "NEW" }
  80. Write-Host " [$tag] $skillName" -ForegroundColor White
  81. } else {
  82. if (Test-Path $destDir) {
  83. Remove-Item -Recurse -Force $destDir
  84. }
  85. New-Item -ItemType Directory -Path $destDir -Force | Out-Null
  86. Get-ChildItem -File -Path $skillDir.FullName | ForEach-Object {
  87. Copy-Item $_.FullName -Destination $destDir
  88. }
  89. Write-Host " [OK] $skillName" -ForegroundColor Green
  90. }
  91. $deployed++
  92. }
  93. }
  94. Write-Host ""
  95. Write-Host "========================================"
  96. Write-Host " Result: $deployed deployed, $skipped skipped, $errors errors"
  97. Write-Host "========================================"
  98. if ($DryRun) {
  99. Write-Host "Remove -DryRun to execute actual deployment." -ForegroundColor Yellow
  100. } else {
  101. # 复制凭证模板(不覆盖已有凭证文件)
  102. $credTemplate = Join-Path $SourceRoot "__config\voc-credentials.template.json"
  103. $credTarget = Join-Path (Split-Path $SkillsRoot -Parent) "voc-credentials.template.json"
  104. $credFile = Join-Path (Split-Path $SkillsRoot -Parent) "voc-credentials.json"
  105. if (Test-Path $credTemplate) {
  106. Copy-Item $credTemplate -Destination $credTarget -Force
  107. Write-Host ""
  108. Write-Host "Credentials template: $credTarget" -ForegroundColor Cyan
  109. if (-not (Test-Path $credFile)) {
  110. Write-Host " → No voc-credentials.json found. Copy template and fill in vocToken to enable per-user tokens." -ForegroundColor Yellow
  111. } else {
  112. Write-Host " → voc-credentials.json already exists, not overwritten." -ForegroundColor Green
  113. }
  114. }
  115. Write-Host ""
  116. Write-Host "Done! Refresh OpenClaw skill list to verify." -ForegroundColor Green
  117. Write-Host " openclaw skills list"
  118. }