deploy-to-openclaw.ps1 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. # OpenClaw VOC Skills Deploy Script v3.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. $ToolsTarget = Join-Path $OpenClawDir "tools"
  27. $WorkspaceToolsTarget = Join-Path $WorkspaceTarget "scripts\tools"
  28. $OpenClawSkillsRoot = Join-Path $ProjectRoot "openclaw-skills"
  29. $ToolItems = @(
  30. @{ Source = Join-Path $ProjectRoot "scripts\tools\openclaw-tool-runner.js"; Dest = "openclaw-tool-runner.js" },
  31. @{ Source = Join-Path $ProjectRoot "scripts\tools\set-voc-token.js"; Dest = "set-voc-token.js" },
  32. @{ Source = Join-Path $ProjectRoot "scripts\tools\voc-token-preflight.js"; Dest = "voc-token-preflight.js" },
  33. @{ Source = Join-Path $ProjectRoot "scripts\tools\voc-single-platform-report.js"; Dest = "voc-single-platform-report.js" },
  34. @{ Source = Join-Path $ProjectRoot "scripts\tools\voc-data-normalizer.js"; Dest = "voc-data-normalizer.js" },
  35. @{ Source = Join-Path $ProjectRoot "scripts\tools\platform-mini-report-generator.js"; Dest = "platform-mini-report-generator.js" },
  36. @{ Source = Join-Path $ProjectRoot "scripts\tools\chapter-insight-writer.js"; Dest = "chapter-insight-writer.js" },
  37. @{ Source = Join-Path $ProjectRoot "scripts\tools\voc-report-auditor.js"; Dest = "voc-report-auditor.js" },
  38. @{ Source = Join-Path $ProjectRoot "scripts\tools\douyin-speaking-profile-memory.js"; Dest = "douyin-speaking-profile-memory.js" },
  39. @{ Source = Join-Path $ProjectRoot "scripts\tools\douyin-speaking-daily-runner.js"; Dest = "douyin-speaking-daily-runner.js" },
  40. @{ Source = Join-Path $ProjectRoot "scripts\tools\douyin-speaking-daily-report.js"; Dest = "douyin-speaking-daily-report.js" },
  41. @{ Source = Join-Path $ProjectRoot "scripts\tools\douyin-viral-script-analyzer.js"; Dest = "douyin-viral-script-analyzer.js" },
  42. @{ Source = Join-Path $ProjectRoot "scripts\tools\douyin-video-transcriber.js"; Dest = "douyin-video-transcriber.js" },
  43. @{ Source = Join-Path $OpenClawSkillsRoot "voc-report-factory\html-v2\gen-report-template.js"; Dest = "voc-report-factory\html-v2\gen-report-template.js" },
  44. @{ Source = Join-Path $OpenClawSkillsRoot "voc-report-factory\html-v2\report-renderer-template.js"; Dest = "voc-report-factory\html-v2\report-renderer-template.js" },
  45. @{ Source = Join-Path $ProjectRoot "demo\xiaohongshu\raw-notes.json"; Dest = "course-samples\xiaohongshu\raw-notes.json" },
  46. @{ Source = Join-Path $ProjectRoot "demo\xiaohongshu\raw-comments.json"; Dest = "course-samples\xiaohongshu\raw-comments.json" }
  47. )
  48. $SkillCategories = @(
  49. "voc",
  50. "social-media",
  51. "competitor-analysis",
  52. "review-analysis",
  53. "synthesis",
  54. "social-voc",
  55. "douyin",
  56. "xiaohongshu",
  57. "video-creation",
  58. "jimeng",
  59. "payment",
  60. "test"
  61. )
  62. # ============================================
  63. # Helper Functions
  64. # ============================================
  65. function Remove-Bom {
  66. param([string]$FilePath)
  67. $bytes = [System.IO.File]::ReadAllBytes($FilePath)
  68. if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
  69. $clean = $bytes[3..($bytes.Length - 1)]
  70. [System.IO.File]::WriteAllBytes($FilePath, $clean)
  71. return $true
  72. }
  73. return $false
  74. }
  75. function Test-SkillValid {
  76. param([string]$SkillDir, [string]$SkillName)
  77. $skillMd = Join-Path $SkillDir "SKILL.md"
  78. $apiConf = Join-Path $SkillDir "api-config.json"
  79. if (-not (Test-Path $skillMd)) {
  80. Write-Host " [SKIP] $SkillName - missing SKILL.md" -ForegroundColor DarkGray
  81. return $false
  82. }
  83. # Validate YAML frontmatter
  84. $mdContent = [System.IO.File]::ReadAllText($skillMd, [System.Text.Encoding]::UTF8)
  85. if ($mdContent -notmatch "^---\s*\r?\n") {
  86. Write-Host " [WARN] $SkillName - SKILL.md missing YAML frontmatter" -ForegroundColor Yellow
  87. }
  88. # Validate api-config.json if exists
  89. if (Test-Path $apiConf) {
  90. try {
  91. $null = Get-Content $apiConf -Raw -Encoding UTF8 | ConvertFrom-Json
  92. } catch {
  93. Write-Host " [ERROR] $SkillName - invalid JSON in api-config.json" -ForegroundColor Red
  94. return $false
  95. }
  96. }
  97. return $true
  98. }
  99. function Deploy-File {
  100. param([string]$Source, [string]$Dest, [string]$Label)
  101. if ($DryRun) {
  102. $tag = if (Test-Path $Dest) { "UPDATE" } else { "NEW" }
  103. Write-Host " [$tag] $Label" -ForegroundColor White
  104. } else {
  105. $destDir = Split-Path $Dest -Parent
  106. if (-not (Test-Path $destDir)) {
  107. New-Item -ItemType Directory -Path $destDir -Force | Out-Null
  108. }
  109. Copy-Item $Source -Destination $Dest -Force
  110. }
  111. }
  112. # ============================================
  113. # Banner
  114. # ============================================
  115. Write-Host ""
  116. Write-Host " ====================================================" -ForegroundColor Cyan
  117. Write-Host " OpenClaw VOC Skills Deploy v3.0.0" -ForegroundColor Cyan
  118. Write-Host " ====================================================" -ForegroundColor Cyan
  119. Write-Host ""
  120. Write-Host " Project: $ProjectRoot"
  121. Write-Host " OpenClaw: $OpenClawDir"
  122. if ($DryRun) { Write-Host " Mode: DRY RUN (preview only)" -ForegroundColor Yellow }
  123. if ($SkillsOnly) { Write-Host " Scope: Skills only" -ForegroundColor Yellow }
  124. if ($WorkshopOnly) { Write-Host " Scope: Workshop only" -ForegroundColor Yellow }
  125. Write-Host ""
  126. # Pre-flight check
  127. if (-not (Test-Path $OpenClawDir)) {
  128. Write-Host " [ERROR] OpenClaw directory not found: $OpenClawDir" -ForegroundColor Red
  129. Write-Host " Is OpenClaw installed? Specify -OpenClawDir to override." -ForegroundColor Yellow
  130. exit 1
  131. }
  132. $totalDeployed = 0
  133. $totalSkipped = 0
  134. $totalErrors = 0
  135. $bomFixed = 0
  136. # ============================================
  137. # Part 1: Deploy Skills
  138. # ============================================
  139. if (-not $WorkshopOnly) {
  140. Write-Host " [1/4] Deploying Skills" -ForegroundColor Cyan
  141. Write-Host " $('-' * 48)"
  142. if (-not $DryRun -and -not (Test-Path $SkillsTarget)) {
  143. New-Item -ItemType Directory -Path $SkillsTarget -Force | Out-Null
  144. }
  145. foreach ($cat in $SkillCategories) {
  146. $catPath = Join-Path $OpenClawSkillsRoot $cat
  147. if (-not (Test-Path $catPath)) { continue }
  148. $skillDirs = Get-ChildItem -Directory -Path $catPath -ErrorAction SilentlyContinue
  149. if ($null -eq $skillDirs -or $skillDirs.Count -eq 0) { continue }
  150. Write-Host " [$cat]" -ForegroundColor DarkCyan
  151. foreach ($skillDir in $skillDirs) {
  152. $skillName = $skillDir.Name
  153. if (-not (Test-SkillValid $skillDir.FullName $skillName)) {
  154. $totalSkipped++
  155. continue
  156. }
  157. $destDir = Join-Path $SkillsTarget $skillName
  158. if ($DryRun) {
  159. $tag = if (Test-Path $destDir) { "UPDATE" } else { "NEW" }
  160. Write-Host " [$tag] $skillName" -ForegroundColor White
  161. } else {
  162. if (Test-Path $destDir) {
  163. Remove-Item -Recurse -Force $destDir
  164. }
  165. New-Item -ItemType Directory -Path $destDir -Force | Out-Null
  166. Get-ChildItem -File -Path $skillDir.FullName | ForEach-Object {
  167. Copy-Item $_.FullName -Destination $destDir
  168. }
  169. # Fix UTF-8 BOM in SKILL.md (causes OpenClaw parsing failures)
  170. $deployedMd = Join-Path $destDir "SKILL.md"
  171. if (Test-Path $deployedMd) {
  172. if (Remove-Bom $deployedMd) {
  173. $bomFixed++
  174. }
  175. }
  176. Write-Host " [OK] $skillName" -ForegroundColor Green
  177. }
  178. $totalDeployed++
  179. }
  180. }
  181. # Also deploy workshop skills (e.g. brand-context-builder)
  182. $workshopSkillsPath = Join-Path $OpenClawSkillsRoot "workshop"
  183. if (Test-Path $workshopSkillsPath) {
  184. $wsSkills = Get-ChildItem -Directory -Path $workshopSkillsPath | Where-Object {
  185. Test-Path (Join-Path $_.FullName "SKILL.md")
  186. }
  187. if ($wsSkills.Count -gt 0) {
  188. Write-Host " [workshop skills]" -ForegroundColor DarkCyan
  189. foreach ($ws in $wsSkills) {
  190. $skillName = $ws.Name
  191. $destDir = Join-Path $SkillsTarget $skillName
  192. if ($DryRun) {
  193. $tag = if (Test-Path $destDir) { "UPDATE" } else { "NEW" }
  194. Write-Host " [$tag] $skillName" -ForegroundColor White
  195. } else {
  196. if (Test-Path $destDir) { Remove-Item -Recurse -Force $destDir }
  197. New-Item -ItemType Directory -Path $destDir -Force | Out-Null
  198. Get-ChildItem -File -Path $ws.FullName | ForEach-Object {
  199. Copy-Item $_.FullName -Destination $destDir
  200. }
  201. $deployedMd = Join-Path $destDir "SKILL.md"
  202. if (Test-Path $deployedMd) { if (Remove-Bom $deployedMd) { $bomFixed++ } }
  203. Write-Host " [OK] $skillName" -ForegroundColor Green
  204. }
  205. $totalDeployed++
  206. }
  207. }
  208. }
  209. Write-Host ""
  210. }
  211. # ============================================
  212. # Part 2: Deploy Workshop Playbooks (v3 split-file architecture)
  213. # ============================================
  214. if (-not $SkillsOnly) {
  215. Write-Host " [2/4] Deploying Workshop Playbooks" -ForegroundColor Cyan
  216. Write-Host " $('-' * 48)"
  217. # v3: Deploy all workshop .md files (global rules + session files + supporting docs)
  218. $workshopMdFiles = Get-ChildItem -File -Path (Join-Path $OpenClawSkillsRoot "workshop") -Filter "*.md" -ErrorAction SilentlyContinue
  219. if ($workshopMdFiles -and $workshopMdFiles.Count -gt 0) {
  220. foreach ($mdFile in $workshopMdFiles) {
  221. $dest = Join-Path $WorkspaceTarget $mdFile.Name
  222. Deploy-File $mdFile.FullName $dest $mdFile.Name
  223. if (-not $DryRun) { Write-Host " [OK] $($mdFile.Name)" -ForegroundColor Green }
  224. $totalDeployed++
  225. }
  226. } else {
  227. Write-Host " [SKIP] No workshop .md files found" -ForegroundColor DarkGray
  228. }
  229. Write-Host ""
  230. }
  231. # ============================================
  232. # Part 2b: Deploy Douyin Speaking Daily Package
  233. # ============================================
  234. if (-not $SkillsOnly) {
  235. Write-Host " [2b/4] Deploying Douyin Speaking Daily Package" -ForegroundColor Cyan
  236. Write-Host " $('-' * 48)"
  237. $douyinSpeakingSrc = Join-Path $OpenClawSkillsRoot "douyin-speaking-daily"
  238. $douyinSpeakingDest = Join-Path $WorkspaceTarget "douyin-speaking-daily"
  239. if (Test-Path $douyinSpeakingSrc) {
  240. Get-ChildItem -File -Recurse -Path $douyinSpeakingSrc | ForEach-Object {
  241. $relative = $_.FullName.Substring($douyinSpeakingSrc.Length).TrimStart('\', '/')
  242. $dest = Join-Path $douyinSpeakingDest $relative
  243. Deploy-File $_.FullName $dest ("douyin-speaking-daily/" + ($relative -replace '\\', '/'))
  244. if (-not $DryRun) { Write-Host " [OK] douyin-speaking-daily/$($relative -replace '\\', '/')" -ForegroundColor Green }
  245. $totalDeployed++
  246. }
  247. } else {
  248. Write-Host " [SKIP] douyin-speaking-daily directory not found" -ForegroundColor DarkGray
  249. }
  250. Write-Host ""
  251. }
  252. # ============================================
  253. # Part 3: Deploy Memory Templates
  254. # ============================================
  255. if (-not $SkillsOnly) {
  256. Write-Host " [3/4] Deploying Memory Templates" -ForegroundColor Cyan
  257. Write-Host " $('-' * 48)"
  258. $memSrc = Join-Path $OpenClawSkillsRoot "workshop\memory-templates"
  259. if (Test-Path $memSrc) {
  260. if (-not $DryRun -and -not (Test-Path $MemoryTarget)) {
  261. New-Item -ItemType Directory -Path $MemoryTarget -Force | Out-Null
  262. }
  263. Get-ChildItem -File -Path $memSrc -Filter "*.json" | ForEach-Object {
  264. $dest = Join-Path $MemoryTarget $_.Name
  265. Deploy-File $_.FullName $dest $_.Name
  266. if (-not $DryRun) { Write-Host " [OK] $($_.Name)" -ForegroundColor Green }
  267. $totalDeployed++
  268. }
  269. } else {
  270. Write-Host " [SKIP] memory-templates directory not found" -ForegroundColor DarkGray
  271. }
  272. Write-Host ""
  273. }
  274. # ============================================
  275. # Part 4: Deploy Local Tools
  276. # ============================================
  277. Write-Host " [4/4] Deploying Local Tools" -ForegroundColor Cyan
  278. Write-Host " $('-' * 48)"
  279. foreach ($tool in $ToolItems) {
  280. if (-not (Test-Path $tool.Source)) {
  281. Write-Host " [SKIP] $($tool.Dest) - source not found" -ForegroundColor DarkGray
  282. $totalSkipped++
  283. continue
  284. }
  285. $toolsDest = Join-Path $ToolsTarget $tool.Dest
  286. $workspaceDest = Join-Path $WorkspaceToolsTarget $tool.Dest
  287. Deploy-File $tool.Source $toolsDest $tool.Dest
  288. Deploy-File $tool.Source $workspaceDest ("workspace/scripts/tools/" + $tool.Dest)
  289. if (-not $DryRun) { Write-Host " [OK] $($tool.Dest)" -ForegroundColor Green }
  290. $totalDeployed++
  291. }
  292. Write-Host ""
  293. # ============================================
  294. # Part 5: Credentials Template
  295. # ============================================
  296. if (-not $DryRun -and -not $WorkshopOnly) {
  297. $credTemplate = Join-Path $ProjectRoot "__config\voc-credentials.template.json"
  298. $credTarget = Join-Path $OpenClawDir "voc-credentials.template.json"
  299. $credFile = Join-Path $OpenClawDir "voc-credentials.json"
  300. if (Test-Path $credTemplate) {
  301. Copy-Item $credTemplate -Destination $credTarget -Force
  302. if (-not (Test-Path $credFile)) {
  303. Write-Host " [INFO] Credentials template copied. Fill in vocToken in:" -ForegroundColor Yellow
  304. Write-Host " $credFile" -ForegroundColor Yellow
  305. }
  306. }
  307. }
  308. # ============================================
  309. # Summary
  310. # ============================================
  311. Write-Host " ====================================================" -ForegroundColor Cyan
  312. Write-Host " Deploy Summary" -ForegroundColor Cyan
  313. Write-Host " ====================================================" -ForegroundColor Cyan
  314. Write-Host ""
  315. Write-Host " Deployed: $totalDeployed"
  316. Write-Host " Skipped: $totalSkipped"
  317. Write-Host " Errors: $totalErrors"
  318. if ($bomFixed -gt 0) {
  319. Write-Host " BOM fixed: $bomFixed" -ForegroundColor Yellow
  320. }
  321. Write-Host ""
  322. if ($DryRun) {
  323. Write-Host " Remove -DryRun to execute actual deployment." -ForegroundColor Yellow
  324. } else {
  325. Write-Host " Done! Restart OpenClaw gateway to load new skills." -ForegroundColor Green
  326. Write-Host ""
  327. Write-Host " Verify:" -ForegroundColor DarkGray
  328. Write-Host " openclaw skills list" -ForegroundColor DarkGray
  329. Write-Host " openclaw skills info <skill-name>" -ForegroundColor DarkGray
  330. Write-Host " Test-Path ~/.openclaw/workspace/scripts/tools/openclaw-tool-runner.js" -ForegroundColor DarkGray
  331. }
  332. Write-Host ""