diff --git a/scripts/adopt-existing.py b/scripts/adopt-existing.py index 8044994..8100874 100755 --- a/scripts/adopt-existing.py +++ b/scripts/adopt-existing.py @@ -205,12 +205,19 @@ def agents_md(repo: str, rep: dict): branch_line = (f"| 默认分支 | `{rep['default_branch']}` —— 已启用分支保护(禁直推 + 必须 PR) |" if rep.get("protections") else f"| 默认分支 | `{rep['default_branch']}` —— **直推**(默认不开分支保护,正本 §1.3) |") + # 用 .get() 而不是下标:缺 key 时抛 KeyError 会**掩盖**下面那条真正要报的错 + # (实测:夹具少一个 key,于是"锚点坏了"的自检报的是 KeyError,等于没验)。 + _wf = "、".join(rep.get("workflows") or []) or "(无)" + _ctx = "、".join(rep.get("contexts") or []) or "(无)" + _rn = "、".join(rep.get("runners") or []) or "(无本仓 runner —— 有工作流也会永远 queued)" + if rep.get("runners_scope"): + _rn += f"({rep['runners_scope']})" facts = "\n".join([ "## 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 ''} |", "", + f"| CI | 工作流 {_wf};status context {_ctx} |", + f"| Runner | {_rn} |", "", ]) # ⚠️ 锚点必须真的存在。`str.replace` 找不到时**静默返回原文**,不会报错 —— # 实测踩过:锚点写成 `## 2. 硬约束`(骨架里其实是 `## 1. 硬约束`),