check-complete.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. # Check if all phases in task_plan.md are complete
  3. # Always exits 0 — uses stdout for status reporting
  4. # Used by Stop hook to report task completion status
  5. PLAN_FILE="${1:-task_plan.md}"
  6. if [ ! -f "$PLAN_FILE" ]; then
  7. echo "[planning-with-files] No task_plan.md found — no active planning session."
  8. exit 0
  9. fi
  10. # Count total phases
  11. TOTAL=$(grep -c "### Phase" "$PLAN_FILE" || true)
  12. # Check for **Status:** format first
  13. COMPLETE=$(grep -cF "**Status:** complete" "$PLAN_FILE" || true)
  14. IN_PROGRESS=$(grep -cF "**Status:** in_progress" "$PLAN_FILE" || true)
  15. PENDING=$(grep -cF "**Status:** pending" "$PLAN_FILE" || true)
  16. # Fallback: check for [complete] inline format if **Status:** not found
  17. if [ "$COMPLETE" -eq 0 ] && [ "$IN_PROGRESS" -eq 0 ] && [ "$PENDING" -eq 0 ]; then
  18. COMPLETE=$(grep -c "\[complete\]" "$PLAN_FILE" || true)
  19. IN_PROGRESS=$(grep -c "\[in_progress\]" "$PLAN_FILE" || true)
  20. PENDING=$(grep -c "\[pending\]" "$PLAN_FILE" || true)
  21. fi
  22. # Default to 0 if empty
  23. : "${TOTAL:=0}"
  24. : "${COMPLETE:=0}"
  25. : "${IN_PROGRESS:=0}"
  26. : "${PENDING:=0}"
  27. # Report status (always exit 0 — incomplete task is a normal state)
  28. if [ "$COMPLETE" -eq "$TOTAL" ] && [ "$TOTAL" -gt 0 ]; then
  29. echo "[planning-with-files] ALL PHASES COMPLETE ($COMPLETE/$TOTAL). If the user has additional work, add new phases to task_plan.md before starting."
  30. else
  31. echo "[planning-with-files] Task in progress ($COMPLETE/$TOTAL phases complete). Update progress.md before stopping."
  32. if [ "$IN_PROGRESS" -gt 0 ]; then
  33. echo "[planning-with-files] $IN_PROGRESS phase(s) still in progress."
  34. fi
  35. if [ "$PENDING" -gt 0 ]; then
  36. echo "[planning-with-files] $PENDING phase(s) pending."
  37. fi
  38. fi
  39. exit 0