Skip to content

Conversation

@lyjjl
Copy link
Contributor

@lyjjl lyjjl commented Jan 2, 2026

由 Sourcery 提供的摘要

改进 Linux 启动脚本,以更安全地处理 Ctrl+C,简化交互式提示,并精简 QQ/PMHQ/LLBot 的环境和依赖设置。

错误修复(Bug Fixes):

  • 通过更健壮地保护和捕获信号,防止在选择和清理过程中多次按下 Ctrl+C 导致的崩溃。
  • 在关机和恢复流程中,避免对空或无效的 PMHQ 进程 ID 执行信号操作。
  • 确保交互式提示从 TTY 读取输入,以避免在 stdin 被重定向时出现问题。

增强内容(Enhancements):

  • 使用一秒倒计时循环优化关机提示,并提供更清晰的默认行为说明。
  • 合并并简化发行版检测、QQ 安装逻辑,以及针对 Arch 和基于 Debian 系统的依赖安装流程。
  • 统一并收紧针对 X11/Wayland 和输入法的环境变量配置。
  • 通过内联简单条件并复用诸如 PMHQ 二进制路径等公共变量,减少脚本的冗长输出和重复代码。
  • 使 LLBot 启动日志和模式选择更清晰,并略微精简运行命令的构造流程。
Original summary in English

Summary by Sourcery

Improve the Linux startup script to handle Ctrl+C more safely, simplify interactive prompts, and streamline environment and dependency setup for QQ/PMHQ/LLBot.

Bug Fixes:

  • Prevent crashes caused by repeated Ctrl+C during selection and cleanup by guarding and trapping signals more robustly.
  • Avoid signal operations on empty or invalid PMHQ process IDs during shutdown and resume flows.
  • Ensure interactive prompts read from the TTY to avoid issues when stdin is redirected.

Enhancements:

  • Refine shutdown prompt with a one-second countdown loop and clearer default behavior messaging.
  • Consolidate and simplify distro detection, QQ installation logic, and dependency installation for Arch and Debian-based systems.
  • Unify and tighten environment variable configuration for X11/Wayland and input methods.
  • Reduce script verbosity and duplication by inlining simple conditionals and reusing common variables like the PMHQ binary path.
  • Ensure LLBot startup logs and mode selection are clearer and slightly streamline the run command construction.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 2, 2026

审阅者指南

此 PR 强化了 Linux 启动脚本在选择/清理过程中的 Ctrl+C 相关崩溃防护,简化了多处控制流,并提升了在 Linux 上运行 LLBot/PMHQ 时的进程处理、发行版特定安装以及交互式输入处理的健壮性。

文件级变更

变更 详情 文件
使清理和信号处理在重复 Ctrl+C 和缺失 PMHQ PID 的情况下更加稳健,防止在关机或进程被分离时崩溃。
  • 引入 CLEANING 状态标志并在 cleanup 中加入早返回保护,避免重入
  • 为 SIGINT/SIGTERM 安装 trap,并在 cleanup 内部临时忽略后续的 SIGINT/SIGTERM,避免清理过程中被中断
  • 在调用 kill 和 kill -9/-TERM/-CONT 时增加非空 PID 检查,并更防御性地使用进程组 ID
  • 调整进程清理和后台进程继续运行相关的日志信息
