deploy-to-openclaw.ps1 15 KB

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