#1142·skills

wizard: editing the script while a wizard is running kills it (bash reads incrementally); patch parses the whole file before the first prompt

Author: kurama-aiCreated Sep 30, 2026Updated Sep 30, 2026

What happens

A wizard waits at prompts for minutes while the human works in a browser. Bash reads a script incrementally, by byte offset, as it executes, and template.sh runs its stages at top level. So when the file changes during a run (the agent that authored it fixing a hint while the human is mid-stage, an editor save, a git pull), the running shell resumes at a stale offset in the new file and dies with a spurious error.

Seen for real: a generated wizard was paused at "Paste the Client ID:" while its author updated two instruction lines above that point. Pressing Enter produced line 275: syntax error near unexpected token '(' on a line that was valid before and after the edit.

Reproduction

Start the template with stdin on a fifo, wait at the first prompt, insert 40 comment lines above TOTAL_STAGES, then feed the remaining answers (fake open, unauthenticated fake gh, macOS):

/bin/bash (3.2):              command not found, exit=127
/opt/homebrew/bin/bash (5.3): command not found, exit=127

Proposed fix

Run the authored section inside one function, run_wizard, called on the last line and followed by exit, so bash parses the whole file before the first prompt and never reads it again. The library above the STAGES marker is untouched; the marker comment tells the authoring agent to keep stages inside the function and leave the last line alone.

diff
 # STAGES: author this section. One stage() per step the human takes.
 # ...
+run_wizard() {
+
 TOTAL_STAGES=1

 banner "Stripe setup"
 ...
 finish
+}
+
+run_wizard "$@"; exit

Same reproduction against the patched template:

/bin/bash (3.2):              Setup complete, exit=0, both values written
/opt/homebrew/bin/bash (5.3): Setup complete, exit=0, both values written

bash -n passes under both bashes; shellcheck output is unchanged from main (the unused RED is #1003's, left alone here).

The patch

Pull requests from outside accounts look closed on this repo, so the change sits on a fork with a patch changeset, ready to pull or cherry-pick:

https://github.com/mattpocock/skills/compare/main...kurama-ai:mattpocock-skills:wizard-parse-before-first-prompt?expand=1

Happy to open it as a PR if that route is available.

Generated with Claude Code