script/start-linux.sh
重构交互式提示(模式选择、清理确认、sudo 检查、确认助手),使其在 stdin 被管道传入时依然更加可靠、具备超时感知且对 tty 安全。
  • 使用 `sudo -v
简化针对 Arch 和 Debian 系发行版的依赖安装逻辑。
  • 将 PMHQ_BIN 抽取为从 SCRIPT_DIR 计算得到的可复用变量
  • 使用精简条件表达式在 Arch 和 Debian 安装函数之间进行选择
  • 在 Arch 安装中简化 yay 安装流程:先尝试 pacman,再回退到 AUR clone/makepkg,去掉多余的清理步骤
  • 在 Debian 安装中,将架构检测简化为紧凑表达式,略微缩短错误信息,并始终通过 apt-get 安装 ffmpeg 和 xvfb,而不是扫描缺失二进制文件
  • 调整 QQ 依赖安装日志以及 ALSA 库选择,使用结合 apt-cache show 的更短条件表达式
script/start-linux.sh
收紧在 X11/Wayland 与无头/GUI 模式下的环境配置、权限配置以及输入法相关标志。
  • 针对 Wayland 与 X11 分别计算 IM_ENV:确保始终设置基础 XMODIFIERS,并仅在 X11 下扩展工具包特定变量
  • 避免关于 xauth/Wayland/X11 检测的冗余日志,只在必要时使用最小化的 xhost 配置
  • 使用精简条件逻辑在清理时调用 xhost -local,在非 Arch 的 GUI 运行中调用 xhost +local
  • 使用 PMHQ_BIN 为 node 和 PMHQ 设置可执行位,并确保 llbot 目录的所有权归当前用户
script/start-linux.sh
重构 LLBot 启动路径构造和等待行为,使其更直接、更健壮。
  • 将 NODE_BIN 和 LLBOT_JS 直接内联到 sub_cmd 组合中,而不是单独变量
  • 压缩 LLBot 启动日志,使其更简短并聚焦于所选模式
  • 在 xvfb-run 和直接调用 PMHQ 时一致性地使用 env $IM_ENV
  • 对 PMHQ_PID 调用 wait 时忽略错误,避免 wait 失败导致脚本退出
script/start-linux.sh

Tips and commands

与 Sourcery 交互

  • 触发新评审: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub Issue: 回复 Sourcery 的某条评审评论,请它从该评论创建 issue。也可以直接回复该评论 @sourcery-ai issue 来创建 issue。
  • 生成 Pull Request 标题: 在 PR 标题中任意位置写上 @sourcery-ai,即可随时生成标题。也可以在 PR 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 PR 正文任意位置写上 @sourcery-ai summary,即可在对应位置生成 PR 摘要。也可以在 PR 中评论 @sourcery-ai summary 来随时(重新)生成摘要。
  • 生成审阅者指南: 在 PR 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 一次性解决所有 Sourcery 评论: 在 PR 中评论 @sourcery-ai resolve 来标记解决所有 Sourcery 评论。如果你已经处理完所有评论且不再希望看到它们,这会很有用。
  • 一次性撤销所有 Sourcery 评审: 在 PR 中评论 @sourcery-ai dismiss 以撤销所有现有的 Sourcery 评审。尤其适用于你想从头开始新一轮评审的情况——别忘了再评论 @sourcery-ai review 触发新评审!

自定义你的使用体验

访问你的 控制面板 来:

  • 启用或禁用评审功能,比如 Sourcery 生成的 PR 摘要、审阅者指南等。
  • 修改评审语言。
  • 添加、删除或编辑自定义评审指令。
  • 调整其它评审设置。

获取帮助

Original review guide in English

Reviewer's Guide

This PR hardens the Linux start script against Ctrl+C-related crashes during selection/cleanup, simplifies several control flows, and improves robustness of process handling, distro-specific setup, and interactive input handling when running LLBot/PMHQ on Linux.

File-Level Changes

Change Details Files
Make cleanup and signal handling robust against repeated Ctrl+C and missing PMHQ PID, preventing crashes during shutdown or when processes are detached.
  • Introduce CLEANING state flag and early-return guard in cleanup to avoid re-entrancy
  • Install a trap for SIGINT/SIGTERM and, inside cleanup, temporarily ignore further SIGINT/SIGTERM to avoid mid-cleanup interruption
  • Guard kill and kill -9/-TERM/-CONT calls with non-empty PID checks and use process group IDs more defensively
  • Adjust log messages around process cleanup and background process continuation
script/start-linux.sh
Rework interactive prompts (mode selection, cleanup confirmation, sudo check, confirm helper) to be more reliable, timeout-aware, and tty-safe even when stdin is piped.
  • Use sudo -v
Simplify distro-specific install logic and dependency handling for Arch and Debian-based systems.
  • Factor PMHQ_BIN as a reusable variable computed from SCRIPT_DIR
  • Use a condensed conditional to choose between Arch and Debian install functions
  • In Arch install, simplify yay installation: first try pacman, then fall back to AUR clone/makepkg without redundant cleanup
  • In Debian install, simplify architecture detection into a compact expression, slightly shorten error messages, and always install ffmpeg and xvfb via apt-get instead of scanning for missing binaries
  • Adjust QQ dependency installation messages and ALSA library selection using a shorter conditional with apt-cache show
script/start-linux.sh
Tighten environment setup, permission configuration, and input method flags across X11/Wayland and headless/GUI modes.
  • Compute IM_ENV differently for Wayland vs X11, ensuring a base XMODIFIERS and extending with toolkit-specific variables only for X11
  • Avoid noisy logs about xauth/Wayland/X11 detection and rely on minimal xhost configuration when necessary
  • Use a compact conditional to call xhost -local for cleanup and +local for non-Arch GUI runs
  • Set executable bits on node and PMHQ using PMHQ_BIN and ensure ownership of the llbot directory for the current user
script/start-linux.sh
Refactor LLBot launch path construction and waiting behavior to be more direct and resilient.
  • Inline NODE_BIN and LLBOT_JS into the sub_cmd composition instead of separate variables
  • Adjust LLBot startup logs to be shorter and focus on the selected mode
  • Use env $IM_ENV consistently for xvfb-run and direct PMHQ invocations
  • Wait on PMHQ_PID with errors ignored to avoid script termination if wait fails
script/start-linux.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:

  • 现在 Debian 的架构检测会将所有非 x86_64 的机器默认视为 arm64(local ARCH=$([ "$MACHINE" == "x86_64" ] && echo "amd64" || echo "arm64")),这会把之前在不支持架构上显式报错的行为改成静默地选择错误的架构;建议保留一个显式的 case 分支或在未知架构上保留报错路径。
  • install_arch 中,用于克隆并构建 yay 的回退路径在执行完 makepkg -si 后,不再删除 /tmp/yay_install,这与之前的版本行为不同,并可能在 /tmp 中留下过期的构建产物;建议恢复清理步骤。
给 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- The Debian architecture detection now defaults any non-x86_64 machine to arm64 (`local ARCH=$([ "$MACHINE" == "x86_64" ] && echo "amd64" || echo "arm64")`), which changes the previous explicit error on unsupported architectures into a silent wrong-arch selection; consider keeping an explicit case statement or error path for unknown architectures.
- In `install_arch`, the fallback path that clones and builds yay no longer removes `/tmp/yay_install` after `makepkg -si`, which changes behavior from the previous version and can leave stale build artifacts in /tmp; consider restoring the cleanup step.

## Individual Comments

### Comment 1
<location> `script/start-linux.sh:157` </location>
<code_context>
-        aarch64) ARCH="arm64" ;;
-        *)       error "不支持的架构: $MACHINE" ;;
-    esac
+    local ARCH=$([ "$MACHINE" == "x86_64" ] && echo "amd64" || echo "arm64")

     if [ ! -f "/opt/QQ/qq" ] && confirm "未检测到 QQ,是否安装?"; then
</code_context>

<issue_to_address>
**issue:** Architecture detection now treats all non-x86_64 as arm64, which can mis-handle unsupported architectures.

The previous version explicitly errored on unsupported architectures. Now, anything not `x86_64` is treated as `arm64`, which will be wrong on e.g. `armv7l` or `riscv64` and will attempt to install an invalid package instead of failing fast. Consider reintroducing explicit validation, for example:

```bash
case "$MACHINE" in
  x86_64)  ARCH="amd64" ;;
  aarch64) ARCH="arm64" ;;
  *)       error "不支持的架构: $MACHINE" ;;
