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):