deploy-to-openclaw.ps1 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. # OpenClaw VOC Skills Deploy Script v2.0.0
  2. #
  3. # Deploys skills, workshop playbook, and memory templates to OpenClaw
  4. #
  5. # Usage:
  6. # .\deploy-to-openclaw.ps1 # Deploy everything
  7. # .\deploy-to-openclaw.ps1 -DryRun # Preview only
  8. # .\deploy-to-openclaw.ps1 -SkillsOnly # Deploy skills only
  9. # .\deploy-to-openclaw.ps1 -WorkshopOnly # Deploy workshop only
  10. # .\deploy-to-openclaw.ps1 -OpenClawDir "D:\path" # Custom OpenClaw directory
  11. param(
  12. [string]$OpenClawDir = "$env:USERPROFILE\.openclaw",
  13. [string]$ProjectRoot = (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent),
  14. [switch]$SkillsOnly,
  15. [switch]$WorkshopOnly,
  16. [switch]$DryRun
  17. )
  18. $ErrorActionPreference = "Stop"
  19. $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
  20. # ============================================
  21. # Paths
  22. # ============================================
  23. $SkillsTarget = Join-Path $OpenClawDir "skills"
  24. $WorkspaceTarget = Join-Path $OpenClawDir "workspace"
  25. $MemoryTarget = Join-Path $WorkspaceTarget "memory"
  26. $SkillCategories = @(
  27. "voc",
  28. "social-media",
  29. "competitor-analysis",
  30. "review-analysis",
  31. "synthesis",
  32. "social-voc",
  33. "douyin",
  34. "video-creation",
  35. "jimeng",
  36. "payment",
  37. "test"
  38. )
  39. # ============================================
  40. # Helper Functions
  41. # ============================================
  42. function Remove-Bom {
  43. param([string]$FilePath)
  44. $bytes = [System.IO.File]::ReadAllBytes($FilePath)
  45. if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
  46. $clean = $bytes[3..($bytes.Length - 1)]
  47. [System.IO.File]::WriteAllBytes($FilePath, $clean)
  48. return $true
  49. }
  50. return $false
  51. }
  52. function Test-SkillValid {
  53. param([string]$SkillDir, [string]$SkillName)
  54. $skillMd = Join-Path $SkillDir "SKILL.md"
  55. $apiConf = Join-Path $SkillDir "api-config.json"
  56. if (-not (Test-Path $skillMd)) {
  57. Write-Host " [SKIP] $SkillName - missing SKILL.md" -ForegroundColor DarkGray
  58. return $false
  59. }
  60. # Validate YAML frontmatter
  61. $mdContent = [System.IO.File]::ReadAllText($skillMd, [System.Text.Encoding]::UTF8)
  62. if ($mdContent -notmatch "^---\s*\r?\n") {
  63. Write-Host " [WARN] $SkillName - SKILL.md missing YAML frontmatter" -ForegroundColor Yellow
  64. }
  65. # Validate api-config.json if exists
  66. if (Test-Path $apiConf) {
  67. try {
  68. $null = Get-Content $apiConf -Raw -Encoding UTF8 | ConvertFrom-Json
  69. } catch {
  70. Write-Host " [ERROR] $SkillName - invalid JSON in api-config.json" -ForegroundColor Red
  71. return $false
  72. }
  73. }
  74. return $true
  75. }
  76. function Deploy-File {
  77. param([string]$Source, [string]$Dest, [string]$Label)
  78. if ($DryRun) {
  79. $tag = if (Test-Path $Dest) { "UPDATE" } else { "NEW" }
  80. Write-Host " [$tag] $Label" -ForegroundColor White
  81. } else {
  82. $destDir = Split-Path $Dest -Parent
  83. if (-not (Test-Path $destDir)) {
  84. New-Item -ItemType Directory -Path $destDir -Force | Out-Null
  85. }
  86. Copy-Item $Source -Destination $Dest -Force
  87. }
  88. }
  89. # ============================================
  90. # Banner
  91. # ============================================
  92. Write-Host ""
  93. Write-Host " ====================================================" -ForegroundColor Cyan
  94. Write-Host " OpenClaw VOC Skills Deploy v2.0.0" -ForegroundColor Cyan
  95. Write-Host " ====================================================" -ForegroundColor Cyan
  96. Write-Host ""
  97. Write-Host " Project: $ProjectRoot"
  98. Write-Host " OpenClaw: $OpenClawDir"
  99. if ($DryRun) { Write-Host " Mode: DRY RUN (preview only)" -ForegroundColor Yellow }
  100. if ($SkillsOnly) { Write-Host " Scope: Skills only" -ForegroundColor Yellow }
  101. if ($WorkshopOnly) { Write-Host " Scope: Workshop only" -ForegroundColor Yellow }
  102. Write-Host ""
  103. # Pre-flight check
  104. if (-not (Test-Path $OpenClawDir)) {
  105. Write-Host " [ERROR] OpenClaw directory not found: $OpenClawDir" -ForegroundColor Red
  106. Write-Host " Is OpenClaw installed? Specify -OpenClawDir to override." -ForegroundColor Yellow
  107. exit 1
  108. }
  109. $totalDeployed = 0
  110. $totalSkipped = 0
  111. $totalErrors = 0
  112. $bomFixed = 0
  113. # ============================================
  114. # Part 1: Deploy Skills
  115. # ============================================
  116. if (-not $WorkshopOnly) {
  117. Write-Host " [1/3] Deploying Skills" -ForegroundColor Cyan
  118. Write-Host " $('-' * 48)"
  119. if (-not $DryRun -and -not (Test-Path $SkillsTarget)) {
  120. New-Item -ItemType Directory -Path $SkillsTarget -Force | Out-Null
  121. }
  122. foreach ($cat in $SkillCategories) {
  123. $catPath = Join-Path $ProjectRoot $cat
  124. if (-not (Test-Path $catPath)) { continue }
  125. $skillDirs = Get-ChildItem -Directory -Path $catPath -ErrorAction SilentlyContinue
  126. if ($null -eq $skillDirs -or $skillDirs.Count -eq 0) { continue }
  127. Write-Host " [$cat]" -ForegroundColor DarkCyan
  128. foreach ($skillDir in $skillDirs) {
  129. $skillName = $skillDir.Name
  130. if (-not (Test-SkillValid $skillDir.FullName $skillName)) {
  131. $totalSkipped++
  132. continue
  133. }
  134. $destDir = Join-Path $SkillsTarget $skillName
  135. if ($DryRun) {
  136. $tag = if (Test-Path $destDir) { "UPDATE" } else { "NEW" }
  137. Write-Host " [$tag] $skillName" -ForegroundColor White
  138. } else {
  139. if (Test-Path $destDir) {
  140. Remove-Item -Recurse -Force $destDir
  141. }
  142. New-Item -ItemType Directory -Path $destDir -Force | Out-Null
  143. Get-ChildItem -File -Path $skillDir.FullName | ForEach-Object {
  144. Copy-Item $_.FullName -Destination $destDir
  145. }
  146. # Fix UTF-8 BOM in SKILL.md (causes OpenClaw parsing failures)
  147. $deployedMd = Join-Path $destDir "SKILL.md"
  148. if (Test-Path $deployedMd) {
  149. if (Remove-Bom $deployedMd) {
  150. $bomFixed++
  151. }
  152. }
  153. Write-Host " [OK] $skillName" -ForegroundColor Green
  154. }
  155. $totalDeployed++
  156. }
  157. }
  158. # Also deploy workshop skills (e.g. brand-context-builder)
  159. $workshopSkillsPath = Join-Path $ProjectRoot "workshop"
  160. if (Test-Path $workshopSkillsPath) {
  161. $wsSkills = Get-ChildItem -Directory -Path $workshopSkillsPath | Where-Object {
  162. Test-Path (Join-Path $_.FullName "SKILL.md")
  163. }
  164. if ($wsSkills.Count -gt 0) {
  165. Write-Host " [workshop skills]" -ForegroundColor DarkCyan
  166. foreach ($ws in $wsSkills) {
  167. $skillName = $ws.Name
  168. $destDir = Join-Path $SkillsTarget $skillName
  169. if ($DryRun) {
  170. $tag = if (Test-Path $destDir) { "UPDATE" } else { "NEW" }
  171. Write-Host " [$tag] $skillName" -ForegroundColor White
  172. } else {
  173. if (Test-Path $destDir) { Remove-Item -Recurse -Force $destDir }
  174. New-Item -ItemType Directory -Path $destDir -Force | Out-Null
  175. Get-ChildItem -File -Path $ws.FullName | ForEach-Object {
  176. Copy-Item $_.FullName -Destination $destDir
  177. }
  178. $deployedMd = Join-Path $destDir "SKILL.md"
  179. if (Test-Path $deployedMd) { if (Remove-Bom $deployedMd) { $bomFixed++ } }
  180. Write-Host " [OK] $skillName" -ForegroundColor Green
  181. }
  182. $totalDeployed++
  183. }
  184. }
  185. }
  186. Write-Host ""
  187. }
  188. # ============================================
  189. # Part 2: Deploy Workshop Playbook
  190. # ============================================
  191. if (-not $SkillsOnly) {
  192. Write-Host " [2/3] Deploying Workshop Playbook" -ForegroundColor Cyan
  193. Write-Host " $('-' * 48)"
  194. $playbookSrc = Join-Path $ProjectRoot "workshop\workshop-voc-playbook.md"
  195. if (Test-Path $playbookSrc) {
  196. $playbookDest = Join-Path $WorkspaceTarget "workshop-voc-playbook.md"
  197. Deploy-File $playbookSrc $playbookDest "workshop-voc-playbook.md"
  198. if (-not $DryRun) { Write-Host " [OK] workshop-voc-playbook.md" -ForegroundColor Green }
  199. $totalDeployed++
  200. } else {
  201. Write-Host " [SKIP] workshop-voc-playbook.md not found" -ForegroundColor DarkGray
  202. }
  203. Write-Host ""
  204. }
  205. # ============================================
  206. # Part 3: Deploy Memory Templates
  207. # ============================================
  208. if (-not $SkillsOnly) {
  209. Write-Host " [3/3] Deploying Memory Templates" -ForegroundColor Cyan
  210. Write-Host " $('-' * 48)"
  211. $memSrc = Join-Path $ProjectRoot "workshop\memory-templates"
  212. if (Test-Path $memSrc) {
  213. if (-not $DryRun -and -not (Test-Path $MemoryTarget)) {
  214. New-Item -ItemType Directory -Path $MemoryTarget -Force | Out-Null
  215. }
  216. Get-ChildItem -File -Path $memSrc -Filter "*.json" | ForEach-Object {
  217. $dest = Join-Path $MemoryTarget $_.Name
  218. Deploy-File $_.FullName $dest $_.Name
  219. if (-not $DryRun) { Write-Host " [OK] $($_.Name)" -ForegroundColor Green }
  220. $totalDeployed++
  221. }
  222. } else {
  223. Write-Host " [SKIP] memory-templates directory not found" -ForegroundColor DarkGray
  224. }
  225. Write-Host ""
  226. }
  227. # ============================================
  228. # Part 4: Credentials Template
  229. # ============================================
  230. if (-not $DryRun -and -not $WorkshopOnly) {
  231. $credTemplate = Join-Path $ProjectRoot "__config\voc-credentials.template.json"
  232. $credTarget = Join-Path $OpenClawDir "voc-credentials.template.json"
  233. $credFile = Join-Path $OpenClawDir "voc-credentials.json"
  234. if (Test-Path $credTemplate) {
  235. Copy-Item $credTemplate -Destination $credTarget -Force
  236. if (-not (Test-Path $credFile)) {
  237. Write-Host " [INFO] Credentials template copied. Fill in vocToken in:" -ForegroundColor Yellow
  238. Write-Host " $credFile" -ForegroundColor Yellow
  239. }
  240. }
  241. }
  242. # ============================================
  243. # Summary
  244. # ============================================
  245. Write-Host " ====================================================" -ForegroundColor Cyan
  246. Write-Host " Deploy Summary" -ForegroundColor Cyan
  247. Write-Host " ====================================================" -ForegroundColor Cyan
  248. Write-Host ""
  249. Write-Host " Deployed: $totalDeployed"
  250. Write-Host " Skipped: $totalSkipped"
  251. Write-Host " Errors: $totalErrors"
  252. if ($bomFixed -gt 0) {
  253. Write-Host " BOM fixed: $bomFixed" -ForegroundColor Yellow
  254. }
  255. Write-Host ""
  256. if ($DryRun) {
  257. Write-Host " Remove -DryRun to execute actual deployment." -ForegroundColor Yellow
  258. } else {
  259. Write-Host " Done! Restart OpenClaw gateway to load new skills." -ForegroundColor Green
  260. Write-Host ""
  261. Write-Host " Verify:" -ForegroundColor DarkGray
  262. Write-Host " openclaw skills list" -ForegroundColor DarkGray
  263. Write-Host " openclaw skills info <skill-name>" -ForegroundColor DarkGray
  264. }
  265. Write-Host ""