esac
```

or keep the one-liner but guard it with a `case`/`if` that errors on unknown architectures.
</issue_to_address>

Sourcery 对开源项目免费——如果你觉得我们的代码审查有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • The Debian architecture detection now defaults any non-x86_64 machine to arm64 (local ARCH=$([ "$MACHINE" == "x86_64" ] && echo "amd64" || echo "arm64")), which changes the previous explicit error on unsupported architectures into a silent wrong-arch selection; consider keeping an explicit case statement or error path for unknown architectures.
  • In install_arch, the fallback path that clones and builds yay no longer removes /tmp/yay_install after makepkg -si, which changes behavior from the previous version and can leave stale build artifacts in /tmp; consider restoring the cleanup step.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The Debian architecture detection now defaults any non-x86_64 machine to arm64 (`local ARCH=$([ "$MACHINE" == "x86_64" ] && echo "amd64" || echo "arm64")`), which changes the previous explicit error on unsupported architectures into a silent wrong-arch selection; consider keeping an explicit case statement or error path for unknown architectures.
- In `install_arch`, the fallback path that clones and builds yay no longer removes `/tmp/yay_install` after `makepkg -si`, which changes behavior from the previous version and can leave stale build artifacts in /tmp; consider restoring the cleanup step.

## Individual Comments

### Comment 1
<location> `script/start-linux.sh:157` </location>
<code_context>
-        aarch64) ARCH="arm64" ;;
-        *)       error "不支持的架构: $MACHINE" ;;
-    esac
+    local ARCH=$([ "$MACHINE" == "x86_64" ] && echo "amd64" || echo "arm64")

     if [ ! -f "/opt/QQ/qq" ] && confirm "未检测到 QQ,是否安装?"; then
</code_context>

<issue_to_address>
**issue:** Architecture detection now treats all non-x86_64 as arm64, which can mis-handle unsupported architectures.

The previous version explicitly errored on unsupported architectures. Now, anything not `x86_64` is treated as `arm64`, which will be wrong on e.g. `armv7l` or `riscv64` and will attempt to install an invalid package instead of failing fast. Consider reintroducing explicit validation, for example:

```bash
case "$MACHINE" in
  x86_64)  ARCH="amd64" ;;
  aarch64) ARCH="arm64" ;;
  *)       error "不支持的架构: $MACHINE" ;;
esac
```

or keep the one-liner but guard it with a `case`/`if` that errors on unknown architectures.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@lyjjl
Copy link
Contributor Author

lyjjl commented Jan 2, 2026

fix issue #673

@linyuchen linyuchen changed the base branch from main to dev January 2, 2026 09:54
@linyuchen linyuchen merged commit 18e7133 into LLOneBot:dev Jan 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants