task-brief 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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: <git-dir>/sdd/task-<N>-brief.md — unique per repo
  8. # instance, so concurrent sessions cannot collide.
  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=$(git rev-parse --git-path sdd)
  21. mkdir -p "$dir"
  22. dir=$(cd "$dir" && pwd)
  23. out="$dir/task-${n}-brief.md"
  24. fi
  25. awk -v n="$n" '
  26. /^```/ { infence = !infence }
  27. !infence && /^#+[ \t]+Task[ \t]+[0-9]+/ {
  28. intask = ($0 ~ ("^#+[ \t]+Task[ \t]+" n "([^0-9]|$)"))
  29. }
  30. intask { print }
  31. ' "$plan" > "$out"
  32. if [ ! -s "$out" ]; then
  33. echo "task ${n} not found in ${plan} (no heading matching 'Task ${n}')" >&2
  34. exit 3
  35. fi
  36. echo "wrote ${out}: $(wc -l < "$out" | tr -d ' ') lines"