task-brief 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/<plan-basename>/task-<N>-brief.md
  8. # (per plan and per worktree; concurrent runs of the SAME plan in the same
  9. # working tree share it).
  10. set -euo pipefail
  11. if [ $# -lt 2 ] || [ $# -gt 3 ]; then
  12. echo "usage: task-brief PLAN_FILE TASK_NUMBER [OUTFILE]" >&2
  13. exit 2
  14. fi
  15. plan=$1
  16. n=$2
  17. [ -f "$plan" ] || { echo "no such plan file: $plan" >&2; exit 2; }
  18. if [ $# -eq 3 ]; then
  19. out=$3
  20. else
  21. # Invoke via bash rather than direct exec: some extractors (Python zipfile)
  22. # strip Unix exec bits when unpacking marketplace packages (#2040).
  23. dir=$("${BASH:-bash}" "$(cd "$(dirname "$0")" && pwd)/sdd-workspace" "$plan")
  24. out="$dir/task-${n}-brief.md"
  25. fi
  26. awk -v n="$n" '
  27. /^```/ { infence = !infence }
  28. !infence && /^#+[ \t]+Task[ \t]+[0-9]+/ {
  29. intask = ($0 ~ ("^#+[ \t]+Task[ \t]+" n "([^0-9]|$)"))
  30. }
  31. intask { print }
  32. ' "$plan" > "$out"
  33. if [ ! -s "$out" ]; then
  34. echo "task ${n} not found in ${plan} (no heading matching 'Task ${n}')" >&2
  35. exit 3
  36. fi
  37. echo "wrote ${out}: $(wc -l < "$out" | tr -d ' ') lines"