Repository navigation
feat: 支持新提交 @ 首审唤醒、自定义前缀去重与存量评审群接管 - #3
Merged
Merged
Conversation
…e-existing PR group adoption - Add backward-compatible RepoRule fields `mentionKickoffOnNewCommit`, `newCommitPromptTemplate`, and `existingGroupPrefixTemplate` - Extend `HostBridge.sendFollowUpUpdate()` to resolve creator-scoped kickoff bot Feishu/Lark `open_id` without cross-app confusion, prepending `<at user_id="ou_..."></at> ` on new commits while keeping idempotent `dedupSeed`/`requestId` and `MAX_IPC_TEXT_BYTES` boundaries - Support safe template variables in `buildNewCommitMessage()` with `<at>`/`@all` neutralization and `<untrusted_pr_metadata>` isolation - Add strict start-anchored delimiter prefix matching (`existingGroupPrefixTemplate` and safe derivation from `groupNameTemplate`) in `groupNameMatchesPr()` - Add `POST /api/adopt-group`, `POST /api/adopt-groups`, CLI `github:adopt-group` / `github:adopt-groups`, Dashboard collapsible fields and diagnostics adopt controls, plus full unit/integration tests and EN/ZH README docs Co-Authored-By: Claude Code <[email protected]>
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.
背景与目标
基于
origin/main(v0.1.0)实现两项完全通用、向后兼容的增强能力(对v0.1.0已有config.json与state.json零 breaking change),使@botmux-ai/plugin-github能够完整承接 PR 自动建群、存量评审群接管与新提交唤醒首审复核流程:onNewCommit支持@首审 Bot 唤醒复审与自定义新提交提醒模板设计说明
1.
onNewCommit首审唤醒与自定义提醒模板src/types.ts、src/config/schema.ts):在RepoRule新增向后兼容的可选字段:mentionKickoffOnNewCommit?: boolean(默认false)newCommitPromptTemplate?: string(默认空字符串,为空时逐字节保持现有buildNewCommitMessage()默认格式)src/engine/rules.ts):buildNewCommitMessage()在模板非空时支持单遍安全变量替换:{{repo}}、{{prNumber}}、{{headSha}}、{{shortHeadSha}}、{{previousHeadSha}}、{{shortPreviousHeadSha}}、{{url}}、{{author}}、{{title}};sanitizeUntrustedText()/sanitizeSafeHttpUrl()清洗(中和<at>、@all、@everyone、尖括号、控制字符、BiDi 与 Unicode Tag 字符),免疫 JSString.replace$&/ 双重展开;<untrusted_pr_metadata ...>...</untrusted_pr_metadata>隔离信封,严格控制在MAX_IPC_TEXT_BYTES(8192 字节)以内,绝不截断闭合边界。@提及与幂等性(src/host/bridge.ts、src/engine/watcher.ts):HostBridge.sendFollowUpUpdate()支持可选kickoffBotAppId,复用resolveCreatorScopedKickoffOpenId()按creatorLarkAppId域解析首审 Bot 飞书open_id;botOpenId、非可提及成员与自@;解析失败时在events.jsonl写入warn事件(followup_mention_unresolved)并返回告警字段,绝不静默发错@;<at user_id="ou_..."></at>前缀(与首审 kickoff 一致),配合 180 字节预留预算与prependPrefixWithinUtf8Limit()兜底保护,完整兼容原有幂等dedupSeed/requestId机制。2. 自定义群名前缀去重与存量 PR 评审群安全接管
src/config/prefix.ts、src/config/schema.ts、src/host/bridge.ts):RepoRule新增可选字段existingGroupPrefixTemplate?: string(如pr {{prNumber}});{{prNumber}}、仅允许{{prNumber}}/{{repo}}、禁止控制符与换行、无{{repo}}时要求至少 2 字符且含字母/汉字的静态前缀,拒绝{{prNumber}}/#{{prNumber}}等过宽模式;groupNameMatchesPr()支持显式existingGroupPrefixTemplate;当其留空且groupNameTemplate以固定前缀 +{{prNumber}}+ 分隔符开头(如pr {{prNumber}} {{title}})时自动推导同等严格的边界前缀(若{{prNumber}}后紧跟{{repo}}则保留{{repo}}并排除-边界,避免如acme/botmux误匹配acme/botmux-plugin-github);(?=$|[\s\-::]),杜绝pr 91误匹配pr 919及 PR 标题正文中的pr 51/#51劫持去重。src/engine/watcher.ts、src/service/runner.ts、src/server/settings.ts、src/cli/index.ts、scripts/validate.mjs):POST /api/adopt-group、POST /api/adopt-groups与 CLI 命令:botmux github:adopt-group <owner/repo#N> <oc_chatId> [--dry-run] [--json]botmux github:adopt-groups [--repo owner/repo] [--dry-run] [--json]dist/cli/commands.json自动同步生成 6 个命令,scripts/validate.mjs同步校验全部 6 个命令。PrGroupRecord新增可选字段adopted?: boolean,isPrGroupComplete()识别已接管群(无需伪造历史kickoffMessageId),确保后续轮询不重发 kickoff、不重置顶、不重发 PR 评论,而新 commit 立即触发onNewCommit+@唤醒首审。src/dashboard/helpers.ts、src/dashboard/index.ts、README.md):existingGroupPrefixTemplate,并在勾选onNewCommit时展示mentionKickoffOnNewCommit与newCommitPromptTemplate(附kickoffBotAppId依赖提示),同步计入「已自定义 N 项」徽标;已接管;README.md。安全与幂等边界
open_id零混用:sendFollowUpUpdate()严格通过 creator 域bot-openids-<creator>.json/members-display解析,拒绝 foreign self-viewbotOpenId,失败记warn绝不发错@。@注入:newCommitPromptTemplate全部不可信变量中和<at>/@all/ 尖括号并附带<untrusted_pr_metadata>,严格受MAX_IPC_TEXT_BYTES约束。pr 91不撞pr 919,acme/botmux不撞acme/botmux-plugin-github,标题正文不劫持),显式existingGroupPrefixTemplate覆盖自动推导前缀。oc_...格式合法、且chatId真实存在于listCreatorGroups(rule.creatorBotAppId);多群命中同一 PR、同一群跨仓命中多个 PR、或chatId已被其他 PR 绑定时一律标记conflict跳过并报告(HTTP 409 / 详细清单),绝不猜错;遇到creating+outcomeUnknown进行中锁同样跳过不覆盖。--dry-run严格零副作用:不写state.json、不写events.jsonl、不发任何飞书消息。测试与自检结果
npm run typecheck:通过npm run build:通过(生成 6 个 CLI 命令,dist/dashboard/index.js零node:*/react依赖)npm run validate:通过(含独立dist/沙箱验证与commands.json6 命令校验)npm run test:unit:35 / 35 通过newCommitPromptTemplate全变量渲染与<at>/@all/XML 注入中和、MAX_IPC_TEXT_BYTES预算;existingGroupPrefixTemplate校验与推导、pr 91vspr 919、acme/botmuxvsacme/botmux-plugin-github、标题防劫持、显式前缀覆盖推导前缀;v0.1.0配置零破坏兼容;Dashboard helpers 徽标计数与往返校验。npm run test:integration:43 / 43 通过(含npm packNode + Bun 独立运行验证)onNewCommitcreator-scopedopen_id解析与失败隔离告警;自定义/推导前缀防止历史群pr 4042 xxx重复建群;adopt-group/adopt-groups通过控制接口与编译后 CLI 的正常接管、幂等性、非法/伪造chatId拒绝、多群冲突跳过、--dry-run字节级零副作用;接管后推送新 commit 立即触发@首审唤醒;Dashboard 新高级字段与诊断区接管按钮端到端渲染。{{repo}}末尾-连字符跨仓碰撞边界、显式前缀覆盖推导前缀、CLI 非 summary 错误响应防护、adoptGroupsPhase 3outcomeUnknownTOCTOU 防护、Dashboard 接管面板展示 errors/warnings/conflictPrKeys)并复跑全套测试绿色通过。🤖 Generated with Claude Code