Repository navigation
fix(init): --guided reads piped answers, aborts non-zero on EOF; EOF-safe y/N prompts (#375) - #376
Merged
Merged
Conversation
…ts with exit 1 (#375) `charter init --guided` with piped stdin stopped mid-questionnaire, wrote nothing and exited 0. Root cause: a pending rl.question callback never fires when readline closes on EOF, so run()'s promise never settled and Node exited 0 once the event loop drained. - Check up front, before any prompt or write: non-TTY stdin or a non-text format exits 1 with a message (stderr, or one JSON error document) naming `charter init --preset <...>` / `--force`. Answers are never read from a pipe. - Questions reject on readline 'close', so Ctrl-D / Ctrl-C mid-questionnaire prints "Aborted; nothing was written." and exits 1. - Tests run the real readline over a PassThrough for EOF and the happy path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mptYesNo (#375) Rework after review: refusing every non-TTY stdin would lock out Git Bash / mintty users, whose typed input reaches node.exe as a pipe. - Drop the non-TTY refusal (GUIDED_REQUIRES_TTY). Guided answers come from a queue fed by rl.on('line'), so lines that arrive while no question is pending are no longer dropped: fully piped answers work like typed ones. - stdin closing before the last answer (short pipe, </dev/null, Ctrl-D on an empty line) prints "Aborted; nothing was written." and exits 1; Ctrl-C at a terminal exits 130. Nothing is written before the last answer. - --format json refusal (GUIDED_REQUIRES_TEXT) kept. - promptYesNo: a close before the answer resolves N with a note on stderr instead of leaving the promise pending (exit 0 mid-run). - --guided --preset <name> seeds the fallback preset instead of being ignored. - Root --help lists all six presets for init and setup. - Docs/CHANGELOG: both root causes, usage-log caveat, Ctrl-D wording. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… preset lists (#375) Second review round on PR #376: - promptYesNo: Ctrl-C (readline SIGINT) prints "Aborted." and exits 130 from the helper, so bootstrap no longer carries on to migrate/install after an interrupt. EOF / Ctrl-D on an empty line still resolve N with the note. - init --guided --ci refuses up front (exit 1); a CI stdin that never closes would otherwise wait forever. - Terminal-mode readline tests over a fake TTY: typed Enter, Ctrl-C (130), Ctrl-D on an empty line (1), Ctrl-D mid-line deletes; promptYesNo Ctrl-C (mocked process.exit) and Ctrl-D. - All preset lists show six presets (root --help option, adf --help, CLI README, docs snippet). - CHANGELOG: --guided --format json removal and --ci refusal under Changed; pipe Ctrl-C wording limited to what is verified. Drop leftover setTTY(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ecorded; preset tables (#375) - promptYesNo: Ctrl-C rejects with CLIError('Aborted.', 130) instead of process.exit(130). No caller catches it, so the command still stops, run() records the usage-log event with exit 130, and bin.ts prints `charter: Aborted.` and sets the exit code. Test drives bootstrap's orphan prompt in terminal mode and checks the 130 telemetry event. - Global Flags --preset rows in docs/cli-reference.md and docs-snippets/charter-cli-reference.md list all six presets. - init.ts comment: 130 is what POSIX shells report; Windows reports STATUS_CONTROL_C_EXIT. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #375
Problem
charter init --guidedwith piped / non-TTY stdin (echo y | charter init --guided, CI) stopped partway through the questions, wrote nothing, and exited 0. It did this even when every answer was piped (printf 'typescript\ny\ny\n' | ...).Root causes (two)
rl.questiononly receives a line if a question is pending at that moment, so lines 2..n were dropped and the run stalled after Q2.closeand never calls a pendingrl.questioncallback.run()'s promise never settled,bin.tsnever setprocess.exitCode, and Node exited 0 once the event loop drained.Fix
packages/cli/src/commands/init.tsGuidedLineReaderregistersrl.on('line')once and queues lines. Each question takes the next queued line or waits for one, so piped answers behave like typed ones and write the same files. Non-TTY stdin is not refused: Git Bash/mintty without ConPTY presents typed input tonode.exeas a pipe (review finding 1 on the first revision).</dev/null, Ctrl-D on an empty line), it printsAborted; nothing was written.on stderr and exits 1. Ctrl-C at a terminal (readlineSIGINT) exits 130. On a pipe, Ctrl-C is a process signal that readline never sees. The CLI does not handle it, so the signal ends the process; the exact exit status has not been verified on Windows/mintty..charter/telemetry/events.ndjsonis still appended, as after every command. In a fresh dir with no.charter/.gitignoreit shows up as untracked; the docs say so.--format jsonis still refused up front (GUIDED_REQUIRES_TEXT): one JSON document{ error, errorCode, guided: true, writesPerformed: 0 }, exit 1.GUIDED_REQUIRES_TTYis gone.--guided --preset <name>now seeds the fallback preset (previously silently ignored). It is used when the language answer names no known stack, and Q1 showsblank keeps --preset <name>. A recognized language or a Cloudflareystill decides. I picked this over a warning because it makes the flag useful and is a one-line change in the existing decision chain.packages/cli/src/commands/adf-scaffold-write.ts:promptYesNorl.question. A close before the answer now resolves N, withNo answer (input closed); treating it as N.on stderr. The non-TTY guard is unchanged.--reset-adf"Replace them?", this is the existing decline path: exit 1, nothing written.bootstrap.tscall sites are untouched (bootstrap rewrites .mcp.json formatting and overwrites a hand-edited charter-governance.yml with no backup #374 is in flight there).packages/cli/src/index.ts: the root--helplists all six presets forinitandsetup.Tests
init-guided-tty.test.ts(19 tests) runs the realnode:readlineover a PassThrough:--presetseeding, and language overriding the seed;</dev/null,echo y |and two-answer pipes all exit 1 with nothing written;.charter/untouched;promptYesNo: EOF gives N plus a note,ygives yes, non-TTY gives N without creating an interface;Other test files: the
no-silent-overwrite.test.tsreadline mock is now an EventEmitter that answersprompt()with alineevent, and thebootstrap-force-merge.test.tsmock gainsonce.Full suite: 1620 passed; the 3 failures are the known pre-existing Windows path-separator ones (bootstrap #307, context-refresh, serve-context).
Docs
docs/cli-reference.md(charter init->--guided) and CHANGELOG[Unreleased]->### Fixed(guided, y/N prompts,--presetseeding, help text).Known cosmetic
With piped answers, the echo of each answer in the stdout transcript is not uniform. An answer that arrives while its question is waiting is not echoed; answers already queued are. Echoing unconditionally would double-echo mintty typists.
Update (d429987, second review round)
promptYesNo, Ctrl-C: readlineSIGINTnow printsAborted.and callsprocess.exit(130)inside the helper. Bootstrap no longer goes on to migrate configs or install packages after an interrupt.bootstrap.tsis untouched. EOF and Ctrl-D on an empty line still mean N, with the note.init --guided --ciis refused up front: exit 1, with a stderr message namingcharter init --preset. When--format jsonis also passed, the JSON refusal applies instead.terminal: trueover a fake TTY PassThrough. 10 consecutive runs passed. They cover:\x03(exit 130),\x04on an empty line (exit 1), and\x04mid-line deleting a character;promptYesNo:\x03withprocess.exitmocked (asserts 130), and\x04(resolves N).--help--presetoption,charter adf --help,packages/cli/README.md(two places) anddocs-snippets/charter-cli-reference.md.bootstrap.ts:145, the invalid-preset error message, still lists five; I left it because bootstrap rewrites .mcp.json formatting and overwrites a hand-edited charter-governance.yml with no backup #374 is changing that file.--guided --format jsonremoval and the--cirefusal are now under### Changed.setTTY()calls fromno-silent-overwrite.test.ts.Update (5dee01b)
promptYesNoon Ctrl-C: it now rejects withCLIError('Aborted.', 130)instead of callingprocess.exit(130). Nothing between the prompt and the dispatcher catches it, so:run()records the usage-log event with exit code 130;bin.tsprintscharter: Aborted.and sets the exit code.CLIError130 and the 130 telemetry event.--presetrows indocs/cli-reference.mdanddocs-snippets/charter-cli-reference.mdnow list all six presets.init.tscomment: now says 130 is what POSIX shells report and that Windows reportsSTATUS_CONTROL_C_EXIT.🤖 Generated with Claude Code