task-brief 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env bash
  2. # Extract one task's full text from an implementation plan into a file the
  3. # implementer reads in one call, so the task text never has to be pasted
  4. # through the controller's context.
  5. #
  6. # Usage: task-brief PLAN_FILE TASK_NUMBER [OUTFILE]
  7. # Default OUTFILE: <repo-root>/.superpowers/sdd/task-<N>-brief.md
  8. # (per worktree; concurrent runs in the same working tree share it).
  9. set -euo pipefail
  10. if [ $# -lt 2 ] || [ $# -gt 3 ]; then
  11. echo "usage: task-brief PLAN_FILE TASK_NUMBER [OUTFILE]" >&2
  12. exit 2
  13. fi
  14. plan=$1
  15. n=$2
  16. [ -f "$plan" ] || { echo "no such plan file: $plan" >&2; exit 2; }
  17. if [ $# -eq 3 ]; then
  18. out=$3
  19. else
  20. dir=$("$(cd "$(dirname "$0")" && pwd)/sdd-workspace")
  21. out="$dir/task-${n}-brief.md"
  22. fi
  23. awk -v n="$n" '
  24. /^```/ { infence = !infence }
  25. !infence && /^#+[ \t]+Task[ \t]+[0-9]+/ {
  26. intask = ($0 ~ ("^#+[ \t]+Task[ \t]+" n "([^0-9]|$)"))
  27. }
  28. intask { print }
  29. ' "$plan" > "$out"
  30. if [ ! -s "$out" ]; then
  31. echo "task ${n} not found in ${plan} (no heading matching 'Task ${n}')" >&2
  32. exit 3
  33. fi
  34. echo "wrote ${out}: $(wc -l < "$out" | tr -d ' ') lines"