claude-code-best/scripts
IronRookieCoder 223b694965 fix(windows): prevent terminal startup failures
## Bug 详情
- issues.md #46:Windows MSYS2/UCRT64 下执行 csc,欢迎信息输出后在 stdin raw mode/终端输入初始化阶段崩溃,出现 native std::bad_weak_ptr 和后续 Bun mutex corrupt。
- issues.md #47:cmd.exe 可启动,但 PowerShell 运行 csc 会走 npm 生成的 csc.ps1;截图显示 node.exe 报错 "Input must be provided either through stdin or as a prompt argument when using --print",说明裸 csc 被误判成 print/non-interactive 模式。

## 根因
- MSYS2/Cygwin/mintty 等 Windows 终端对 Node/Bun stdin raw mode 和终端扩展控制序列兼容性不稳定,启动早期强行 setRawMode/查询终端能力会触发崩溃风险。
- npm 的 PowerShell shim 解析优先级高于 csc.cmd,且可能让 stdout TTY 状态不可用;原 main.tsx 只要 stdout 非 TTY 就自动进入 non-interactive/--print 路径,最终在没有 prompt/stdin 时触发 #47 的报错。

## 修复方案
- 为 Ink stdin raw mode 增加 Windows 风险终端检测,在 MSYS2/Cygwin/mintty 或显式禁用开关下跳过 raw mode,使用 cooked input fallback。
- early input 捕获在启动早期复用同类风险判断,避免 REPL 渲染前就触发 raw mode 崩溃。
- postinstall 在 Windows 上清理属于本包的 csc.ps1,让 PowerShell 回落到与 cmd.exe 一致的 csc.cmd 启动路径。
- 新增 non-interactive 判定工具,保留显式 -p/--print、--init-only、--sdk-url 的 headless 行为,但要求 stdin/stdout 都不是交互 TTY 才自动进入 non-interactive,避免 PowerShell shim 下裸 csc 被误判。

## 变更要点
- 新增 packages/@ant/ink/src/core/raw-mode-support.ts 及单元测试,覆盖普通 Windows shell、MSYS2/Cygwin/mintty 和禁用开关
- 调整 Ink App raw mode 生命周期,只在真正启用 raw mode 后写入/清理 bracketed paste、focus reporting、extended key 等终端控制序列
- 调整 component unmount/exit 清理逻辑,按 rawModeEnabledCount/rawModeActive 关闭实际启用的输入监听和 raw mode
- 调整 src/utils/earlyInput.ts,避免不安全 Windows 终端在启动阶段启用 stdin raw mode
- 调整 scripts/postinstall.cjs,立即和延迟清理 npm 生成的 csc.ps1 shim
- 调整 src/main.tsx 使用 shouldUseNonInteractiveSession,并新增对应测试覆盖 PowerShell shim 场景

## 自测
- bun test packages/@ant/ink/src/core/__tests__/raw-mode-support.test.ts src/utils/__tests__/earlyInput.test.ts src/utils/__tests__/nonInteractiveSession.test.ts
- node --check scripts/postinstall.cjs
- bun run src/entrypoints/cli.tsx --version
- bun run lint
- git diff --check

## 已知限制
- bun run typecheck 仍失败,错误来自仓库既有缺失声明/缺失模块和无关类型问题,不来自本次改动。
2026-05-14 17:07:51 +08:00
..
check-bundle-integrity.ts style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
defines.ts chore: bump version to 4.0.17 2026-05-13 20:17:39 +08:00
dev-debug.ts style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
dev.ts fix: 使用 HTTPS + gh token 替代 SSH 克隆 review 仓库 2026-05-12 12:23:50 +08:00
dump-prompt.ts style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
generate-review-builtin.ts chore: switch review skill download branch to main 2026-05-12 20:51:25 +08:00
install-cosknow.mjs fix: install cosknow globally to always fetch latest version 2026-04-24 19:09:52 +08:00
post-build.ts build: Vite 单文件构建 + 修复 doubaoime-asr 打包后 WASM 加载失败 2026-05-03 16:13:20 +08:00
postinstall.cjs fix(windows): prevent terminal startup failures 2026-05-14 17:07:51 +08:00
probe-local-wiring.ts feat: 注册所有新命令到命令系统和工具注册表 2026-05-09 23:04:39 +08:00
probe-subscription-endpoints.ts fix: 进一步脱敏 probe-subscription-endpoints 日志中的 orgUUID 2026-05-10 13:14:22 +08:00
rcs-ccb.sh chore: 更新构建 feature 的问题 2026-04-19 08:27:25 +08:00
rcs.ts style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
run-parallel.mjs style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
setup-chrome-mcp.mjs style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
smoke-test-commands.ts feat: 注册所有新命令到命令系统和工具注册表 2026-05-09 23:04:39 +08:00
verify-autofix-pr.ts feat: 添加 GitHub 集成命令(issue、share、autofix-pr) 2026-05-09 23:04:23 +08:00
vite-plugin-feature-flags.ts style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
vite-plugin-import-meta-require.ts style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00