task-brief 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. [ -e "$plan" ] || { echo "no such plan: $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. if [ -d "$plan" ]; then
  27. # directory plan: the shared header, then this task's own file
  28. task=$(ls "$plan"/[0-9][0-9]-*.md 2>/dev/null | awk -v n="$n" '{ f=$0; sub(/.*\//,"",f); if (f+0==n) print $0 }' | head -1)
  29. [ -n "$task" ] || { echo "task ${n} not found in ${plan} (no [0-9][0-9]-*.md numbered ${n})" >&2; exit 3; }
  30. { [ -f "$plan/00-header.md" ] && cat "$plan/00-header.md"; echo; cat "$task"; } > "$out"
  31. echo "wrote ${out}: $(wc -l < "$out" | tr -d ' ') lines"
  32. exit 0
  33. fi
  34. awk -v n="$n" '
  35. /^```/ { infence = !infence }
  36. !infence && /^#+[ \t]+Task[ \t]+[0-9]+/ {
  37. intask = ($0 ~ ("^#+[ \t]+Task[ \t]+" n "([^0-9]|$)"))
  38. }
  39. intask { print }
  40. ' "$plan" > "$out"
  41. if [ ! -s "$out" ]; then
  42. echo "task ${n} not found in ${plan} (no heading matching 'Task ${n}')" >&2
  43. exit 3
  44. fi
  45. echo "wrote ${out}: $(wc -l < "$out" | tr -d ' ') lines"