resolve-plan-dir.ps1 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # planning-with-files: resolve active plan directory (PowerShell mirror).
  2. #
  3. # Resolution order matches scripts/resolve-plan-dir.sh:
  4. # 1. $env:PLAN_ID -> .\.planning\$PLAN_ID\
  5. # 2. .\.planning\.active_plan content
  6. # 3. Newest .\.planning\<dir>\ by LastWriteTime
  7. # 4. Empty (legacy fallback to .\task_plan.md handled by caller)
  8. param(
  9. [string]$PlanRoot = (Join-Path (Get-Location) ".planning")
  10. )
  11. $activeFile = Join-Path $PlanRoot ".active_plan"
  12. if ($env:PLAN_ID) {
  13. $candidate = Join-Path $PlanRoot $env:PLAN_ID
  14. if (Test-Path $candidate -PathType Container) {
  15. Write-Output $candidate
  16. exit 0
  17. }
  18. }
  19. if (Test-Path $activeFile) {
  20. $planId = (Get-Content $activeFile -Raw).Trim()
  21. if ($planId) {
  22. $candidate = Join-Path $PlanRoot $planId
  23. if (Test-Path $candidate -PathType Container) {
  24. Write-Output $candidate
  25. exit 0
  26. }
  27. }
  28. }
  29. if (Test-Path $PlanRoot -PathType Container) {
  30. $latest = Get-ChildItem -Path $PlanRoot -Directory |
  31. Where-Object { -not $_.Name.StartsWith('.') } |
  32. Sort-Object LastWriteTime -Descending |
  33. Select-Object -First 1
  34. if ($latest) {
  35. Write-Output $latest.FullName
  36. }
  37. }
  38. exit 0