task-brief 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. dir=$("$(cd "$(dirname "$0")" && pwd)/sdd-workspace" "$plan")
  22. out="$dir/task-${n}-brief.md"
  23. fi
  24. awk -v n="$n" '
  25. /^```/ { infence = !infence }
  26. !infence && /^#+[ \t]+Task[ \t]+[0-9]+/ {
  27. intask = ($0 ~ ("^#+[ \t]+Task[ \t]+" n "([^0-9]|$)"))
  28. }
  29. intask { print }
  30. ' "$plan" > "$out"
  31. if [ ! -s "$out" ]; then
  32. echo "task ${n} not found in ${plan} (no heading matching 'Task ${n}')" >&2
  33. exit 3
  34. fi
  35. echo "wrote ${out}: $(wc -l < "$out" | tr -d ' ') lines"