Skip to content

fix(fm-brief): bash 3.2 here-doc parse error breaks default brief scaffolding - #121

Closed
scar-sh wants to merge 1 commit into
kunchenguid:mainfrom
scar-sh:fm/fix-brief-q2
Closed

scar-sh wants to merge 1 commit into
kunchenguid:mainfrom
scar-sh:fm/fix-brief-q2

Conversation

@scar-sh

@scar-sh scar-sh commented Jun 28, 2026

Copy link
Copy Markdown

Problem

On stock macOS Bash (GNU bash 3.2.57, i.e. /bin/bash), bin/fm-brief.sh fails to parse:

$ /bin/bash -n bin/fm-brief.sh
bin/fm-brief.sh: line 211: unexpected EOF while looking for matching `''
bin/fm-brief.sh: line 263: syntax error: unexpected end of file

This breaks the default task path: no-mistakes-mode briefs cannot be scaffolded at all on a stock-bash machine. It went unnoticed because modern bash (5.x) parses the file fine.

Root cause

The no-mistakes (default-mode) Definition-of-done block was assigned via command substitution wrapping a here-doc:

DOD=$(cat <<EOF
...
Follow no-mistakes' own guidance for the mechanics: ...
...
EOF
)

That here-doc body contains an apostrophe (no-mistakes'). Bash 3.2's command-substitution parser mis-tokenizes the apostrophe inside $(...) as an opening single-quote and scans to EOF looking for its match. The --scout, direct-PR, and local-only here-docs happen to contain no apostrophe, so only the default path errored.

A quoted delimiter (<<'EOF') does not fix it — the bug is in the $(...) command-substitution parser itself, not heredoc quoting (verified: an apostrophe in a <<'EOF' body inside $(...) still breaks bash 3.2). The same here-doc body parses fine at statement level.

Fix

Move every mode's Definition-of-done out of $(...) and append it directly to the brief with cat >> "$BRIEF" <<EOF. The here-doc bodies are byte-identical to before — this is a parser-compatibility fix, not a content change. The assembled brief output is unchanged for all modes: same single blank line at the Project-memory → Definition-of-done join, and $ID interpolation plus escaped backticks preserved.

Validation (stock Bash 3.2.57, /bin/bash)

bash -n before vs after:

# before
bin/fm-brief.sh: line 211: unexpected EOF while looking for matching `''
bin/fm-brief.sh: line 263: syntax error: unexpected end of file   (exit 2)
# after
$ /bin/bash -n bin/fm-brief.sh ; echo $?
0

Functionally scaffolded a complete, correct brief under /bin/bash for every mode and inspected the output:

  • no-mistakes (default), direct-PR, local-only, scout, and a --secondmate charter all scaffold successfully.
  • direct-PR / local-only driven via a temp registry (data/projects.md); unknown-project fallback (→ no-mistakes) also exercised.
  • Confirmed the default-mode brief still contains the unchanged no-mistakes DoD text: the /no-mistakes invocation, no-mistakes axi run --help, the ask-user / --yes rules, and the done: PR {url} checks green line.
  • Confirmed exactly one blank line at the Project-memory → Definition-of-done join, backticks rendered (not literal \`), and $ID interpolated correctly in Setup, Rule 1, and the local-only/direct-PR DoD.

Diff is limited to bin/fm-brief.sh.

…ffolding

The no-mistakes (default-mode) Definition-of-done block was assigned via
DOD=$(cat <<EOF ... EOF), and its body contains an apostrophe ("no-mistakes'").
GNU bash 3.2.57 (stock /bin/bash on macOS) mis-tokenizes that apostrophe inside
$(...) command substitution as an opening single-quote and scans to EOF for a
match, so `bash -n bin/fm-brief.sh` errors and the default task path cannot
scaffold a brief at all on a stock-bash machine. Bash 5.x parses it fine, and
the --scout / direct-PR / local-only here-docs happen to contain no apostrophe,
which is why it went unnoticed.

A quoted delimiter (<<'EOF') does not help: the bug is in the command-sub
parser, not heredoc quoting. The same here-doc body parses fine at statement
level. Fix moves every mode's Definition-of-done out of $(...) and appends it
directly to the brief with `cat >> "$BRIEF" <<EOF`. Bodies are byte-identical
and the assembled brief output is unchanged for all modes (verified: identical
single blank line at the join, backticks and $ID interpolation preserved).

  $ /bin/bash -n bin/fm-brief.sh   # before: error line 211/263; after: exit 0
@scar-sh scar-sh closed this Jun 28, 2026
@william-lubelski-mercury

Copy link
Copy Markdown

@scar-sh sorry my claude was trying to operate on my fork and it commented here. I think this fix is valid

fritznoff pushed a commit to fritznoff/starship that referenced this pull request Nov 2, 2026
…nchenguid#121)

* fix(bin): stop bounded probes losing their answer to the terminal

fm_run_timeout runs its command in its own process group so a timeout can
kill the whole group. That also moves the command out of the terminal's
foreground process group, so a probed CLI that touches the terminal takes
SIGTTOU and stops until the bound kills it. The caller then reads an empty
answer from a perfectly healthy tool.

The failure is invisible without a terminal, which is why it reached a
release: every non-interactive caller and test saw the same probe pass.
Interactively it refused `firstmate claude`, whose account seat check read
nothing from a logged-in home and concluded it could not prove the seat.
Codex profiles were unaffected only because no account is pinned for them.

Detach stdin instead of surrendering the group kill, so runaway children
stay bounded. Every caller here is a read-only probe with no stdin to pass
through, and bin/fm-toolchain-lib.sh already carried this redirect at its
own call site before the helper owned it.

Verified under a real pseudo-terminal: unfixed reads OUT=[] RC=124, fixed
reads OUT=[PROBE-OK] RC=0, on both the timeout(1) and perl fallback paths.

* no-mistakes(review): harden pty test drain, leak guard, python3 prereq; drop redundant redirect

* no-mistakes(document): test: self-skip timeout pty test without python3

* fix(fork-surface): claim tests/fm-timeout-lib.test.sh under upstream-drift-detect

The new pty test for bin/fm-timeout-lib.sh was an unclaimed fork-only path,
which failed the Declared fork surface check and the live-manifest assertion
in tests/fm-fork-surface.test.sh inside portable-serial-1. The capability that
owns the helper now owns and is proven by its test.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants