feat(channels): install-service — one command to run channels start at login/boot#60
Merged
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
要让聊天桥接跨重启常驻,以前得手动照抄
docs/deploy/里的 systemd/launchd/NSSM 模板。coding-bridge channels install-service现在检测平台,写一个用户级服务单元(已填好当前 python + config dir),并打印一条启用命令:~/.config/systemd/user/coding-bridge-channels.service~/Library/LaunchAgents/cloud.acedata.coding-bridge-channels.plistrun-channels.cmd(写在 config dir)+ 一条schtasks /create … /sc onlogon命令安全
只写一个用户级文件 + 打印启用命令 —— 绝不自己 enable/start 服务,也不做任何提权/系统级操作。不带
--force时拒绝覆盖已有单元。Testing
ruffclean;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-purposesubagent(此机无 Codex),read-only,一轮。VERDICT: ISSUES FOUND — 4 个路径注入健壮性项,已 fix-or-rebut:ExecStart未加引号(python 路径含空格会断)。FIXED:ExecStart="{python}" -m …(systemd 双引号语义 = 单 token)。Environment=未转义(config_dir 含换行可注入第二条指令)。FIXED:Environment="CODING_BRIDGE_CONFIG_DIR=…"+ 新增控制字符校验(python/config 路径含\n/\r/任意 <0x20 →ValueError,fail fast 不生成危险单元)。.cmd/ 打印的schtasks命令的引号注入(config_dir 含")。部分 FIXED + REBUTTED:控制字符校验已堵住换行向量;引号向量 rebut —— Windows 文件系统禁止路径含",.cmd的set "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 的修复。