From 3735a50d5ab4c77ffa0ec7f0423d7414415c0aab Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Thu, 22 Oct 2026 22:26:43 +0000 Subject: fix(sdd): task-brief refuses a brief an unclosed code fence would run to EOF task-brief ignores Task headings inside fenced code blocks by toggling a flag on every ``` line. When a plan leaves a fence open (an edit deletes a closing fence), the flag stays set for the rest of the file, every later Task heading is invisible, and the requested task's brief runs to EOF. The script then reported success: #2436 saw a 177-line task come back as a 1159-line brief holding tasks 6 through 10, handed to an implementer as its requirements. The awk now notes whether a Task heading line appears inside the fence that is still open at EOF. If one does while the requested task is being captured, the task's end cannot be found, so task-brief deletes the partial output and exits 4, naming the line where the fence opened. If the open fence hides the requested heading itself, it names the fence before the existing not-found error (exit 3), and suppresses the "use the English word Task" hint, which would otherwise blame the plan's English headings for what the fence did. A fence left open that hides no Task heading changes nothing about the brief, so it is still written, with a warning on stderr. Real plans do this: in a corpus of 1,288 plans, refusing on any fence left open at EOF blocked three correct briefs in two plans, each ending in a stray ``` that hides no task. With this rule every brief in that corpus matches dev's. An unclosed fence in a later task leaves an earlier task's brief alone. The plan path reaches awk through the environment rather than -v, which would interpret the backslashes of a Windows path as escapes. The fence rule itself is unchanged, so this composes with #2304's CommonMark fence tracking: a correct parser still cannot close a fence the author never closed. Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba --- .../subagent-driven-development/scripts/task-brief | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'skills/subagent-driven-development/scripts') diff --git a/skills/subagent-driven-development/scripts/task-brief b/skills/subagent-driven-development/scripts/task-brief index d95cd59..8549e48 100755 --- a/skills/subagent-driven-development/scripts/task-brief +++ b/skills/subagent-driven-development/scripts/task-brief @@ -41,8 +41,20 @@ fi # the plan is in. A plan with no Task headings at all usually translated it # ("## Tarea 1"), so list the headings shaped like tasks before the # not-found error instead of implying the plan has no task 1 (#2496). -awk -v n="$n" ' - /^```/ { infence = !infence } +# +# A fence that never closes hides every Task heading after it (#2436). When +# it hides one while the requested task is being captured, that task's end +# can't be found and the brief would run on through every later task: refuse +# (exit 4) rather than hand an implementer several tasks as its requirements. +# When it hides the requested heading itself, say so before the not-found +# error. A stray fence that hides no Task heading (real plans end with a lone +# ``` line) leaves the brief complete, so brief it with a warning. +# The plan path goes through ENVIRON, not -v, which would mangle the +# backslashes of a Windows path. +rc=0 +TASK_BRIEF_PLAN="$plan" awk -v n="$n" ' + /^```/ { infence = !infence; if (infence) { fence_line = NR; hidden = 0 } } + infence && /^#+[ \t]+Task[ \t]/ { hidden = 1 } !infence && /^#+[ \t]+Task[ \t]/ { id = $0 sub(/^#+[ \t]+Task[ \t]+/, "", id) @@ -59,14 +71,27 @@ awk -v n="$n" ' } } !infence && /^#+[ \t]+[^ \t]+[ \t]+[A-Za-z0-9.]*[0-9]/ && shaped < 5 { shaped_heading[++shaped] = $0 } - intask { print } + intask { print; found = 1 } END { - if (!tasks && shaped) { + where = "the code fence opened at line " fence_line " of " ENVIRON["TASK_BRIEF_PLAN"] " never closes" + if (infence && hidden && (intask || !found)) { + print "task-brief: " where ", so no Task heading after it can be seen; close that fence in the plan and rerun" | "cat >&2" + if (intask) exit 4 + } else if (infence && intask) { + print "task-brief: warning: " where "; it hides no Task heading, so this brief is complete" | "cat >&2" + } + # An open fence that hid Task headings already explains why none were + # seen; the English-word hint would contradict it. + if (!tasks && shaped && !(infence && hidden)) { 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" for (i = 1; i <= shaped; i++) print " " shaped_heading[i] | "cat >&2" } } -' "$plan" > "$out" +' "$plan" > "$out" || rc=$? +if [ "$rc" -ne 0 ]; then + if [ -f "$out" ]; then rm -f "$out"; fi + exit "$rc" +fi if [ ! -s "$out" ]; then echo "task ${n} not found in ${plan} (no heading matching 'Task ${n}')" >&2 -- cgit