1#!/usr/bin/env bash2# Extract one task's full text from an implementation plan into a file the3# implementer reads in one call, so the task text never has to be pasted4# through the controller's context.5#6# Usage: task-brief [-C DIR] PLAN_FILE TASK_NUMBER [OUTFILE]7# Default OUTFILE: <repo-root>/.superpowers/sdd/<plan-basename>/task-<N>-brief.md8# (per plan and per worktree; concurrent runs of the SAME plan in the same9# working tree share it). -C DIR runs as if started in DIR, as in sdd-workspace.10set -euo pipefail1112here=$(cd "$(dirname "$0")" && pwd)13if [ "${1:-}" = "-C" ]; then14 [ -d "${2:-}" ] || { echo "bad -C directory: ${2:-}" >&2; exit 2; }15 cd "$2"16 shift 217fi18
83 where = "the code fence opened at line " fence_line " of " ENVIRON["TASK_BRIEF_PLAN"] " never closes"
84 if (infence && hidden && (intask || !found)) {
85 print "task-brief: " where ", so no Task heading after it can be seen; close that fence in the plan and rerun" | "cat >&2"
86 if (intask) exit 4
87 } else if (infence && intask) {
88 print "task-brief: warning: " where "; it hides no Task heading, so this brief is complete" | "cat >&2"
89 }
90 # An open fence that hid Task headings already explains why none were
91 # seen; the English-word hint would contradict it.
92 if (!tasks && shaped && !(infence && hidden)) {
93 print "task-brief: no task headings found. Task headings must use the English word \"Task\" (\"### Task 1: ...\"), even when the rest of the plan is in another language. Headings shaped like tasks:" | "cat >&2"
94 for (i = 1; i <= shaped; i++) print " " shaped_heading[i] | "cat >&2"
95 }
96 }
97' "$plan" > "$out" || rc=$?
98if [ "$rc" -ne 0 ]; then
99 if [ -f "$out" ]; then rm -f "$out"; fi
100 exit "$rc"
101fi
102
103if [ ! -s "$out" ]; then
104 echo "task ${n} not found in ${plan} (no heading matching 'Task ${n}')" >&2