summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Vincent <jesse@fsck.com>2026-10-22 22:26:43 +0000
committerJesse Vincent <jesse@fsck.com>2026-10-23 03:38:19 +0000
commit3735a50d5ab4c77ffa0ec7f0423d7414415c0aab (patch)
tree8132b3256872ca2d1453e25be693fbe247595f23
parent750ba92008b88850f6ab321706c7f840bbfff503 (diff)
fix(sdd): task-brief refuses a brief an unclosed code fence would run to EOFfix/2436-task-brief-unclosed-fence
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
-rwxr-xr-xskills/subagent-driven-development/scripts/task-brief35
-rwxr-xr-xtests/claude-code/test-sdd-workspace.sh113
2 files changed, 143 insertions, 5 deletions
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
diff --git a/tests/claude-code/test-sdd-workspace.sh b/tests/claude-code/test-sdd-workspace.sh
index 22f1774..d626e03 100755
--- a/tests/claude-code/test-sdd-workspace.sh
+++ b/tests/claude-code/test-sdd-workspace.sh
@@ -285,6 +285,119 @@ PLAN
echo " stderr: $es_err"
fi
+ # --- An unclosed fence hides every later Task heading (#2436) ---
+ cat > "$repo/plan-unclosed.md" <<'PLAN'
+# Example Plan
+
+### Task 1: First task
+
+```typescript
+const x = 1
+```
+
+```typescript
+const y = 2
+
+### Task 2: Second task
+
+TASK-2-MARKER
+
+### Task 3: Third task
+
+TASK-3-MARKER
+PLAN
+ local fence_out="$TEST_ROOT/unclosed-brief.md" fence_err
+ rc=0
+ fence_err="$(cd "$repo" && "$SDD_SCRIPTS/task-brief" plan-unclosed.md 1 "$fence_out" 2>&1 >/dev/null)" || rc=$?
+ if [[ "$rc" -eq 4 && ! -e "$fence_out" && "$fence_err" == *"line 9"*"never closes"* ]]; then
+ pass "task-brief refuses a brief that an unclosed fence would run to EOF (exit 4, names the line)"
+ else
+ fail "task-brief refuses a brief that an unclosed fence would run to EOF (exit 4, names the line)"
+ echo " exit: $rc"
+ echo " stderr: $fence_err"
+ echo " brief: $(cat "$fence_out" 2>/dev/null)"
+ fi
+
+ rc=0
+ fence_err="$(cd "$repo" && "$SDD_SCRIPTS/task-brief" plan-unclosed.md 2 "$fence_out" 2>&1 >/dev/null)" || rc=$?
+ if [[ "$rc" -eq 3 && "$fence_err" == *"never closes"* ]]; then
+ pass "task-brief names the unclosed fence when it hides the requested heading"
+ else
+ fail "task-brief names the unclosed fence when it hides the requested heading"
+ echo " exit: $rc"
+ echo " stderr: $fence_err"
+ fi
+
+ # An unclosed fence in a later task does not touch an earlier task's brief.
+ sed 's/^### Task 1: First task$/### Task 0: Before/' "$repo/plan-unclosed.md" \
+ | sed '1a\
+\
+### Task 1: Clean\
+\
+CLEAN-MARKER' > "$repo/plan-unclosed-later.md"
+ rc=0
+ fence_err="$(cd "$repo" && "$SDD_SCRIPTS/task-brief" plan-unclosed-later.md 1 "$fence_out" 2>&1 >/dev/null)" || rc=$?
+ if [[ "$rc" -eq 0 && -z "$fence_err" ]] && grep -q CLEAN-MARKER "$fence_out" && ! grep -q 'Task 0' "$fence_out"; then
+ pass "an unclosed fence in a later task leaves an earlier task's brief alone"
+ else
+ fail "an unclosed fence in a later task leaves an earlier task's brief alone"
+ echo " exit: $rc"
+ echo " stderr: $fence_err"
+ echo " brief: $(cat "$fence_out" 2>/dev/null)"
+ fi
+
+ # A stray fence that hides no Task heading (seen in real plans as a lone
+ # ``` on the last line) leaves the brief complete: brief it, and warn.
+ cat > "$repo/plan-stray-fence.md" <<'PLAN'
+### Task 1: First
+
+BODY-1
+
+### Task 2: Last
+
+BODY-2
+```
+PLAN
+ rc=0
+ fence_err="$(cd "$repo" && "$SDD_SCRIPTS/task-brief" plan-stray-fence.md 2 "$fence_out" 2>&1 >/dev/null)" || rc=$?
+ if [[ "$rc" -eq 0 && "$fence_err" == *"warning"*"line 8"*"never closes"* ]] \
+ && grep -q BODY-2 "$fence_out" && ! grep -q BODY-1 "$fence_out"; then
+ pass "a stray fence that hides no Task heading briefs the task and warns"
+ else
+ fail "a stray fence that hides no Task heading briefs the task and warns"
+ echo " exit: $rc"
+ echo " stderr: $fence_err"
+ echo " brief: $(cat "$fence_out" 2>/dev/null)"
+ fi
+
+ # An unclosed fence that hides only some later prose, but no Task
+ # heading, also leaves the last task's brief complete.
+ printf '### Task 1: Only\n\nBODY-1\n\n```sh\necho hi\n\n## Notes\n\nNOT-A-TASK\n' > "$repo/plan-stray-prose.md"
+ rc=0
+ fence_err="$(cd "$repo" && "$SDD_SCRIPTS/task-brief" plan-stray-prose.md 1 "$fence_out" 2>&1 >/dev/null)" || rc=$?
+ if [[ "$rc" -eq 0 && "$fence_err" == *"warning"* ]] && grep -q BODY-1 "$fence_out"; then
+ pass "an unclosed fence that hides no Task heading does not block the brief"
+ else
+ fail "an unclosed fence that hides no Task heading does not block the brief"
+ echo " exit: $rc"
+ echo " stderr: $fence_err"
+ fi
+
+ # When the open fence hides every Task heading, the fence is the
+ # diagnosis: the plan's English Task headings must not also draw the
+ # "use the English word Task" hint, which would contradict it.
+ printf '## Phase 1: Setup\n\n```sh\necho hi\n\n### Task 1: Hidden\n\nBODY-1\n' > "$repo/plan-fence-hides-all.md"
+ rc=0
+ fence_err="$(cd "$repo" && "$SDD_SCRIPTS/task-brief" plan-fence-hides-all.md 1 "$fence_out" 2>&1 >/dev/null)" || rc=$?
+ if [[ "$rc" -eq 3 && "$fence_err" == *"line 3"*"never closes"* && "$fence_err" == *"task 1 not found"* \
+ && "$fence_err" != *"English word"* ]]; then
+ pass "a fence hiding every Task heading gets the fence message, not the English-word hint"
+ else
+ fail "a fence hiding every Task heading gets the fence message, not the English-word hint"
+ echo " exit: $rc"
+ echo " stderr: $fence_err"
+ fi
+
# --- review-package takes the plan first and lands in its directory ---
local git_id=(-c user.email=t@example.com -c user.name=t -c commit.gpgsign=false)
( cd "$repo" \