Skip to content

feat(channels): install-service — one command to run channels start at login/boot#60

Merged
Germey merged 1 commit into
mainfrom
feat/channels-install-service
Jul 4, 2026
Merged

feat(channels): install-service — one command to run channels start at login/boot#60
Germey merged 1 commit into
mainfrom
feat/channels-install-service

Conversation

@acedatacloud-dev

Copy link
Copy Markdown
Member

What & why

要让聊天桥接跨重启常驻,以前得手动照抄 docs/deploy/ 里的 systemd/launchd/NSSM 模板。coding-bridge channels install-service 现在检测平台,写一个用户级服务单元(已填好当前 python + config dir),并打印一条启用命令:

  • Linux → systemd user unit ~/.config/systemd/user/coding-bridge-channels.service
  • macOS → launchd LaunchAgent ~/Library/LaunchAgents/cloud.acedata.coding-bridge-channels.plist
  • Windowsrun-channels.cmd(写在 config dir)+ 一条 schtasks /create … /sc onlogon 命令

安全

只写一个用户级文件 + 打印启用命令 —— 绝不自己 enable/start 服务,也不做任何提权/系统级操作。不带 --force 时拒绝覆盖已有单元。

Testing

  • ruff clean;channels/service.py 是纯渲染,单测 7 个(3 平台 + 不支持平台 + XML 转义 + token 提示 + 控制字符拒绝);全套件 504 pass / 1 skip
  • 手动跑 channels install-service(Windows, tmp config dir)生成了正确的 run-channels.cmd("D:\...\python.exe" -m coding_bridge channels start)+ schtasks 激活命令。

🤖 对抗评审

Reviewer: Claude general-purpose subagent(此机无 Codex),read-only,一轮。VERDICT: ISSUES FOUND — 4 个路径注入健壮性项,已 fix-or-rebut:

  • RISK 1 — systemd ExecStart 未加引号(python 路径含空格会断)。FIXED:ExecStart="{python}" -m …(systemd 双引号语义 = 单 token)。
  • RISK 2 — systemd Environment= 未转义(config_dir 含换行可注入第二条指令)。FIXED:Environment="CODING_BRIDGE_CONFIG_DIR=…" + 新增控制字符校验(python/config 路径含 \n/\r/任意 <0x20 → ValueError,fail fast 不生成危险单元)。
  • RISK 3 / 4 — Windows .cmd / 打印的 schtasks 命令的引号注入(config_dir 含 ")。部分 FIXED + REBUTTED:控制字符校验已堵住换行向量;引号向量 rebut —— Windows 文件系统禁止路径含 ",.cmdset "VAR=…" 引号形式对 & < > | 是字面量安全的,且 schtasks 行是打印给操作者手动执行(非 subprocess),不是自动运行。

已确认无问题项:从不执行激活命令 / 不碰系统级路径;launchd 用 xml.sax.saxutils.escape;platform.system().lower() 一致匹配;mkdir(parents=True) + 无 --force 拒绝覆盖 + OSError 干净报错(无 traceback)。

新增测试 test_rejects_control_char_in_path 固化了 RISK 2 的修复。

Keeping the chat bridge running across reboots meant hand-copying a docs/deploy template. This command detects the platform and writes a user-scoped unit (systemd user unit, launchd LaunchAgent, or a run-channels.cmd plus a schtasks command) pre-filled with this python and config dir, then prints the single command to enable it.

Safety: only writes a user-scoped file and prints the activation command; never enables/starts the service or does anything privileged. Refuses to overwrite an existing unit without --force.

service.py is pure rendering, unit-tested (7 tests). Full suite 504 pass/1 skip. Adversarial review found 4 path-injection robustness items: fixed by quoting systemd ExecStart+Environment and a control-char guard (newline/CR in python/config path raises ValueError); residual Windows quote cases rebutted (filesystem forbids quotes in paths; schtasks line is printed, not executed).
@Germey Germey merged commit 342a743 into main Jul 4, 2026
3 checks passed
@Germey Germey deleted the feat/channels-install-service branch July 4, 2026 08:04
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