# Install Codex skills from this Playbook snapshot into CODEX_HOME. # - Source: \codex\skills\\ # - Dest: $env:CODEX_HOME\skills\\ (default CODEX_HOME=$HOME\.codex) # # Usage: # powershell -File scripts/install_codex_skills.ps1 # powershell -File scripts/install_codex_skills.ps1 style-cleanup commit-message # powershell -File scripts/install_codex_skills.ps1 -Local # # Notes: # - Codex loads skills at startup; restart `codex` after installation. # - Existing destination skill dirs are backed up with a timestamp suffix. [CmdletBinding()] param( [Alias('h', '?')] [switch]$Help, [switch]$Local, [switch]$All, [Parameter(Mandatory = $false)] [string[]]$Skills ) $ErrorActionPreference = "Stop" if ($Help) { Write-Host "Usage:" Write-Host " powershell -File scripts/install_codex_skills.ps1 -All" Write-Host " powershell -File scripts/install_codex_skills.ps1 -Skills style-cleanup,commit-message" Write-Host "" Write-Host "Options:" Write-Host " -Local Install to ./.codex (or CODEX_HOME if set)." Write-Host " -Skills Comma/space-separated skill names." Write-Host " -All Install all skills." Write-Host " -Help Show this help." Write-Host "" Write-Host "Env:" Write-Host " CODEX_HOME Target Codex home (default: ~/.codex)." exit 0 } if ($All -and $Skills -and $Skills.Count -gt 0) { throw "Use either -All or -Skills, not both." } if (-not $All -and (-not $Skills -or $Skills.Count -eq 0)) { throw "Missing -All or -Skills. Use -Help for usage." } $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path $SkillsSrcRoot = Join-Path $Src "codex/skills" if (-not (Test-Path $SkillsSrcRoot)) { throw "Skills source dir not found: $SkillsSrcRoot" } $CodexHome = $env:CODEX_HOME if ($Local) { $localHome = Join-Path (Get-Location) ".codex" if (-not $CodexHome) { $CodexHome = $localHome } } if (-not $CodexHome) { $homeDir = $HOME if (-not $homeDir) { $homeDir = $env:USERPROFILE } $CodexHome = (Join-Path $homeDir ".codex") } $SkillsDstRoot = Join-Path $CodexHome "skills" New-Item -ItemType Directory -Path $SkillsDstRoot -Force | Out-Null $timestamp = Get-Date -Format "yyyyMMddHHmmss" function Install-One([string]$Name) { $srcDir = Join-Path $SkillsSrcRoot $Name $dstDir = Join-Path $SkillsDstRoot $Name if (-not (Test-Path $srcDir)) { throw "Skill not found: $Name ($srcDir)" } if (Test-Path $dstDir) { $bak = Join-Path $SkillsDstRoot "$Name.bak.$timestamp" Move-Item $dstDir $bak Write-Host "Backed up existing skill: $Name -> $(Split-Path -Leaf $bak)" } Copy-Item $srcDir $dstDir -Recurse -Force Write-Host "Installed: $Name" } if ($All) { foreach ($dir in (Get-ChildItem -Path $SkillsSrcRoot -Directory)) { if ($dir.Name.StartsWith(".")) { continue } Install-One $dir.Name } } else { foreach ($item in $Skills) { if (-not $item) { continue } foreach ($part in $item.Split(@(',', ' '), [System.StringSplitOptions]::RemoveEmptyEntries)) { if (-not $part) { continue } Install-One $part } } } Write-Host "Done. Skills installed to: $SkillsDstRoot"