From bcdeb7f927ce9eb3e37a4900ad439184ae23aec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Sat, 10 Oct 2026 18:06:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(adopt):=20=E7=94=9F=E6=88=90=E5=99=A8?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E7=8E=B0=E7=8A=B6=E8=A1=A8=E7=9A=84=E9=94=9A?= =?UTF-8?q?=E7=82=B9=E5=86=99=E9=94=99=EF=BC=8C=E4=B8=94=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E6=98=AF=E9=9D=99=E9=BB=98=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一提交(d80b30e)里那句"验证:对两种 rep 各生成一次,落到 AGENTS.md 的那行 分别正确"**是不成立的** —— 验证脚本当场 IndexError,我却先把提交信息写好了。 如实纠正,并把挖出来的真 bug 修掉: 根因:`agents_md` 用 `body.replace("## 2. 硬约束", …)` 插入现状表, 而骨架里的实际标题是 `## 1. 硬约束`。`str.replace` 找不到时**静默返回原文**, 不抛错、不警告 ⇒ 这张"接入时核实的现状"表**从来没有被插进去过**, 而工具一切正常地"成功"了。这正是正本 §3.2-3 那条:断言校验器真的作用在目标上。 改法: - 锚点改成真实的 `## 1. 硬约束`,小节改名为 `## 0b.`(插在 §0 与 §1 之间,不改骨架编号) - 插入前**显式断言锚点存在**,不存在就带说明退出,不再静默 验证(本次真跑): - 对「没开保护 / 开了保护」两种 rep 各生成一次,生成物中 `| 默认分支` 那行分别正确, 且 `## 0b.` 确在 - 反向自检:把锚点改坏 → 报错退出(而不是照常返回一个缺了现状表的文件) --- scripts/adopt-existing.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/adopt-existing.py b/scripts/adopt-existing.py index b0d73a1..8044994 100755 --- a/scripts/adopt-existing.py +++ b/scripts/adopt-existing.py @@ -206,13 +206,20 @@ def agents_md(repo: str, rep: dict): if rep.get("protections") else f"| 默认分支 | `{rep['default_branch']}` —— **直推**(默认不开分支保护,正本 §1.3) |") facts = "\n".join([ - "## 1b. 接入时核实的现状(事实变了就更新;别让它过期)", "", + "## 0b. 接入时核实的现状(事实变了就更新;别让它过期)", "", "| 项 | 值 |", "|---|---|", branch_line, f"| CI | 工作流 {rep['workflows'] or '(无)'};status context {rep['contexts'] or '(无)'} |", f"| Runner | {rep['runners'] or '(无本仓 runner —— 有工作流也会永远 queued)'}{'(' + rep['runners_scope'] + ')' if rep['runners_scope'] else ''} |", "", ]) - return body.replace("## 2. 硬约束", facts + "\n## 2. 硬约束", 1) + # ⚠️ 锚点必须真的存在。`str.replace` 找不到时**静默返回原文**,不会报错 —— + # 实测踩过:锚点写成 `## 2. 硬约束`(骨架里其实是 `## 1. 硬约束`), + # 于是这张现状表从来没被插进去,而工具一切正常地"成功"了。 + # 所以这里显式断言锚点存在(正本 §3.2-3:断言校验器真的作用在目标上)。 + anchor = "## 1. 硬约束" + if anchor not in body: + sys.exit(f"❌ AGENTS 骨架里找不到锚点 {anchor!r};现状表会**静默**插不进去,先修锚点再跑") + return body.replace(anchor, facts + "\n" + anchor, 1) def run_git(*args, cwd=None, stdin=None):