Skip to content

Commit a2bd270

Browse files
hwchwc
authored andcommitted
fix: guard process-group kill (upstream anomalyco#45938); configurable question toggle key + space (upstream anomalyco#46093)
1 parent 24f9529 commit a2bd270

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎packages/core/src/shell.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,21 @@ export async function killTree(proc: ChildProcess, opts?: { exited?: () => boole
4545
}
4646

4747
try {
48-
process.kill(-pid, "SIGTERM")
49-
await sleep(SIGKILL_TIMEOUT_MS)
50-
if (!opts?.exited?.()) {
51-
process.kill(-pid, "SIGKILL")
48+
// 组击杀只对"独立进程组"(我们以 detached 拉起的子进程)安全。
49+
// pid 为 0/1 时 kill(-pid) 等价于 kill(0)/(-1), 会把信号广播到调用者所在组乃至全部用户进程
50+
// (上游 #45938: macOS 上退出时误杀用户整个终端会话/其他应用)。
51+
if (pid > 1) {
52+
process.kill(-pid, "SIGTERM")
53+
await sleep(SIGKILL_TIMEOUT_MS)
54+
if (!opts?.exited?.()) {
55+
process.kill(-pid, "SIGKILL")
56+
}
57+
} else {
58+
proc.kill("SIGTERM")
59+
await sleep(SIGKILL_TIMEOUT_MS)
60+
if (!opts?.exited?.()) {
61+
proc.kill("SIGKILL")
62+
}
5263
}
5364
} catch {
5465
proc.kill("SIGTERM")

‎packages/tui/src/config/keybind.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export const Definitions = {
208208
"dialog.select.submit": keybind("return", "Submit selected dialog item"),
209209
"dialog.prompt.submit": keybind("return", "Submit dialog prompt"),
210210
"dialog.mcp.toggle": keybind("space", "Toggle MCP in MCP dialog"),
211+
"question.toggle": keybind("space", "Toggle answer option"),
211212
"dialog.move_session.new": keybind("ctrl+m", "New project copy"),
212213
"dialog.move_session.delete": keybind("ctrl+d", "Delete project copy"),
213214
"dialog.move_session.refresh": keybind("ctrl+r", "Refresh project copies"),

‎packages/tui/src/i18n/en.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ export const dict: Dict = {
117117
"question.reject": "Reject question",
118118
"question.submitAnswer": "Submit answer",
119119
"question.confirm": "Confirm",
120+
"question.selectAnswer": "Toggle answer option",
121+
"question.toggle.desc": "切换答案选项",
120122

121123
// Sidebar
122124
"sidebar.context": "Context",

‎packages/tui/src/i18n/zh.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ export const dict: Dict = {
117117
"question.reject": "拒绝问题",
118118
"question.submitAnswer": "提交答案",
119119
"question.confirm": "确认",
120+
"question.selectAnswer": "Toggle answer option",
121+
"question.toggle.desc": "切换答案选项",
120122

121123
// Sidebar
122124
"sidebar.context": "上下文",

‎packages/tui/src/routes/session/question.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,17 @@ export function QuestionPrompt(props: { request: QuestionRequest; directory?: st
278278
},
279279
{ key: "down", desc: "Next answer", group: "Question", cmd: () => moveTo((store.selected + 1) % total) },
280280
{ key: "j", desc: "Next answer", group: "Question", cmd: () => moveTo((store.selected + 1) % total) },
281-
{ key: "return", desc: "Select answer", group: "Question", cmd: () => selectOption() },
281+
{ key: "return", desc: t("question.selectAnswer"), group: "Question", cmd: () => selectOption() },
282+
...(multi()
283+
? [
284+
...tuiConfig.keybinds.get("question.toggle").map((binding) => ({
285+
...binding,
286+
desc: t("question.toggle.desc"),
287+
group: "Question",
288+
cmd: () => selectOption(),
289+
})),
290+
]
291+
: []),
282292
{ key: "escape", desc: t("question.reject"), group: "Question", cmd: () => reject() },
283293
...tuiConfig.keybinds.get("app.exit"),
284294
]),

0 commit comments

Comments
 (0)