deploy-to-openclaw.ps1 4.6 KB

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