Repository navigation
Conversation
`rtk init` (Ask mode, the default) prints the manual instructions and exits 0 when stdin is not a terminal. `prompt_user_confirmation` already defaults to No there, which is the right default, but the caller cannot tell that apart from a human typing `n` -- so an installer, a CI job or a devcontainer postCreateCommand sees success for a hook that was never installed. Measured on 0924356, Windows, with CLAUDE_CONFIG_DIR pointed at a temp dir holding a settings.json: rtk init -g --agent claude </dev/null EXIT=0, hook absent, settings.json untouched The VS Code extension ai-token-optimize-vscode hits this: its post-install runs `rtk init -g --copilot` and then tells the user RTK is wired. Split the unanswered prompt out as its own outcome (PatchResult::DeclinedNonInteractive) rather than reusing Declined, and end the run with an error naming --auto-patch. The rest of init still completes first: the hook is the only piece that did not land. --no-patch is untouched and still exits 0 -- a deliberate skip is not a failure. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Address the critical non-interactive TTY handling and missing caller-level regression coverage.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR makes unanswered non-interactive Claude settings prompts fail explicitly instead of silently succeeding.
Changes:
- Adds
DeclinedNonInteractivewith actionable guidance. - Preserves
--auto-patchand--no-patchbehavior. - Adds regression tests for prompt outcomes.
| File | Summary |
|---|---|
src/hooks/init.rs |
Implements outcome handling and error reporting. Review findings remain for caller-level coverage, pseudo-TTY handling, and stronger no-write assertions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| fn stdin_can_answer_prompt() -> bool { | ||
| use std::io::IsTerminal; | ||
| std::io::stdin().is_terminal() |
There was a problem hiding this comment.
Conceded, and fixed in 6276ae7 — the helper claimed more than it proved.
You are right that a pseudo-TTY defeats is_terminal(), and this file already says so: prompt_telemetry_consent documents devcontainer postCreateCommand and CI agents handing rtk a pseudo-TTY, and short-circuits on RTK_TELEMETRY_DISABLED for exactly that reason.
What I changed:
- Renamed to
stdin_is_terminal()and documented both halves. No terminal at all is the half this settles: theNoinprompt_user_confirmationis then nobody's decision, so reporting it as one is wrong regardless of what the pseudo-TTY case does. The pseudo-TTY hang is real, predates this change, and is untouched here. - Extracted
finish_patch_outcomeso both callers share one outcome→exit mapping, with a test at that level (the missing caller-level coverage in your overview).
On the hang itself, I did not want to invent policy in your tool. Two shapes that would close it, and I will send whichever you prefer as its own PR:
- An explicit signal, matching the precedent already in this file:
RTK_NONINTERACTIVE=1(and/orCI) treated as "do not prompt", the wayRTK_TELEMETRY_DISABLEDis handled today. - A bounded read: prompt, wait N seconds, then take the same
DeclinedNonInteractivepath instead of blocking forever.
Option 1 is the smaller change and matches what is already here; option 2 needs no environment cooperation. Your call.
📊 Automated PR Analysis
SummaryFixes Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
…exit decision Copilot review, PR rtk-ai#4141. `is_terminal()` does not establish that a human is there to answer: this file already records that some non-interactive environments hand rtk a pseudo-TTY, where the prompt waits forever. The helper claimed more than it proves. - Rename to `stdin_is_terminal` and document both halves: no terminal means the No belongs to nobody, while a pseudo-TTY still hangs and wants its own fix. - Extract `finish_patch_outcome` so both callers share one mapping from outcome to exit code, and cover it with a test at that level. Co-Authored-By: Claude Opus 5 <[email protected]>

Summary
rtk initin the default Ask mode prints the manual instructions and exits 0 when stdin is not a terminal, so the hook is not installed and the caller is told it succeeded.PatchResult::DeclinedNonInteractive) instead of reusingDeclined, and end the run with an error naming--auto-patch. Everything else init writes still completes first.--no-patchis untouched and still exits 0: a deliberate skip is not a failure.Why it matters
prompt_user_confirmationalready defaults to No without a terminal, which is the right default. The caller just cannot tell that apart from a human typingn. An installer, a CI job, or a devcontainerpostCreateCommandsees a zero exit for a hook that was never registered.That is not hypothetical: the
ai-token-optimize-vscodeextension runsrtk init -g --copilotfrom its installer and then tells the user RTK is wired. I hit it by hand on Windows first, which is how I found it.Measured, on
0924356, WindowsAfter this change, same command:
--auto-patchon the same file: exit 0, hook installed, pre-existing keys intact.--no-patch: exit 0.Test plan
cargo fmt --checkclean,cargo clippy --all-targetscleancargo test --bin rtk: 3644 passed. The 17 failures are all incore::stream("program not found") and reproduce identically on a stock checkout ofdevelopon this Windows box, so they are environmental and predate this change.hooks::init::tests: the unanswered prompt is its own outcome and leavessettings.jsonuntouched;--no-patchstill reportsSkipped; the error message names both flags.test_ask_mode_without_a_terminal_is_its_own_outcomefails withleft: Declined, right: DeclinedNonInteractive. The test fails against the old behavior.CLAUDE_CONFIG_DIRpointed at a scratch dir: the three exit codes above.Note on scope
Only the Claude
settings.jsonpath returnsPatchResult, so that is all this touches. Other prompts (pi/ompextension overwrite, Trae) callprompt_user_confirmationdirectly and take the same silent default; happy to follow up separately if you want that pattern closed too.