@autocodeflow/cli 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ui.js CHANGED
@@ -85,3 +85,51 @@ export function interruptExit() {
85
85
  process.stderr.write('\n');
86
86
  process.exit(EXIT_CODES.INTERRUPTED);
87
87
  }
88
+ /**
89
+ * 破坏性操作的交互确认 —— 三处 delete 此前各自内联 readline.question,
90
+ * 在 stdin 非交互(agent / CI / `< NUL`)时会**静默假绿**:
91
+ *
92
+ * $ acf app delete <id> < NUL
93
+ * Delete application <id>? [y/N] <- 提示打出后立刻 EOF
94
+ * $ echo $? -> 0,且既无 "Aborted." 也无错误行
95
+ *
96
+ * 后果是自动化面最危险的一类失败:agent 把「什么都没删」读成「删除成功」,
97
+ * 继续跑下游步骤。根因是 readline 在 EOF 时以空串 resolve(不是 reject),
98
+ * 调用方的 `/^y(es)?$/` 判否后走 "Aborted." 分支——而该分支在 Windows 上
99
+ * 连输出都会丢,进程以 0 收场。
100
+ *
101
+ * 语义(与 login 的 TOTP 非交互分支同一思路,收敛到一处):
102
+ * - `--yes` 给定 → 直接放行,不碰 stdin(脚本显式表态的唯一通路);
103
+ * - stdin 非 TTY → **拒绝**并给可操作错误(UsageError → 退出码 2)。既不
104
+ * 静默通过(会误删)也不静默取消(会假绿);
105
+ * - stdin 是 TTY → 交互提问;除 y/yes 外一律视为主动放弃,返回 false,
106
+ * 由调用方原样 return(退出码 0 —— README 已把「主动放弃确认」归入成功)。
107
+ *
108
+ * @returns true = 继续执行;false = 用户主动放弃(调用方应直接 return)。
109
+ */
110
+ export async function confirmDestructive(question, opts = {}) {
111
+ if (opts.yes)
112
+ return true;
113
+ if (process.stdin.isTTY !== true) {
114
+ emitUsageError('Confirmation cannot be read: stdin is not interactive. ' +
115
+ 'Re-run with --yes (-y) to confirm this destructive operation in non-interactive use ' +
116
+ '(CI / agent / piped stdin).');
117
+ }
118
+ const readline = await import('readline/promises');
119
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
120
+ // raw 模式下 Ctrl+C 触发 rl 'SIGINT' 而非进程信号;无监听只会 pause,
121
+ // 确认提示处会假死。接住并走统一中断出口(130)。
122
+ rl.on('SIGINT', () => interruptExit());
123
+ let answer;
124
+ try {
125
+ answer = await rl.question(`${question} [y/N] `);
126
+ }
127
+ finally {
128
+ rl.close();
129
+ }
130
+ if (!/^y(es)?$/i.test(answer)) {
131
+ console.log(chalk.yellow('Aborted.'));
132
+ return false;
133
+ }
134
+ return true;
135
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autocodeflow/cli",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "AutoCodeFlow CLI — manage tasks, executions and applications from the terminal",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",