set-active-plan.ps1 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # planning-with-files: set or display the active plan pointer (PowerShell).
  2. #
  3. # Usage:
  4. # .\set-active-plan.ps1 <plan_id> — pin .planning\.active_plan to plan_id
  5. # .\set-active-plan.ps1 — print the current active plan (if any)
  6. param(
  7. [string]$PlanId = ""
  8. )
  9. $PlanRoot = Join-Path (Get-Location) ".planning"
  10. $ActiveFile = Join-Path $PlanRoot ".active_plan"
  11. if ($PlanId -eq "") {
  12. if (Test-Path $ActiveFile) {
  13. $current = (Get-Content $ActiveFile -Raw -Encoding UTF8).Trim()
  14. $planDir = Join-Path $PlanRoot $current
  15. if ($current -ne "" -and (Test-Path $planDir)) {
  16. Write-Output "Active plan: $current"
  17. Write-Output "Path: $planDir"
  18. } elseif ($current -ne "") {
  19. Write-Output "Active plan pointer: $current (directory not found — stale pointer)"
  20. } else {
  21. Write-Output "No active plan set."
  22. }
  23. } else {
  24. Write-Output "No active plan set."
  25. }
  26. exit 0
  27. }
  28. $PlanDir = Join-Path $PlanRoot $PlanId
  29. if (-not (Test-Path $PlanDir)) {
  30. Write-Error "Error: plan directory not found: $PlanDir"
  31. Write-Error "Run: init-session.sh `"$PlanId`" to create it, or check .planning\ for available plans."
  32. exit 1
  33. }
  34. if (-not (Test-Path $PlanRoot)) {
  35. New-Item -ItemType Directory -Path $PlanRoot -Force | Out-Null
  36. }
  37. Set-Content -Path $ActiveFile -Value $PlanId -Encoding UTF8 -NoNewline
  38. Write-Output "Active plan set to: $PlanId"
  39. Write-Output "Path: $PlanDir"
  40. Write-Output ""
  41. Write-Output "To pin this terminal session only:"
  42. Write-Output "`$env:PLAN_ID = '$PlanId'"