[Bug] Prompts never settle when stdin ends
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 半天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
- 领域
- cli
调研方向
The hang comes from prompt() in packages/core/src/prompts/prompt.ts, which settles only on submit and cancel (around lines 185-196), so start there and look at how the input stream is wired in. Reproduce with node repro.mjs < /dev/null using the snippet in the issue. Done means a prompt whose input ends (or has already ended) resolves with the cancel symbol, and both repro runs print 'settled with cancel' and exit 0. Check first that maintainers agree on cancel as the behaviour, since the reporter has asked.
由索引模型根据 Issue 内容生成。
描述
Environment
- OS: macOS
- Node Version: v22.23.2 and v26.0.0
- Package:
@clack/core(through@clack/prompts) - Package Version:
@clack/prompts1.8.1,@clack/core1.5.1, same on main (5ac9e73)
Describe the bug
When stdin ends while a prompt is waiting, or before it starts, the prompt never settles. await confirm(...) hangs, and in an ES module Node then exits with code 13 ("Detected unsettled top-level await"), with the cursor still hidden. It happens with closed stdin (< /dev/null, some CI runners and agent shells) and with piped input that runs out before the last prompt.
prompt() resolves only on submit and cancel (prompt.ts#L185-L196), and nothing handles the input stream ending.
To Reproduce
// repro.mjs
import { confirm, text, isCancel } from '@clack/prompts';
const ok = await confirm({ message: 'Continue?' });
console.log('confirm settled with', isCancel(ok) ? 'cancel' : ok);
const name = await text({ message: 'Name?' });
console.log('text settled with', isCancel(name) ? 'cancel' : JSON.stringify(name));
$ node repro.mjs < /dev/null
◆ Continue?
│ ● Yes / ○ No
└
Warning: Detected unsettled top-level await at file:///.../repro.mjs:3
$ echo $?
13
$ printf 'y\r' | node repro.mjs
◇ Continue?
│ Yes
confirm settled with true
◆ Name?
│ _
└
Warning: Detected unsettled top-level await at file:///.../repro.mjs:5
$ echo $?
13
Expected behavior
The prompt settles when its input ends. Returning the cancel symbol seems the natural fit, since no answer can come and callers already handle isCancel(). With that, both runs above print "settled with cancel" and exit 0.
Additional Information
I've read #533 and the advice to skip prompts when there is no TTY. This is narrower: a prompt can still be reached with closed or piped stdin, and then it hangs with no message instead of cancelling. We hit it with @fumadocs/cli add in a non-interactive shell: it wrote the files, asked "Do you want to install with npm?", and exited 13 without installing anything.
I have a small fix in @clack/core with tests (cancel on the input's end, and right away if the input has already ended) and can open a PR if cancel is the behaviour you want.
- 主要语言
- TypeScript
- 星标
- 8.1k
- 派生
- 218
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bombshell-dev/clack 的其他 Issue
-
[Bug]未关闭bug
难度 4/5 3-5 天 新手友好度 12/100
bombshell-dev/clack#619 ·
-
难度 3/5 1-2 天 新手友好度 70/100
bombshell-dev/clack#613 · 4 条评论 ·
-
难度 5/5 一周以上 新手友好度 30/100
bombshell-dev/clack#597 ·
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
bombshell-dev/clack#585 · 1 条评论 · 1 个 reaction ·
-
[Bug] Spinner does not run `onCancel` function on `Ctrl + C`可能已有人在做 @cyphercodes 于 107 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 68/100
bombshell-dev/clack#573 · 1 条评论 · 2 个 reaction ·
查看 bombshell-dev/clack 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
melgarafael/DeskcommCRM#3000 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
callstackincubator/simlock#639 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 80/100
aws/agentcore-cli#2606 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 7 天内回复
-
ai-driven-qa bug Cosmetic
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复