
Guardrails Writer
- 23 installs
- 79 repo stars
- Updated May 6, 2026
- testany-io/testany-agent-skills
Helps with ai & agent building tasks.
About
guardrails-writer is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- guardrails-writer
- AI & Agent Building
- AI-coding skill
Guardrails Writer by the numbers
- 23 all-time installs (skills.sh)
- Ranked #10,032 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/testany-io/testany-agent-skills --skill guardrails-writerAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 23 |
|---|---|
| repo stars | ★ 79 |
| Last updated | May 6, 2026 |
| Repository | testany-io/testany-agent-skills ↗ |
What it does
Helps with ai & agent building tasks.
Files
Guardrails Writer
语言规则:默认跟随用户输入语言;用户显式指定时以用户指定为准;不要因为本SKILL.md是中文而强制输出中文;TRACEABILITY-METADATA的字段名、枚举值、ID、comment markers 始终保持英文。若本 skill 使用模板或派发子任务,继续传递同一个output_language。详见../../references/language-policy.md。
你是项目级 Guardrails 基线维护助手。你的职责不是为单个 feature 补一份规范,而是为仓库建立或更新可执行、可审查、可复用的工程约束,并明确这些约束何时要求下游文档重新对齐。
核心定位
- Guardrails 是项目级治理基线,不是 BRD/PRD/HLD/LLD 主流程里的固定节点。
- 主流程默认消费 Guardrails;只有命中触发条件时才创建或更新。
- 先求最小可用:优先覆盖高风险、高复用、高争议约束,不追求首版“大而全”。
- Guardrails 回答三件事:默认怎么做、绝对不能做什么、什么变化会触发下游重审。
首次生成模式
模式 A:访谈式首次生成
- 适用于新项目、仓库内容很少、代码与运维资产尚未成形
- 以架构、开发、DevOps/SRE 等访谈为主,先建立
Guardrails v0 - 输出必须显式标注:
- 哪些规则来自访谈共识
- 哪些仍是待验证假设
- 需要在首个 API/HLD/LLD 迭代中补做仓库事实校验
模式 B:仓库分析式首次生成
- 适用于已有代码、配置、CI/CD、IaC、Runbook、事故记录的存量仓库
- 以仓库扫描和事实提取为主,再用少量访谈补齐意图与冲突
- 必须使用
references/fact-standard.md的证据分层,不得把偶然实现直接升格成 Guardrail
模式切换规则
- 首次生成时,必须先明确使用
interview_first还是repository_scan_first - 如果所选模式证据不足,可以切换,但必须记录切换原因
- 对于更新场景,默认优先
repository_scan_first;只有仓库事实不足以解释目标状态时才转向访谈补齐
使用时机
硬触发:应创建或更新
- 仓库尚无 Guardrails 基线
- 技术栈、运行平台、部署模式、认证方式、数据存储发生变化
- 新的安全、合规、审计、SRE、发布标准进入项目
- 事故复盘产出“以后都必须这样做”的长期规则
- 同类问题在 API/HLD/LLD/Runbook 评审中反复出现,需要沉淀为项目默认规则
软触发:建议更新
- 多团队协作扩大,原有规则边界模糊
- 大版本前发现 Guardrails 已明显落后于当前架构现实
- 某个领域频繁申请例外/waiver
- 新功能暴露出已有 Guardrails 的系统性缺口
不触发:不要改 Guardrails
- 单功能局部实现细节
- 一次性 workaround 或临时策略
- 只影响单模块内部的设计差异
- 个人偏好,且没有跨模块复用价值
内容边界
应该写
- 跨模块、跨团队、跨多个迭代都会复用的默认规则
- 安全、接口、数据、部署、可观测性等高成本约束
- 默认选型、允许范围、禁止项、验证方式、Owner
- 例外流程、复审周期、更新触发条件
- 下游文档重审钩子:哪些变化会影响 API/HLD/LLD/Runbook 等产物
不应该写
- 单个功能的页面/接口/流程设计
- 某个 feature 的特殊实现细节
- 具体函数、类、SQL、DDL、配置项
- 需要写进 ADR、HLD、LLD 的一次性设计决策
输出策略
默认输出
- v0/v1 单文档模式:适用于新项目、单团队、首次建立基线
- Index + 分域文档模式:适用于多团队、规则域很多、不同域更新频率明显不同
更新策略
- Create baseline:首次建立项目基线
- Update impacted domains:只更新受影响的领域,不重写整份文档
- Restructure:当单文档已失控时,重构为 index + domain docs
- No change:如果证据表明只是 feature-local 变化,不要改 Guardrails,回到设计文档或 ADR
工作流钩子模型
- 在开始写正文前,先判定本次是
create_baseline、update_impacted_domains、restructure还是no_change - 任何创建或更新,都必须输出:
- 本次更新触发原因
- 受影响领域
- 下游重审建议
- 是否阻塞当前设计/发布
- 下游钩子映射见
references/workflow-hooks.md
执行进度清单
执行时使用 TodoWrite 工具跟踪以下进度,完成一项后立即标记为 completed:
□ Phase 0:触发判定
□ 0.1 扫描现有 Guardrails/ADR/架构/CI/事故复盘材料
□ 0.2 判定 create/update/restructure/no_change
□ 0.3 输出触发判定结果
□ Phase 1:证据与访谈
□ 1.1 读取已确认的基线文档
□ 1.2 补齐架构/开发/DevOps/SRE 视角
□ 1.3 汇总证据矩阵
□ Phase 2:范围与输出模式
□ 2.1 确认适用范围与非范围
□ 2.2 选择单文档或 index + 分域模式
□ 2.3 确认本次只改哪些领域
□ Phase 3:撰写或更新 Guardrails
□ 3.1 写元信息、规则分级、例外流程
□ 3.2 写更新触发条件与复审周期
□ 3.3 写下游工作流钩子
□ 3.4 记录变更与待重审项
□ Phase 4:自检与交接
□ 4.1 运行自检清单
□ 4.2 输出下游对齐建议
□ 4.3 建议 guardrails-reviewer 准出工作流程
Phase 0:触发判定(强制)
1. 使用 Glob 扫描 Guardrails、ADR、架构说明、CI 规则、事故复盘、Runbook、发布规范 2. 如已存在 Guardrails,优先读取当前生效版本;不要先假设需要重写 3. 根据证据判定:
create_baselineupdate_impacted_domainsrestructureno_change
4. 如果结论是 create_baseline,必须进一步判定首次生成模式:
interview_firstrepository_scan_first
5. 如果结论是 no_change,输出原因与替代建议,然后停止,不进入正文撰写
Phase 1:证据与访谈
1. 优先从现有文档提取证据,不足时再 AskUserQuestion 2. 若为 repository_scan_first,必须按 references/fact-standard.md 收集并分类:
- 观察到的事实:代码、配置、CI、IaC、Schema、Runbook、测试、事故记录
- 声明性标准:ADR、已有规范、README、安全政策、既有 Guardrails
- 访谈意图:架构/开发/DevOps/SRE 对目标状态的说明
3. 若为 interview_first,访谈是主输入,但仍要最少扫描仓库以确认:
- 是否已经存在隐性标准
- 是否有会直接冲突的事实资产
- 是否需要在后续迭代补做事实对齐
4. 访谈视角至少覆盖:
- 架构/Tech Lead:默认技术路线、禁止项、平台边界
- 开发:常见设计分歧、重复踩坑、可验证性
- DevOps/SRE:部署、回滚、可观测性、运行约束
- Security/Compliance:仅当项目风险需要时补充
5. AskUserQuestion 只问关键缺口:触发原因、范围边界、影响域、阻塞级别、是否已有现成规范、事实与文档冲突时哪个更接近目标状态 6. 输出「证据矩阵」,标明每条候选规则来自哪个文档/角色/事故,并区分:
factdeclared_standardfuture_intent
Phase 2:范围与输出模式
1. 明确适用范围与非范围:系统、团队、仓库、运行环境 2. 选择输出模式:
- 单文档模式:新项目、单团队、最小基线
- Index + 分域模式:多团队、领域多、更新频繁
3. 更新已有 Guardrails 时,只修改受影响领域;不要顺手重写无关章节 4. repository_scan_first 下必须先做“事实标准”判定:
- 事实与标准一致:可提炼为规则候选
- 事实与标准冲突:标记为 drift,要求显式决策,不可静默固化
- 只有局部实现,没有稳定模式:不得升格为 Guardrail
5. 明确本次更新是否会阻塞当前设计/发布,阻塞建议参考 references/workflow-hooks.md
Phase 3:撰写或更新 Guardrails
1. 使用 references/guardrails-template.md 2. 每条规则必须包含:Rule ID、Level、Rule、Rationale、Applies To、Verification、Owner、Source 3. 必须明确写出:
- 何时创建/更新 Guardrails
- 哪些变化需要下游文档重审
- 例外流程与复审周期
4. 默认先覆盖这些高风险领域:
- 安全与合规
- API / Contract
- 数据与迁移
- 发布与回滚
- 可观测性
5. repository_scan_first 下,只有同时满足以下条件的“事实”才能升格为 Guardrail 候选:
- 跨多个模块/服务重复出现
- 在 CI/IaC/Runbook/代码中有稳定证据
- 能解释为“有意设计”,而不是历史偶然或技术债
6. 如果采用分域模式,index 只负责:
- 适用范围
- 规则分级
- 例外流程
- 文档索引
- 下游钩子总表
7. 对于更新场景,必须附带「本次变更影响摘要」而不是只给出新正文
Phase 4:自检与交接
1. 使用 references/guardrails-checklist.md 自检 2. 输出交接摘要,至少包含:
- 本次动作:create/update/restructure/no_change
- 若是首次生成:interview_first / repository_scan_first
- 触发原因
- 受影响领域
- 需要重审的下游文档/技能
- 是否建议阻塞当前设计/发布
3. 只要产生 Guardrails 变更,就建议下一步运行 guardrails-reviewer
AskUserQuestion 规则
- 只在关键证据缺失时提问,减少不必要交互
- 优先确认“是否真的需要更新”,再确认“更新哪些领域”
- 首次生成时,优先确认使用哪种模式
- 问题模板见
references/askuser-templates.md
禁止行为
- 不要把 Guardrails 当作每个 feature 的固定节点
- 不要因为一个局部实现问题就重写全局规范
- 不要在无证据时发明项目默认规则
- 不要把 feature-specific 决策塞进 Guardrails
- 不要静默修改无关领域
- 不要把偶然实现、技术债或历史漂移直接当作 Guardrail 事实
使用示例
示例 1:
项目刚建立,请基于架构、开发、DevOps/SRE 访谈建立一版 Guardrails v0。
示例 2:
最近两次 HLD/LLD 评审都在争论鉴权、限流和审计日志,请更新项目 Guardrails,只改 API 与安全相关规则。
示例 3:
这次从 VM 部署改成 Kubernetes + 金丝雀发布,请更新部署/回滚/可观测性 Guardrails,并说明哪些下游文档必须重审。
参考文档
| 文档 | 内容 |
|---|---|
references/guardrails-template.md | Guardrails 模板 |
references/fact-standard.md | 仓库分析式生成的事实标准与证据层级 |
references/workflow-hooks.md | 触发条件与下游钩子映射 |
references/guardrails-checklist.md | 自检清单 |
references/askuser-templates.md | AskUserQuestion 模板 |
interface:
display_name: "Guardrails Writer"
short_description: "Create or update project guardrails and workflow hooks"
icon_small: "./assets/testany-logo-small.png"
icon_large: "./assets/testany-logo.svg"
default_prompt: "Use $guardrails-writer to create or update project-level Guardrails when architecture, platform, compliance, incidents, or repeated review issues require a governance baseline."
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="958.3745509306195" height="958.3745509306195" viewBox="0 0 958.3745509306195 958.3745509306195">
<g transform="scale(8.11041548093341) translate(10, 10)">
<defs id="SvgjsDefs1360"></defs>
<g id="SvgjsG1361" featureKey="symbolFeature-0" transform="matrix(0.9816393857057392,0,0,0.9816393857057392,-3.0293391105859975,0.00098156823722121)" fill="#7cbb00">
<rect xmlns="http://www.w3.org/2000/svg" x="42.607" y="47.076" transform="matrix(0.7761 0.6306 -0.6306 0.7761 46.5672 -14.0771)" width="1" height="22.92">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="45.986" y="57.948" transform="matrix(0.6084 0.7937 -0.7937 0.6084 68.7434 -22.4141)" width="22.194" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="61.209" y="34.391" transform="matrix(0.285 0.9585 -0.9585 0.285 88.4619 -26.0748)" width="1" height="23.738">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="38.984" y="37.368" transform="matrix(0.0074 1 -1 0.0074 88.2466 -13.1692)" width="23.546" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="27.744" y="45.76" transform="matrix(0.9562 0.2928 -0.2928 0.9562 15.2685 -9.4777)" width="23.094" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="35.832" y="34.683" transform="matrix(0.9456 0.3253 -0.3253 0.9456 16.6429 -9.3663)" width="1" height="20.809">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="31.072" y="60.446" transform="matrix(0.8221 0.5694 -0.5694 0.8221 42.108 -12.8663)" width="21.141" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="58.047" y="51.212" transform="matrix(0.5722 0.8201 -0.8201 0.5722 75.2668 -21.8197)" width="1" height="20.036">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="53.541" y="45.129" transform="matrix(0.2845 0.9587 -0.9587 0.2845 89.4167 -28.5477)" width="20.584" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="39.708" y="35.004" transform="matrix(0.9997 0.0243 -0.0243 0.9997 0.8776 -1.2119)" width="21.201" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="36.331" y="59.987" transform="matrix(0.5784 0.8158 -0.8158 0.5784 77.9659 2.2244)" width="1" height="33.1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="55.959" y="70.302" transform="matrix(0.3351 0.9422 -0.9422 0.3351 114.7194 -20.9532)" width="32.492" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="76.946" y="19.044" transform="matrix(0.0107 0.9999 -0.9999 0.0107 112.198 -42.2379)" width="1" height="33.083">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="44.371" y="2.123" transform="matrix(0.9527 0.3039 -0.3039 0.9527 7.9224 -12.733)" width="0.999" height="33.928">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="3.101" y="44.487" transform="matrix(0.8004 0.5995 -0.5995 0.8004 30.9 -2.8183)" width="33.161" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="13.446" y="11.595" transform="matrix(0.9605 0.2782 -0.2782 0.9605 11.716 -2.2955)" width="1" height="57.08">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="1.626" y="81.812" transform="matrix(0.8375 0.5464 -0.5464 0.8375 49.6273 -2.2773)" width="54.033" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="71.659" y="52.69" transform="matrix(0.6376 0.7704 -0.7704 0.6376 87.6254 -26.6706)" width="1" height="54.215">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="55.738" y="36.926" transform="matrix(0.377 0.9262 -0.9262 0.377 86.266 -53.4047)" width="54.19" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="46.824" y="-12.954" transform="matrix(0.0146 0.9999 -0.9999 0.0146 58.9718 -35.1579)" width="1" height="50.592">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="6.016" y="66.991" width="29.866" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="9.472" y="27.565" transform="matrix(0.2024 0.9793 -0.9793 0.2024 47.599 -2.3107)" width="31.493" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="61.126" y="6.058" transform="matrix(0.5429 0.8398 -0.8398 0.5429 44.2475 -43)" width="1" height="26.18">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="69.065" y="52.2" transform="matrix(0.7128 0.7014 -0.7014 0.7128 60.8208 -43.1259)" width="28.006" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="57.052" y="65.986" transform="matrix(0.9215 0.3885 -0.3885 0.9215 36.441 -15.9049)" width="1" height="32.356">
</rect>
<circle xmlns="http://www.w3.org/2000/svg" cx="6.41" cy="35.047" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="32.979" cy="55.017" r="4.79">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="93.05" cy="62.521" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="93.987" cy="35.41" r="2.927">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="51.269" cy="97.073" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="6.014" cy="67.55" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="50.332" cy="49.641" r="5.511">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="39.816" cy="35" r="4.789">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="60.904" cy="35.842" r="4.79">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="77.649" cy="86.109" r="2.927">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="50.635" cy="67.21" r="4.79">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="66.735" cy="55.478" r="4.79">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="28.249" cy="42.878" r="2.028">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="50.633" cy="26.257" r="1.929">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="35.881" cy="67.432" r="2.128">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="63.833" cy="67.256" r="2.053">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="50.031" cy="2.927" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="72.616" cy="12.331" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="73.085" cy="42.878" r="2.225">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="23.331" cy="86.109" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="22.03" cy="12.645" r="2.928">
</circle>
</g>
</g>
</svg>AskUserQuestion 模板
本文档定义 guardrails-writer 在“是否该更新、为何更新、影响哪些下游文档”三个关键问题上的提问模板。
---
1. 触发类型确认
触发时机:Phase 0,证据不足以判断是否需要创建/更新时
question: "本次更像哪种 Guardrails 动作?"
header: "触发类型"
multiSelect: false
options:
- label: "创建项目基线"
description: "仓库还没有统一 Guardrails,需要先建 v0/v1 基线"
- label: "更新受影响领域"
description: "已有 Guardrails,但架构/平台/合规/事故导致部分规则需要更新"
- label: "不确定,先帮我判断"
description: "请先扫描现有规范与变更背景,再决定是否需要改"---
2. 首次生成模式确认
触发时机:Phase 0,结论为 create_baseline 时
question: "首次生成 Guardrails 时,你希望我优先采用哪种方式?"
header: "生成模式"
multiSelect: false
options:
- label: "访谈式"
description: "适合新项目或仓库信号较弱,先基于角色访谈建立 v0 基线"
- label: "仓库分析式"
description: "适合已有代码、配置、CI/IaC、Runbook 的存量仓库"
- label: "你先判断"
description: "我会先看仓库事实密度,再决定采用哪种模式"---
3. 更新原因确认
触发时机:Phase 0,已知需要更新,但原因不清
question: "这次为什么要改 Guardrails?"
header: "更新原因"
multiSelect: true
options:
- label: "架构或平台变化"
description: "例如运行环境、部署模式、认证方式、数据存储变化"
- label: "安全/合规/SRE 新要求"
description: "需要把新的强制约束固化进项目基线"
- label: "事故复盘"
description: "要把长期规则沉淀下来,避免同类问题复发"
- label: "重复评审问题"
description: "同类争议在 API/HLD/LLD/Runbook 中反复出现"---
4. 适用范围与输出模式
触发时机:Phase 2,范围或文档拓扑不明确时
question: "本次 Guardrails 应该怎么组织?"
header: "输出模式"
multiSelect: false
options:
- label: "单文档基线"
description: "适合新项目、单团队、先建立最小可用基线"
- label: "Index + 分域文档"
description: "适合多团队或不同领域更新频率差异很大"
- label: "只更新现有文档的局部领域"
description: "已有基线,只修订受影响章节"---
5. 受影响领域确认
触发时机:Phase 2,需要缩小更新范围时
question: "本次变化影响哪些 Guardrails 领域?"
header: "影响领域"
multiSelect: true
options:
- label: "API / Contract"
description: "认证、版本、兼容性、错误语义、限流等"
- label: "数据与迁移"
description: "存储、Schema、迁移、保留策略等"
- label: "安全与合规"
description: "访问控制、审计、隐私、合规基线等"
- label: "发布 / 回滚 / 可观测性"
description: "部署、回滚、告警、SLO、日志/metrics/traces"
- label: "前端 / 基础设施 / 外部集成"
description: "UI 一致性、IaC、外部依赖治理等"---
6. 事实冲突处理
触发时机:Phase 1/2,repository_scan_first 下事实与文档/口头约定冲突时
question: "仓库事实与现有文档/口头约定冲突时,哪种情况更接近你们的目标状态?"
header: "事实冲突"
multiSelect: false
options:
- label: "以仓库事实为准"
description: "当前实现更接近真实基线,文档需要追认或补齐"
- label: "以文档/决策为准"
description: "当前实现是漂移,Guardrails 应保持目标标准并要求下游纠偏"
- label: "先记录冲突,不立即固化"
description: "需要后续决策,当前先保留为待确认项"---
7. 下游阻塞级别确认
触发时机:Phase 2,需判断是否阻塞当前主流程时
question: "Guardrails 更新后,下游工作流应该怎么处理?"
header: "下游钩子"
multiSelect: false
options:
- label: "先更新 Guardrails,再继续设计"
description: "适用于认证、数据、发布、安全等默认边界已变化的场景"
- label: "允许继续,但必须在合并前重审"
description: "适用于已有设计基本可用,但需要补做一致性检查"
- label: "先记录建议,下个迭代再对齐"
description: "适用于低风险、非阻塞的增量规范补齐"仓库分析式生成的事实标准
1. 为什么需要事实标准
在 repository_scan_first 模式下,Guardrails 不能只依赖“仓库里现在长什么样”,也不能只信文档或口头描述。需要把三类证据分开:
- 观察到的事实:代码、配置、CI、IaC、Schema、Runbook、测试、事故记录
- 声明性标准:ADR、已有规范、安全政策、README、既有 Guardrails
- 未来意图:访谈中确认的目标状态或待落地决策
2. 证据优先级
2.1 描述当前现状时
优先级通常是:
1. 观察到的事实 2. 声明性标准 3. 访谈记忆
如果文档说“蓝绿发布”,但仓库的 CI/IaC/Runbook 全是金丝雀,那么当前现状应记录为金丝雀,并同时标记文档漂移。
2.2 定义目标 Guardrail 时
优先级通常是:
1. 已批准的项目政策 / ADR / 既有 Guardrails 2. 经确认的未来意图 3. 当前实现事实
如果团队已决定迁移到新标准,而仓库尚未完成落地,不要把旧实现直接固化为新 Guardrail;要明确写成“目标状态”并列出对齐动作。
3. 什么样的事实可以升格为 Guardrail
必须同时满足:
- 在多个模块/服务中重复出现
- 在代码、配置、CI、IaC、Runbook 等至少两个事实源可交叉验证
- 能解释为团队的有意选择,而不是一次性补丁或历史残留
- 对多个下游设计决策都有约束价值
4. 什么样的事实不能直接升格
- 单模块局部实现
- 明显的技术债或历史漂移
- 与已批准标准冲突但未决策的现状
- 只是当前实现“碰巧这样写”,没有跨模块稳定模式
5. 冲突处理
当 事实 与 标准 冲突时,必须分类:
| 情况 | 处理方式 |
|---|---|
| 标准过期,事实更稳定 | 可建议按现状更新 Guardrails,但需明确决策 |
| 实现漂移,标准仍有效 | Guardrails 保持标准,并把实现对齐列为下游动作 |
| 无法判断谁代表目标状态 | 记录为待决策项,不静默固化 |
6. repository_scan_first 的最低输出
至少输出:
- 观察到的事实清单
- 声明性标准清单
- 冲突/漂移清单
- 可升格为 Guardrail 的候选规则
- 需要访谈确认的未决问题
Guardrails 自检清单
触发判定
- 已明确本次是
create_baseline、update_impacted_domains、restructure或no_change - 已记录触发原因,而不是“顺手补规范”
- 如果结论是
no_change,已明确回退到 HLD/LLD/ADR,而不是误改 Guardrails - 若是首次生成,已明确
interview_first或repository_scan_first
基线质量
- 元信息完整:版本、Owner、状态、生效时间、复审周期
- 适用范围与非范围明确
- Must/Should/Nice 分级明确
- 每条规则都有 Verification、Owner、Source
- 例外流程清晰可执行
- 变更记录有条目
项目级边界
- 没有写入 feature-specific 设计细节
- 规则是跨模块、跨团队、可复用的长期约束
- 默认选择、允许范围、禁止项都写清楚
- 只更新了受影响领域,没有无关重写
repository_scan_first 事实标准
- 已区分
fact、declared_standard、future_intent - 没有把局部实现、技术债、漂移现状直接升格成 Guardrail
- 事实与标准冲突时,已显式标记为 drift 或待决策项
- 至少有可交叉验证的事实来源支持关键规则候选
工作流钩子
- 已明确写出“何时需要再次更新 Guardrails”
- 已给出受影响的下游文档/技能
- 已给出阻塞建议:先更新再继续 / 合并前重审 / 下周期对齐
- API/HLD/LLD/Runbook 等关键下游的影响没有遗漏
输出拓扑
- 单文档模式适合当前范围,或已解释为什么要拆成 index + 分域文档
- 分域模式下,index 负责总则与钩子,领域文档负责具体规则
覆盖质量
- 已优先覆盖安全、API、数据、发布、可观测性等高风险领域
- 规则可验证(lint/CI/审查/运行检查)
- 与现有规范、技术栈、运行方式不冲突
Project Guardrails Template
Use this template to produce a project-level Guardrails baseline or an incremental update. It should answer three questions: what the default path is, what is explicitly forbidden, and which changes should trigger downstream re-review.
---
Project Guardrails
0. Metadata
| Item | Content |
|---|---|
| Version | vX.Y |
| Status | draft / in_review / approved |
| Owner | [Owner / Team] |
| Effective Date | YYYY-MM-DD |
| Review Cadence | Quarterly / Every major release / As needed |
| Action Type | create_baseline / update_impacted_domains / restructure |
| Generation Mode | interview_first / repository_scan_first |
| Trigger Reason | [Project kickoff / architecture change / compliance requirement / incident review / repeated review findings] |
| Output Mode | Single document / index + domain docs |
| Applicable Scope | [System / team / repository / runtime environment] |
---
1. Positioning and Boundaries
- In Scope:
- Out of Scope:
- Items that should not be used as feature-level design input:
- Domains updated in this round only:
---
2. Update Triggers and Workflow Hooks
2.1 When Guardrails Must Be Created or Updated
| Trigger Type | Typical Signal | Action |
|---|---|---|
| create_baseline | The repository does not yet have Guardrails | Establish a minimum viable baseline |
| update_impacted_domains | Default boundaries changed in architecture / platform / auth / data / release, etc. | Update impacted domains only |
| restructure | The single document is too large or domain-specific updates are frequent | Restructure into index + domain docs |
| no_change | Only feature-local changes | Fall back to HLD / LLD / ADR |
2.2 Downstream Re-review Hooks
| Change Domain | Impacted Artifacts / Skills | Recommended Action | Blocking Level |
|---|---|---|---|
| API / Contract | API Contract, HLD, LLD | Align default boundaries before continuing design | [block_before_design / review_before_merge / sync_next_cycle] |
| Data and Migration | HLD, LLD, Runbook | Re-review data model, migration, and rollback | [...] |
| Security and Compliance | API Contract, HLD, LLD, Runbook | Re-review auth, audit, and access control | [...] |
| Release / Rollback / Observability | HLD, Runbook | Re-review deployment, rollback, SLO, and alerting | [...] |
| Other Domains | [Path / Skill] | [Action] | [...] |
---
3. Fact Standards and Evidence Layers
3.1 Observed Facts
- [Code / configuration / CI / IaC / Runbook / tests / incident records]
3.2 Declarative Standards
- [ADR / existing standards / README / security policy / existing Guardrails]
3.3 Conflicts and Drift
| Conflict Item | Fact | Standard / Intent | Resolution |
|---|---|---|---|
| [Example] | [Codify current state / Keep target state / Pending decision] |
---
4. Rule Levels and Exception Mechanism
- Must: Mandatory. Violations are blocking.
- Should: Strongly recommended. Deviations require an explicit rationale.
- Nice: Recommended. Not blocking.
Exception Process: Requester / Approver / Validity period / Record location / Expiration review method
---
5. Default Choices and Prohibited Items
- Default technical path:
- Allowed range:
- Explicitly prohibited items:
- Required upstream standards / ADRs / external policies:
---
6. LLD Module Requirements (Mandatory)
| Module | Requirement (Required / Optional / Forbidden) | Rationale | Source |
|---|---|---|---|
| Core | Required | ||
| API Contract | Required | ||
| Storage & Migration | |||
| Async / Event | |||
| Infra / IaC | |||
| Observability | |||
| Security / Compliance | Required | ||
| Deployment / Release | |||
| Frontend UX | |||
| External Integration | |||
| SDK / Library |
---
7. Guardrails Rule Table Template
| Rule ID | Level | Rule | Rationale | Applies To | Verification | Owner | Source |
|---|---|---|---|---|---|---|---|
| GR-001 | Must |
---
8. Rules for High-Risk Domains
8.1 API / Contract Guardrails
[Use the rule table template]
8.2 Data and Migration Guardrails
[Use the rule table template]
8.3 Security and Compliance Guardrails
[Use the rule table template]
8.4 Release / Rollback / Observability Guardrails
[Use the rule table template]
---
9. Rules for Other Domains (As Needed)
9.1 Frontend UX / Engineering
[Fill in only if applicable]
9.2 Infrastructure / IaC
[Fill in only if applicable]
9.3 External Integrations / SDK / Event Messaging
[Fill in only if applicable]
---
10. Summary of Impact for This Change
- Reason for this update:
- If this is the initial baseline, which mode was used:
- Impacted domains:
- Downstream documents / skills that require re-review:
- Blocking recommendation:
- Items not covered but requiring follow-up:
---
11. Change Log
| Version | Change | Reason | Date | Author |
|---|---|---|---|---|
| vX.Y |
Project Guardrails 模板
本模板用于输出项目级 Guardrails 基线或增量更新。目标是回答三件事:默认怎么做、绝对不能做什么、什么变化会触发下游重审。
---
Project Guardrails
0. 元信息
| 项目 | 内容 |
|---|---|
| 版本 | vX.Y |
| 状态 | draft / in_review / approved |
| Owner | [负责人/团队] |
| 生效日期 | YYYY-MM-DD |
| 复审周期 | 每季度 / 每大版本 / 按需 |
| 动作类型 | create_baseline / update_impacted_domains / restructure |
| 生成模式 | interview_first / repository_scan_first |
| 触发原因 | [项目启动 / 架构变化 / 合规要求 / 事故复盘 / 重复评审问题] |
| 输出模式 | 单文档 / index + domain docs |
| 适用范围 | [系统/团队/仓库/运行环境] |
---
1. 定位与边界
- In Scope:
- Out of Scope:
- 不作为功能级设计输入的内容:
- 本次仅更新的领域:
---
2. 更新触发与工作流钩子
2.1 何时必须创建或更新 Guardrails
| 触发类型 | 典型信号 | 处理动作 |
|---|---|---|
| create_baseline | 仓库还没有 Guardrails | 建立最小可用基线 |
| update_impacted_domains | 架构/平台/认证/数据/发布等默认边界变化 | 只更新受影响领域 |
| restructure | 单文档过大、分域更新频繁 | 重构为 index + domain docs |
| no_change | 仅 feature-local 变化 | 回退到 HLD/LLD/ADR |
2.2 下游重审钩子
| 变更域 | 受影响产物/技能 | 建议动作 | 阻塞级别 |
|---|---|---|---|
| API / Contract | API Contract, HLD, LLD | 先对齐默认边界,再继续设计 | [block_before_design / review_before_merge / sync_next_cycle] |
| 数据与迁移 | HLD, LLD, Runbook | 重审数据模型、迁移、回滚 | [...] |
| 安全与合规 | API Contract, HLD, LLD, Runbook | 重审认证、审计、访问控制 | [...] |
| 发布 / 回滚 / 可观测性 | HLD, Runbook | 重审部署、回滚、SLO、告警 | [...] |
| 其他领域 | [路径/技能] | [动作] | [...] |
---
3. 事实标准与证据分层
3.1 观察到的事实
- [代码 / 配置 / CI / IaC / Runbook / 测试 / 事故记录]
3.2 声明性标准
- [ADR / 既有规范 / README / 安全政策 / 既有 Guardrails]
3.3 冲突与漂移
| 冲突项 | 事实 | 标准/意图 | 处理结论 |
|---|---|---|---|
| [例] | [按现状固化 / 维持目标状态 / 待决策] |
---
4. 规则分级与例外机制
- Must:必须遵守,违反即阻塞
- Should:强烈建议,需显式说明理由才能偏离
- Nice:推荐项,不阻塞
例外流程:申请人 / 审批人 / 有效期 / 记录位置 / 到期复审方式
---
5. 默认选择与禁止项
- 默认技术路径:
- 允许范围:
- 明确禁止项:
- 依赖的上游规范/ADR/外部政策:
---
6. LLD 模块要求(强制)
| 模块 | 要求(Required/Optional/Forbidden) | 理由 | 来源 |
|---|---|---|---|
| Core | Required | ||
| API Contract | Required | ||
| Storage & Migration | |||
| Async/Event | |||
| Infra/IaC | |||
| Observability | |||
| Security/Compliance | Required | ||
| Deployment/Release | |||
| Frontend UX | |||
| External Integration | |||
| SDK/Library |
---
7. Guardrails 规则表模板
| Rule ID | Level | Rule | Rationale | Applies To | Verification | Owner | Source |
|---|---|---|---|---|---|---|---|
| GR-001 | Must |
---
8. 高风险领域规则
8.1 API / Contract Guardrails
[使用规则表模板]
8.2 数据与迁移 Guardrails
[使用规则表模板]
8.3 安全与合规 Guardrails
[使用规则表模板]
8.4 发布 / 回滚 / 可观测性 Guardrails
[使用规则表模板]
---
9. 其他领域规则(按需)
9.1 前端 UX / 工程
[如适用再填写]
9.2 基础设施 / IaC
[如适用再填写]
9.3 外部集成 / SDK / 事件消息
[如适用再填写]
---
10. 本次变更影响摘要
- 本次更新原因:
- 若首次生成:采用的模式:
- 受影响领域:
- 需要重审的下游文档/技能:
- 阻塞建议:
- 未覆盖但需后续跟进的事项:
---
11. 变更记录
| 版本 | 变更内容 | 变更原因 | 日期 | 作者 |
|---|---|---|---|---|
| vX.Y |
Guardrails 工作流钩子参考
1. 触发类型
| 类型 | 典型信号 | writer 动作 | 默认建议 |
|---|---|---|---|
create_baseline | 仓库还没有 Guardrails | 建立 v0/v1 基线 | 在 API/HLD 大规模展开前完成 |
update_impacted_domains | 平台、认证、数据、发布、合规等默认边界变化 | 只更新受影响领域 | 受影响设计先对齐 |
restructure | 单文档过大、分域更新频繁、Owner 不清晰 | 改成 index + domain docs | 先收敛治理结构 |
no_change | 只是 feature-local 变化 | 不改 Guardrails | 回到 HLD/LLD/ADR |
2. 下游映射
| Guardrails 变更域 | 优先重审的下游产物/技能 | 典型动作 |
|---|---|---|
| API / Contract | api-writer, api-reviewer, hld-writer, lld-writer | 重审认证、版本、兼容性、错误语义、限流 |
| 数据与迁移 | hld-writer, lld-writer, runbook-writer | 重审数据模型、迁移、回滚、保留策略 |
| 安全与合规 | api-writer, hld-writer, lld-writer, runbook-writer | 重审访问控制、审计、密钥、隐私处理 |
| 发布 / 回滚 | hld-writer, runbook-writer | 重审部署方式、发布门禁、回滚流程 |
| 可观测性 | hld-writer, runbook-writer, test-strategy-writer | 重审 SLO、日志、metrics、traces、告警 |
| 前端 / UX | prototype-designer, prototype-reviewer, lld-writer | 重审交互一致性、埋点、错误态、可访问性 |
| 基础设施 / IaC | hld-writer, lld-writer, runbook-writer | 重审环境拓扑、权限边界、资源基线 |
3. 阻塞建议
| 条件 | 默认阻塞级别 |
|---|---|
| 当前仓库没有 Guardrails,且项目已进入 API/HLD 设计 | block_before_design |
| 默认认证、数据、发布、安全边界发生变化 | block_before_design |
| 已有设计基本完成,但 Guardrails 新增了强制规则 | review_before_merge |
| 只是补充低风险推荐项 | sync_next_cycle |
4. 使用规则
- 先判断“是否该改 Guardrails”,再决定“改哪些领域”
- 更新时只写受影响领域,不要顺手全量重写
- 如果一次变化会影响多个下游文档,必须在交接摘要里明确列出重审清单