| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #!/usr/bin/env bash
- # Extract one task's full text from an implementation plan into a file the
- # implementer reads in one call, so the task text never has to be pasted
- # through the controller's context.
- #
- # Usage: task-brief PLAN_FILE TASK_NUMBER [OUTFILE]
- # Default OUTFILE: <repo-root>/.superpowers/sdd/<plan-basename>/task-<N>-brief.md
- # (per plan and per worktree; concurrent runs of the SAME plan in the same
- # working tree share it).
- set -euo pipefail
- if [ $# -lt 2 ] || [ $# -gt 3 ]; then
- echo "usage: task-brief PLAN_FILE TASK_NUMBER [OUTFILE]" >&2
- exit 2
- fi
- plan=$1
- n=$2
- [ -e "$plan" ] || { echo "no such plan: $plan" >&2; exit 2; }
- if [ $# -eq 3 ]; then
- out=$3
- else
- # Invoke via bash rather than direct exec: some extractors (Python zipfile)
- # strip Unix exec bits when unpacking marketplace packages (#2040).
- dir=$("${BASH:-bash}" "$(cd "$(dirname "$0")" && pwd)/sdd-workspace" "$plan")
- out="$dir/task-${n}-brief.md"
- fi
- if [ -d "$plan" ]; then
- # directory plan: the shared header, then this task's own file
- 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)
- [ -n "$task" ] || { echo "task ${n} not found in ${plan} (no [0-9][0-9]-*.md numbered ${n})" >&2; exit 3; }
- { [ -f "$plan/00-header.md" ] && cat "$plan/00-header.md"; echo; cat "$task"; } > "$out"
- echo "wrote ${out}: $(wc -l < "$out" | tr -d ' ') lines"
- exit 0
- fi
- awk -v n="$n" '
- /^```/ { infence = !infence }
- !infence && /^#+[ \t]+Task[ \t]+[0-9]+/ {
- intask = ($0 ~ ("^#+[ \t]+Task[ \t]+" n "([^0-9]|$)"))
- }
- intask { print }
- ' "$plan" > "$out"
- if [ ! -s "$out" ]; then
- echo "task ${n} not found in ${plan} (no heading matching 'Task ${n}')" >&2
- exit 3
- fi
- echo "wrote ${out}: $(wc -l < "$out" | tr -d ' ') lines"
|