重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
trace-check by vladm3105/aidoc-flow-framework
npx skills add https://github.com/vladm3105/aidoc-flow-framework --skill trace-check在所有 SDD 工件之间进行自动化的可追溯性验证。
核心功能:
SDD 工作流程(v2.0 - 功能层分组):
业务层:BRD → PRD → EARS →
测试层:BDD →
架构层:ADR → SYS →
需求层:REQ →
实施策略层:IMPL(可选) →
接口层:CTR(可选) →
技术规范层:SPEC →
执行计划层:TASKS →
代码与验证层:Code → Tests → Validation → Review → Production
参考:TRACEABILITY.md v2.0(更新于 2025-10-31)
复杂度:中等(需要解析多种文件格式)
资源需求:
故障模式:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在以下情况下使用 trace-check:
在以下情况下请勿使用 trace-check:
| 输入 | 类型 | 描述 | 示例/默认值 |
|---|---|---|---|
| project_root_path | 必需 | 项目文档根目录的路径 | {project_root}/docs/ |
| artifact_types | 可选 | 要验证的特定工件类型 | ["BRD", "SPEC"] 或 ["all"](默认) |
| strictness_level | 可选 | 验证严格程度 | "strict"(默认),"permissive", "pedantic" |
| validate_cumulative | 可选 | 新增:验证累积标签层次结构 | true 或 false(默认) |
| auto_fix | 可选 | 自动修复损坏的链接 | true 或 false(默认) |
| report_format | 可选 | 输出报告格式 | "markdown"(默认),"json", "text" |
严格程度级别:
permissive:仅警告,不因缺少反向链接而失败strict:因损坏的链接和缺少双向一致性而失败pedantic:因任何可追溯性间隙(包括"待创建"部分)而失败操作:
docs/ 目录以查找所有工件类型预期结果:
验证:
docs/{TYPE}/ 存在{TYPE}-{XXX}_{description}.{ext}操作:
[ID](path#anchor) 格式Markdown 模式识别:
**上游来源:**
- [BRD-01](../BRD/BRD-01_file.md#BRD-01) - 标题(状态,日期)
**下游工件:**
**进行中:**
- [SPEC-01](../SPEC/SPEC-01_file.yaml#anchor) - 标题(状态,日期)
**待创建:**
- SPEC-02+:描述(待定)
数据结构:
操作:
标签提取正则表达式:
import re
TAG_PATTERN = r'@(\w+(?:-\w+)?):\s*([\w\.\-]+(?:[\.:]\w[\w\.\-]*)?(?:\s*,\s*[\w\.\-]+(?:[\.:]\w[\w\.\-]*)?)*)'
# 示例匹配(统一 TYPE.NN.TT.SS 格式):
# @brd: BRD.01.01.30, BRD.01.01.03
# @sys: SYS.01.25.08
# @spec: SPEC-003
# @test: BDD.01.13.01
验证规则:
输出:
{
"src/[project_module]/gateway/connection_service.py": {
"tags": {
"brd": ["BRD.01.01.01", "BRD.01.01.02", "BRD.01.01.03"],
"sys": ["SYS.01.25.01", "SYS.01.25.02"],
"spec": ["SPEC-01"],
"test": ["BDD.01.13.01", "BDD.07.13.01"],
"impl-status": ["complete"]
},
"line_numbers": {
"BRD.01.01.01": 15,
"BRD.01.01.02": 15
}
}
}
错误检测:
@brd: 030 - 缺少文档和元素 ID@brd: BRD.99.01.01 - 文档 BRD-99 不存在@brd: BRD.01.01.99 - 元素 99 不在 BRD-01 中@brd: BRD.01.01.30 - 格式有效且存在脚本:
# 提取标签
python scripts/extract_tags.py --source src/ docs/ tests/ --output docs/generated/tags.json
# 根据文档验证标签
python scripts/validate_tags_against_docs.py --tags docs/generated/tags.json --strict
# 生成矩阵
python scripts/generate_traceability_matrices.py --tags docs/generated/tags.json --output docs/generated/matrices/
操作:
按工件类型预期的累积标签数量:
业务层:
策略:0 个标签(外部业务文档)
BRD:0 个标签(顶层)
PRD:1 个标签(@brd)
EARS:2 个标签(@brd, @prd)
测试层:
BDD:3+ 个标签(@brd 到 @ears)
架构层:
ADR:4 个标签(@brd 到 @bdd)
SYS:5 个标签(@brd 到 @adr)
需求层:
REQ:6 个标签(@brd 到 @sys)
实施策略层:
IMPL:7 个标签(@brd 到 @req)[可选]
接口层:
CTR:8 个标签(@brd 到 @impl)[可选]
技术规范层:
SPEC:7-9 个标签(@brd 到 @req + 可选的 impl/ctr)
执行计划层:
TASKS:8-10 个标签(@brd 到 @spec)
代码与验证层:
Code:9-11 个标签(@brd 到 @tasks)
Tests:10-12 个标签(@brd 到 @code)
Validation:来自所有上游工件的所有标签
注意:功能层按工作流程中的目的对工件进行分组。随着工件在各层中推进,标签数量会累积。数字表示在 15 层架构中工件序列的位置(0-14)。
验证脚本:
# 验证累积标签层次结构合规性
python scripts/validate_tags_against_docs.py \
--source src/ docs/ tests/ \
--docs docs/ \
--validate-cumulative \
--strict
验证规则:
错误检测:
SPEC 缺少 @brd 标签 - 上游链不完整REQ 有 @adr 但缺少 @bdd - 累积链中存在间隙Code 有 8 个标签但应该有 9-11 个 - 工件类型的标签数量不正确SPEC 具有所有 9 个必需标签(@brd 到 @spec) - 有效的累积标签优势:
检查项:
TYPE-XXX 或 TYPE-XXX-YY# BRD-01001 而非 1参考:{project_root}/ai_dev_flow/ID_NAMING_STANDARDS.md
失败示例:
BRD-9 → 应为 BRD-009SPEC-1 → 应为 SPEC-01REQ-42 → 应为 REQ-042目的:确保所有 CTR 工件符合双文件格式要求(.md + .yaml)
操作:
docs/CTR/ 以查找所有 CTR 文件CTR-XXX_{slug}.md 和 CTR-XXX_{slug}.yaml验证逻辑:
def validate_ctr_dual_files(contracts_dir):
"""验证 CTR 双文件格式合规性。"""
errors = []
ctr_files = glob(f"{contracts_dir}/CTR-*.{{md,yaml}}")
# 按 CTR-ID 分组文件
ctr_groups = {}
for filepath in ctr_files:
filename = os.path.basename(filepath)
# 提取:CTR-XXX_{slug}.ext → (CTR-XXX, slug, ext)
match = re.match(r'(CTR-\d{3}(?:-\d{2})?)_(.+)\.(md|yaml)$', filename)
if match:
ctr_id, slug, ext = match.groups()
if ctr_id not in ctr_groups:
ctr_groups[ctr_id] = {}
ctr_groups[ctr_id][ext] = (filepath, slug)
# 验证每个 CTR 组
for ctr_id, files in ctr_groups.items():
# 检查两个文件是否存在
if 'md' not in files:
errors.append(f"{ctr_id}: 缺少 .md 文件(强制)")
if 'yaml' not in files:
errors.append(f"{ctr_id}: 缺少 .yaml 文件(强制)")
# 检查 slug 是否匹配
if 'md' in files and 'yaml' in files:
md_slug = files['md'][1]
yaml_slug = files['yaml'][1]
if md_slug != yaml_slug:
errors.append(
f"{ctr_id}: Slug 不匹配 - "
f"MD: '{md_slug}' 对比 YAML: '{yaml_slug}'"
)
# 验证 YAML 模式(基本检查)
if 'yaml' in files:
yaml_path = files['yaml'][0]
try:
with open(yaml_path) as f:
schema = yaml.safe_load(f)
# 检查必需的模式字段
if not isinstance(schema, dict):
errors.append(f"{ctr_id}: YAML 必须是字典/对象")
elif 'openapi' not in schema and 'asyncapi' not in schema:
# 如果不是 OpenAPI/AsyncAPI 则警告(可能是自定义 JSON Schema)
errors.append(
f"{ctr_id}: YAML 缺少 'openapi' 或 'asyncapi' 字段 "
"(应为标准模式格式)"
)
except Exception as e:
errors.append(f"{ctr_id}: 无效的 YAML - {str(e)}")
return errors
错误示例:
CTR-01: 缺少 .yaml 文件(强制) → 仅存在 .mdCTR-002: 缺少 .md 文件(强制) → 仅存在 .yamlCTR-003: Slug 不匹配 - MD: 'api_contract' 对比 YAML: 'api_spec' → Slug 不匹配CTR-004: YAML 缺少 'openapi' 或 'asyncapi' 字段 → 模式格式不明确CTR-005: 无效的 YAML - 第 42 行解析错误 → 格式错误的 YAML成功标准:
目的:验证 BRD 第 7.2 节、PRD 第 18 节和 ADR 第 4.1 节中的架构主题子章节,以确保层级分离合规性。
层级分离原则:
BRD 第 7.2 节 → PRD 第 18 节 → ADR 第 4.1 节
(做什么及为什么) (如何评估) (最终决策)
─────────────────────────────────────────────────────────────────────────
业务驱动力 技术选项 选定的选项
业务约束 评估标准 权衡分析
子章节 ID 格式:{DOC_TYPE}.NN.EE.SS(3 位主题编号)
| 组件 | 描述 | 示例 |
|---|---|---|
{DOC_TYPE} | 文档类型 | BRD |
.NNN | 文档编号(3-4 位数字) | .001 = BRD-01 |
.NNN | 顺序主题编号(3 位数字,001-999) | .003 = 第三个主题 |
验证逻辑:
def validate_architecture_topics(docs_dir):
"""验证架构决策主题的可追溯性。"""
errors = []
# 1. 提取 BRD 第 7.2 节主题
brd_topics = extract_brd_section_72_topics(docs_dir)
# 2. 验证主题 ID 格式
for topic_id, content in brd_topics.items():
if not re.match(r'^[A-Z]+\.\d{2,9}\.\d{2,9}\.\d{2,9}$', topic_id):
errors.append(f"{topic_id}: 无效的格式(应为 {{DOC_TYPE}}.NN.EE.SS)")
# 3. 检查仅限业务内容(无技术选项)
if has_technical_content(content):
errors.append(f"{topic_id}: 包含技术内容(应仅为业务内容)")
# 4. 验证 PRD 第 18 节详细阐述
prd_topics = extract_prd_section_18_topics(docs_dir)
for topic_id, content in prd_topics.items():
# 检查上游引用是否存在
if content.get('upstream') not in brd_topics:
errors.append(f"PRD {topic_id}: 未找到上游 BRD 主题")
# 检查是否包含技术内容
if not has_technical_options(content):
errors.append(f"PRD {topic_id}: 缺少技术选项")
# 5. 验证 ADR 第 4.1 节起源主题
adr_topics = extract_adr_originating_topics(docs_dir)
for adr_id, content in adr_topics.items():
topic_ref = content.get('originating_topic')
if topic_ref and topic_ref not in brd_topics:
errors.append(f"{adr_id}: 起源主题 {topic_ref} 在 BRD 中未找到")
return errors
内容验证规则:
| 层级 | 章节 | 必需内容 | 禁止内容 |
|---|---|---|---|
| BRD(第 1 层) | 7.2 | 业务驱动力,业务约束 | 技术选项,评估标准 |
| PRD(第 2 层) | 18 | 技术选项,评估标准,上游引用 | 业务约束(从 BRD 重复) |
| ADR(第 5 层) | 4.1 | 起源主题,决策,引用 | 缺少上游引用 |
验证正则表达式模式:
# BRD 第 7.2 节子章节标题(H3-H5,取决于文档上下文)
ARCHITECTURE_TOPIC_PATTERN = r'^#{3,5}\s+([A-Z]+\.\d{2,}\.\d{3}):\s+.+'
# PRD 第 18 节上游引用(3 位主题编号)
PRD_UPSTREAM_PATTERN = r'\*\*Upstream\*\*:\s*BRD-\d{2,}\s+§7\.2\.\d{3}'
# ADR 第 4.1 节起源主题
ADR_ORIGINATING_PATTERN = r'\*\*Originating Topic\*\*:\s*([A-Z]+\.\d{2,}\.\d{3})\s*-\s*.+'
交叉引用验证:
错误示例:
BRD.001.01: 无效的格式 → 应为 BRD.001.001(3 位主题)BRD.001.1: 无效的格式 → 应为 BRD.001.001(3 位主题)BRD.001.001: 包含技术内容 → "WebSocket" 出现在 BRD 中(应移至 PRD)PRD 18.1: 未找到上游 BRD 主题 → 引用不存在的 BRD 主题ADR-01: 起源主题 BRD.999.001 未找到 → 无效的主题引用成功标准:
{DOC_TYPE}.NN.EE.SS 格式测试项:
#anchor 引用有效id: 字段是否与锚点匹配Scenario: 行是否创建锚点相对路径计算:
/docs/SPEC/SPEC-01.yaml/docs/BRD/BRD-01.md[BRD-01](../BRD/BRD-01.md#BRD-01)锚点验证:
# BRD-01 → 锚点 #BRD-01id: ib_gateway_connection_service → 锚点 #ib_gateway_connection_serviceScenario: User connects to IB Gateway → 锚点因解析器而异失败示例:
[SPEC-01](../SPEC/SPEC-01.yaml) → 文件未找到[BRD-01](../BRD/BRD-01.md#BRD-02) → 锚点不匹配逻辑 - 基于标签的方法:
正向矩阵(BRD → 代码):
| 需求 | 实现文件 | 状态 |
|-------------|-------------------|--------|
| BRD.01.01.01 | src/[project_module]/gateway/connection_service.py:15 | ✓ 完成 |
| BRD.01.01.02 | src/[project_module]/gateway/connection_service.py:15 | ✓ 完成 |
| BRD.01.01.30 | src/[project_module]/services/account_service.py:12 | ⚠️ 进行中 |
反向矩阵(代码 → BRD):
| 源文件 | BRD 需求 | 实施状态 |
|-------------|------------------|---------------------|
| src/[project_module]/gateway/connection_service.py | BRD.01.01.01, BRD.01.01.02, BRD.01.01.03 | 完成 |
| src/[project_module]/services/account_service.py | BRD.01.01.30, BRD.01.01.31, BRD.01.01.32 | 进行中 |
传统的第 7 节验证(可选):
评分:
注意: 矩阵是根据标签自动生成的。当使用基于标签的方法时,手动第 7 节是可选的。
指标:
覆盖率要求:
孤立检测:
报告章节:
报告格式:
操作:
docs_backup_YYYYMMDD_HHMMSS.tar.gz安全措施:
备份命令:
cd {project_root}/docs
tar -czf ../backups/docs_backup_$(date +%Y%m%d_%H%M%S).tar.gz .
合规性:
TYPE-XXX 或 TYPE-XXX-YY正则表达式模式:^(BRD|PRD|EARS|BDD|ADR|SYS|REQ|IMPL|CTR|SPEC|TASKS)-\d{3}(-\d{2})?$
失败示例:
BRD-9 → 应为 BRD-009SPEC-1 → 应为 SPEC-01REQ-042-1 → 应为 REQ-042-01测试项:
#anchor失败示例:
[SPEC-01](../SPEC/SPEC-01.yaml) → 文件未找到[BRD-01](../../BRD/BRD-01.md#BRD-01) → 路径深度错误[REQ-015](../REQ/REQ-015.md#REQ-015) → 文件存在但锚点缺失锚点创建规则:
# {ID} → 锚点 #{ID}id: {snake_case_name} → 锚点 #{snake_case_name}Scenario: {title} → 锚点因解析器而异验证:
[ID](path#anchor)失败示例:
[SPEC-01](../SPEC/SPEC-01.yaml#SPEC-01) → YAML 有 id: 字段,而非 H1[BDD-01](../BDD/BDD-01.feature#ib-gateway-connection) → Scenario 标题不匹配逻辑:
评分:(匹配的对数 / 总链接数)× 100%
失败示例:
要求:
计算:(完整的 / 总数)× 100%
失败示例:
定义:
可追溯性规则:
| 文档类型 | 上游可追溯性 | 下游可追溯性 |
|---|---|---|
| BRD | 可选(指向其他 BRD) | 可选 |
| 所有其他文档 | 必需 | 可选 |
关键规则:
预期行为:
失败示例:
用户请求:"在我提交 SPEC-01 之前验证可追溯性"
助手操作:使用 trace-check 技能,参数如下:
{project_root}/docs/["SPEC"]"strict"false**输出
Automated traceability validation across all SDD artifacts.
Core Functions :
SDD Workflow (v2.0 - Functional Layer Groupings):
Business Layer: BRD → PRD → EARS →
Testing Layer: BDD →
Architecture Layer: ADR → SYS →
Requirements Layer: REQ →
Implementation Strategy Layer: IMPL (optional) →
Interface Layer: CTR (optional) →
Technical Specs Layer: SPEC →
Execution Planning Layer: TASKS →
Code & Validation Layer: Code → Tests → Validation → Review → Production
Reference : TRACEABILITY.md v2.0 (updated 2025-10-31)
Complexity : Medium (requires parsing multiple file formats)
Resource Requirements :
Failure Modes :
Use trace-check when :
Do NOT use trace-check when :
| Input | Type | Description | Example/Default |
|---|---|---|---|
| project_root_path | Required | Path to project documentation root | {project_root}/docs/ |
| artifact_types | Optional | Specific artifact types to validate | ["BRD", "SPEC"] or ["all"] (default) |
| strictness_level | Optional | Validation strictness | "strict" (default), "permissive", "pedantic" |
Strictness Levels :
permissive: Warnings only, no failures for missing reverse linksstrict: Fails on broken links and missing bidirectional consistencypedantic: Fails on any traceability gaps including "To Be Created" sectionsActions :
docs/ directory for all artifact typesExpected Results :
Validation :
docs/{TYPE}/ exists{TYPE}-{XXX}_{description}.{ext}Actions :
[ID](path#anchor) formatMarkdown Pattern Recognition :
**Upstream Sources:**
- [BRD-01](../BRD/BRD-01_file.md#BRD-01) - Title (Status, Date)
**Downstream Artifacts:**
**In Progress:**
- [SPEC-01](../SPEC/SPEC-01_file.yaml#anchor) - Title (Status, Date)
**To Be Created:**
- SPEC-02+: Description (TBD)
Data Structure :
Actions :
Tag Extraction Regex :
import re
TAG_PATTERN = r'@(\w+(?:-\w+)?):\s*([\w\.\-]+(?:[\.:]\w[\w\.\-]*)?(?:\s*,\s*[\w\.\-]+(?:[\.:]\w[\w\.\-]*)?)*)'
# Example matches (unified TYPE.NN.TT.SS format):
# @brd: BRD.01.01.30, BRD.01.01.03
# @sys: SYS.01.25.08
# @spec: SPEC-003
# @test: BDD.01.13.01
Validation Rules :
Output :
{
"src/[project_module]/gateway/connection_service.py": {
"tags": {
"brd": ["BRD.01.01.01", "BRD.01.01.02", "BRD.01.01.03"],
"sys": ["SYS.01.25.01", "SYS.01.25.02"],
"spec": ["SPEC-01"],
"test": ["BDD.01.13.01", "BDD.07.13.01"],
"impl-status": ["complete"]
},
"line_numbers": {
"BRD.01.01.01": 15,
"BRD.01.01.02": 15
}
}
}
Error Detection :
@brd: 030 - Missing document and element ID@brd: BRD.99.01.01 - Document BRD-99 doesn't exist@brd: BRD.01.01.99 - Element 99 not in BRD-01@brd: BRD.01.01.30 - Valid format and existsScripts :
# Extract tags
python scripts/extract_tags.py --source src/ docs/ tests/ --output docs/generated/tags.json
# Validate tags against documents
python scripts/validate_tags_against_docs.py --tags docs/generated/tags.json --strict
# Generate matrices
python scripts/generate_traceability_matrices.py --tags docs/generated/tags.json --output docs/generated/matrices/
Actions :
Expected Cumulative Tag Counts by Artifact Type :
Business Layer:
Strategy: 0 tags (external business docs)
BRD: 0 tags (top level)
PRD: 1 tag (@brd)
EARS: 2 tags (@brd, @prd)
Testing Layer:
BDD: 3+ tags (@brd through @ears)
Architecture Layer:
ADR: 4 tags (@brd through @bdd)
SYS: 5 tags (@brd through @adr)
Requirements Layer:
REQ: 6 tags (@brd through @sys)
Implementation Strategy Layer:
IMPL: 7 tags (@brd through @req) [optional]
Interface Layer:
CTR: 8 tags (@brd through @impl) [optional]
Technical Specs Layer:
SPEC: 7-9 tags (@brd through @req + optional impl/ctr)
Execution Planning Layer:
TASKS: 8-10 tags (@brd through @spec)
Code & Validation Layer:
Code: 9-11 tags (@brd through @tasks)
Tests: 10-12 tags (@brd through @code)
Validation: ALL tags from all upstream artifacts
Note : Functional layers group artifacts by purpose in the workflow. Tag counts accumulate as artifacts progress through the layers. Numbers indicate artifact sequence position (0-14) in the 15-layer architecture.
Validation Script :
# Validate cumulative tagging hierarchy compliance
python scripts/validate_tags_against_docs.py \
--source src/ docs/ tests/ \
--docs docs/ \
--validate-cumulative \
--strict
Validation Rules :
Error Detection :
SPEC missing @brd tag - Incomplete upstream chainREQ has @adr but missing @bdd - Gap in cumulative chainCode has 8 tags but should have 9-11 - Incorrect tag count for artifact typeSPEC has all 9 required tags (@brd through @spec) - Valid cumulative taggingBenefits :
Checks :
TYPE-XXX or TYPE-XXX-YY# BRD-01001 not 1Reference : {project_root}/ai_dev_flow/ID_NAMING_STANDARDS.md
Failure Examples :
BRD-9 → Should be BRD-009SPEC-1 → Should be SPEC-01REQ-42 → Should be REQ-042Purpose : Ensure all CTR artifacts comply with dual-file format requirement (.md + .yaml)
Actions :
docs/CTR/ for all CTR filesCTR-XXX_{slug}.md and CTR-XXX_{slug}.yaml existValidation Logic :
def validate_ctr_dual_files(contracts_dir):
"""Validate CTR dual-file format compliance."""
errors = []
ctr_files = glob(f"{contracts_dir}/CTR-*.{{md,yaml}}")
# Group files by CTR-ID
ctr_groups = {}
for filepath in ctr_files:
filename = os.path.basename(filepath)
# Extract: CTR-XXX_{slug}.ext → (CTR-XXX, slug, ext)
match = re.match(r'(CTR-\d{3}(?:-\d{2})?)_(.+)\.(md|yaml)$', filename)
if match:
ctr_id, slug, ext = match.groups()
if ctr_id not in ctr_groups:
ctr_groups[ctr_id] = {}
ctr_groups[ctr_id][ext] = (filepath, slug)
# Validate each CTR group
for ctr_id, files in ctr_groups.items():
# Check both files exist
if 'md' not in files:
errors.append(f"{ctr_id}: Missing .md file (MANDATORY)")
if 'yaml' not in files:
errors.append(f"{ctr_id}: Missing .yaml file (MANDATORY)")
# Check slug matches
if 'md' in files and 'yaml' in files:
md_slug = files['md'][1]
yaml_slug = files['yaml'][1]
if md_slug != yaml_slug:
errors.append(
f"{ctr_id}: Slug mismatch - "
f"MD: '{md_slug}' vs YAML: '{yaml_slug}'"
)
# Validate YAML schema (basic check)
if 'yaml' in files:
yaml_path = files['yaml'][0]
try:
with open(yaml_path) as f:
schema = yaml.safe_load(f)
# Check for required schema fields
if not isinstance(schema, dict):
errors.append(f"{ctr_id}: YAML must be a dictionary/object")
elif 'openapi' not in schema and 'asyncapi' not in schema:
# Warn if not OpenAPI/AsyncAPI (may be custom JSON Schema)
errors.append(
f"{ctr_id}: YAML missing 'openapi' or 'asyncapi' field "
"(expected standard schema format)"
)
except Exception as e:
errors.append(f"{ctr_id}: Invalid YAML - {str(e)}")
return errors
Error Examples :
CTR-01: Missing .yaml file (MANDATORY) → Only .md existsCTR-002: Missing .md file (MANDATORY) → Only .yaml existsCTR-003: Slug mismatch - MD: 'api_contract' vs YAML: 'api_spec' → Slugs don't matchCTR-004: YAML missing 'openapi' or 'asyncapi' field → Schema format unclearCTR-005: Invalid YAML - parsing error at line 42 → Malformed YAMLSuccess Criteria :
Purpose : Validate architecture topic subsections across BRD Section 7.2, PRD Section 18, and ADR Section 4.1 for layer separation compliance.
Layer Separation Principle :
BRD Section 7.2 → PRD Section 18 → ADR Section 4.1
(WHAT & WHY) (HOW to evaluate) (Final decision)
─────────────────────────────────────────────────────────────────────────
Business drivers Technical options Selected option
Business constraints Evaluation criteria Trade-off analysis
Subsection ID Format : {DOC_TYPE}.NN.EE.SS (3-digit topic number)
| Component | Description | Example |
|---|---|---|
{DOC_TYPE} | Document type | BRD |
.NNN | Document number (3-4 digits) | .001 = BRD-01 |
.NNN | Sequential topic number (3 digits, 001-999) | .003 = third topic |
Validation Logic :
def validate_architecture_topics(docs_dir):
"""Validate architecture decision topic traceability."""
errors = []
# 1. Extract BRD Section 7.2 topics
brd_topics = extract_brd_section_72_topics(docs_dir)
# 2. Validate topic ID format
for topic_id, content in brd_topics.items():
if not re.match(r'^[A-Z]+\.\d{2,9}\.\d{2,9}\.\d{2,9}$', topic_id):
errors.append(f"{topic_id}: Invalid format (expected {{DOC_TYPE}}.NN.EE.SS)")
# 3. Check business-only content (no technical options)
if has_technical_content(content):
errors.append(f"{topic_id}: Contains technical content (should be business-only)")
# 4. Validate PRD Section 18 elaborations
prd_topics = extract_prd_section_18_topics(docs_dir)
for topic_id, content in prd_topics.items():
# Check upstream reference exists
if content.get('upstream') not in brd_topics:
errors.append(f"PRD {topic_id}: Upstream BRD topic not found")
# Check has technical content
if not has_technical_options(content):
errors.append(f"PRD {topic_id}: Missing technical options")
# 5. Validate ADR Section 4.1 originating topics
adr_topics = extract_adr_originating_topics(docs_dir)
for adr_id, content in adr_topics.items():
topic_ref = content.get('originating_topic')
if topic_ref and topic_ref not in brd_topics:
errors.append(f"{adr_id}: Originating topic {topic_ref} not found in BRD")
return errors
Content Validation Rules :
| Layer | Section | Required Content | Forbidden Content |
|---|---|---|---|
| BRD (Layer 1) | 7.2 | Business Driver, Business Constraints | Technical options, Evaluation criteria |
| PRD (Layer 2) | 18 | Technical Options, Evaluation Criteria, Upstream reference | Business constraints (duplicated from BRD) |
| ADR (Layer 5) | 4.1 | Originating Topic, Decision, References | Missing upstream references |
Validation Regex Patterns :
# BRD Section 7.2 subsection header (H3-H5 depending on document context)
ARCHITECTURE_TOPIC_PATTERN = r'^#{3,5}\s+([A-Z]+\.\d{2,}\.\d{3}):\s+.+'
# PRD Section 18 upstream reference (3-digit topic number)
PRD_UPSTREAM_PATTERN = r'\*\*Upstream\*\*:\s*BRD-\d{2,}\s+§7\.2\.\d{3}'
# ADR Section 4.1 originating topic
ADR_ORIGINATING_PATTERN = r'\*\*Originating Topic\*\*:\s*([A-Z]+\.\d{2,}\.\d{3})\s*-\s*.+'
Cross-Reference Validation :
Error Examples :
BRD.001.01: Invalid format → Should be BRD.001.001 (3-digit topic)BRD.001.1: Invalid format → Should be BRD.001.001 (3-digit topic)BRD.001.001: Contains technical content → "WebSocket" in BRD (move to PRD)PRD 18.1: Upstream BRD topic not found → References non-existent BRD topicADR-01: Originating topic BRD.999.001 not found → Invalid topic referenceSuccess Criteria :
{DOC_TYPE}.NN.EE.SS formatTests :
#anchor references validid: field matches anchorScenario: lines create anchorsRelative Path Calculation :
/docs/SPEC/SPEC-01.yaml/docs/BRD/BRD-01.md[BRD-01](../BRD/BRD-01.md#BRD-01)Anchor Validation :
# BRD-01 → anchor #BRD-01id: ib_gateway_connection_service → anchor #ib_gateway_connection_serviceScenario: User connects to IB Gateway → anchor variesFailure Examples :
[SPEC-01](../SPEC/SPEC-01.yaml) → File not found[BRD-01](../BRD/BRD-01.md#BRD-02) → Anchor mismatchLogic - Tag-Based Approach :
Forward Matrix (BRD → Code) :
| Requirement | Implementing Files | Status |
|-------------|-------------------|--------|
| BRD.01.01.01 | src/[project_module]/gateway/connection_service.py:15 | ✓ Complete |
| BRD.01.01.02 | src/[project_module]/gateway/connection_service.py:15 | ✓ Complete |
| BRD.01.01.30 | src/[project_module]/services/account_service.py:12 | ⚠️ In Progress |
Reverse Matrix (Code → BRD) :
| Source File | BRD Requirements | Implementation Status |
|-------------|------------------|---------------------|
| src/[project_module]/gateway/connection_service.py | BRD.01.01.01, BRD.01.01.02, BRD.01.01.03 | Complete |
| src/[project_module]/services/account_service.py | BRD.01.01.30, BRD.01.01.31, BRD.01.01.32 | In Progress |
Traditional Section 7 Validation (Optional):
Scoring :
Note: Matrices are auto-generated from tags. Manual Section 7 is optional when using tag-based approach.
Metrics :
Coverage Requirements :
Orphan Detection :
Report Sections :
Report Format :
Actions :
docs_backup_YYYYMMDD_HHMMSS.tar.gzSafety Measures :
Backup Command :
cd {project_root}/docs
tar -czf ../backups/docs_backup_$(date +%Y%m%d_%H%M%S).tar.gz .
Compliance :
TYPE-XXX or TYPE-XXX-YYRegex Pattern : ^(BRD|PRD|EARS|BDD|ADR|SYS|REQ|IMPL|CTR|SPEC|TASKS)-\d{3}(-\d{2})?$
Failure Examples :
BRD-9 → Should be BRD-009SPEC-1 → Should be SPEC-01REQ-042-1 → Should be REQ-042-01Tests :
#anchor found in target fileFailure Examples :
[SPEC-01](../SPEC/SPEC-01.yaml) → File not found[BRD-01](../../BRD/BRD-01.md#BRD-01) → Wrong path depth[REQ-015](../REQ/REQ-015.md#REQ-015) → File exists but anchor missingAnchor Creation Rules :
# {ID} → anchor #{ID}id: {snake_case_name} → anchor #{snake_case_name}Scenario: {title} → anchor varies by parserValidation :
[ID](path#anchor)Failure Examples :
[SPEC-01](../SPEC/SPEC-01.yaml#SPEC-01) → YAML has id: field, not H1[BDD-01](../BDD/BDD-01.feature#ib-gateway-connection) → Scenario title mismatchLogic :
Scoring : (matched pairs / total links) × 100%
Failure Examples :
Requirements :
Calculation : (complete / total) × 100%
Failure Examples :
Definitions :
Traceability Rules :
| Document Type | Upstream Traceability | Downstream Traceability |
|---|---|---|
| BRD | OPTIONAL (to other BRDs) | OPTIONAL |
| All Other Documents | REQUIRED | OPTIONAL |
Key Rules :
Expected Behavior :
Failure Examples :
User Request : "Validate traceability before I commit SPEC-01"
Assistant Action : Uses trace-check skill with:
{project_root}/docs/["SPEC"]"strict"falseOutput :
✅ SPEC-01: ID format valid
✅ SPEC-01: Links resolve (BRD-01, SYS-002, REQ-01, ADR-02)
❌ SPEC-01: Bidirectional gap - BRD-01 missing reverse link
Coverage: SPEC artifacts 100% (1/1)
Consistency: 75% (3/4 links bidirectional)
Recommendation: Update BRD-01 Section 7.2 to add SPEC-01 reference
User Request : "Run full traceability audit and fix issues"
Assistant Action : Uses trace-check skill with:
{project_root}/docs/["all"]"strict"trueActions :
docs_backup_20251111_174001.tar.gzOutput :
✅ Coverage: 98% (85/87 artifacts)
✅ Consistency: 96% (245/255 links)
⚠️ 2 orphaned artifacts: REQ-042, REQ-055 (no upstream)
📋 Auto-fixed: 15 issues
📝 Manual review: 2 issues (see report)
User Request : "Check all SPEC files for traceability issues"
Assistant Action : Uses trace-check skill with:
{project_root}/docs/["SPEC"]"pedantic"Output :
Validated: 8 SPEC files
✅ SPEC-01: Perfect (100% traceability)
✅ SPEC-02: Perfect (100% traceability)
⚠️ SPEC-003: Missing BDD reference
❌ SPEC-004: Broken link to REQ-015 (file not found)
Coverage: 88% (7/8 SPEC with complete traceability)
User Request : "Generate traceability coverage report"
Assistant Action : Uses trace-check skill with:
{project_root}/docs/"markdown"Output :
| Artifact Type | Total | Complete | Coverage | Orphaned |
|---------------|-------|----------|----------|----------|
| BRD | 13 | 13 | 100% | 0 |
| PRD | 15 | 15 | 100% | 0 |
| EARS | 8 | 8 | 100% | 0 |
| BDD | 51 | 51 | 100% | 0 |
| SPEC | 8 | 7 | 88% | 0 |
| REQ | 42 | 40 | 95% | 2 |
| **Total** | **137** | **134** | **98%** | **2** |
User Request : "Validate cumulative tagging compliance across all artifacts"
Assistant Action : Uses trace-check skill with:
{project_root}/docs/["all"]"strict"trueActions :
Output :
✅ Artifact Type Validation: 85/87 artifacts compliant (98%)
✅ Tag Chain Completeness: 100% (no gaps detected)
⚠️ Tag Count Issues: 2 artifacts
- SPEC-004: Has 6 tags but artifact type requires 7-9 (missing @impl or @ctr)
- Code file position_service.py: Has 8 tags but artifact type requires 9-11 (missing upstream tags)
❌ Cumulative Chain Gaps: 0 artifacts
Recommendations:
1. SPEC-004: Add missing @impl or @ctr tag (depending on project structure)
2. position_service.py: Add missing @tasks or @task_plans tag to docstring
3. Run validation weekly to catch gaps early
Benefits :
## Traceability Validation Report
**Project**: IB API MCP Server
**Validation Date**: 2025-11-11 17:40:01 EST
**Scope**: All artifacts (137 documents)
### Summary
- ✅ Overall Status: PASS (with warnings)
- 📊 Coverage: 98% (134/137 complete)
- 🔗 Consistency: 96% (245/255 bidirectional)
- ⚠️ Warnings: 3 issues require attention
- ❌ Errors: 0 blocking issues
## Broken Links (2 found)
| Source | Line | Target | Error |
|--------|------|--------|-------|
| SPEC-004 | 56 | REQ-015 | File not found: ../REQ/REQ-015.md |
| BDD-012 | 134 | SPEC-003 | Anchor not found: #ib_service_spec |
## Missing Traceability (3 artifacts)
| Artifact | Issue | Severity | Recommendation |
|----------|-------|----------|----------------|
| REQ-042 | No upstream sources | Warning | Add BRD/PRD reference |
| REQ-055 | No upstream sources | Warning | Add EARS reference |
| SPEC-003 | No BDD reference | Info | Add BDD-XXX when tests created |
## Bidirectional Inconsistencies (10 found)
| Forward Link | Reverse Link | Status | Fix Command |
|--------------|--------------|--------|-------------|
| SPEC-01 → BRD-01 | BRD-01 → SPEC-01 | ✅ Fixed | Added to BRD-01:463 |
| SPEC-02 → REQ-03 | REQ-03 → SPEC-02 | ❌ Missing | Add to REQ-03 Section 7 |
## Coverage Metrics
| Type | Total | Complete | Coverage | Target | Status |
|------|-------|----------|----------|--------|--------|
| BRD | 13 | 13 | 100% | 100% | ✅ |
| PRD | 15 | 15 | 100% | 100% | ✅ |
| SPEC | 8 | 7 | 88% | 100% | ⚠️ |
| REQ | 42 | 40 | 95% | 100% | ⚠️ |
Performance :
Accuracy :
Safety :
Compatibility :
Action : Increment version and add changelog entry
Example :
## Revision History
| Version | Date | Author | Changes |
|---------|------------|--------|---------|
| 2.1 | 2025-11-11 | trace-check skill | Updated traceability: Added SPEC-01 reference |
| 2.0 | 2025-11-10 | User | Initial complete draft |
Detection : SPEC-01 references BRD-01, but BRD-01 does not reference SPEC-01
Action : Add to BRD-01 Section 7.2 "Downstream Artifacts"
Before :
**To Be Created:**
- SPEC-XXX: Technical implementation specifications
After :
**In Progress:**
- [SPEC-01](../SPEC/SPEC-01_ib_gateway_connection_service.yaml#ib_gateway_connection_service) - IB Gateway Connection Service (Status: Draft, Created: 2025-11-11)
**To Be Created:**
- SPEC-02+: Additional technical specifications (TBD)
Detection : Link [BRD-01](../../BRD/BRD-01.md#BRD-01) from /docs/SPEC/SPEC-01.yaml
Calculation :
/docs/SPEC/SPEC-01.yaml/docs/BRD/BRD-01.md../BRD/BRD-01.mdAction : Update link to [BRD-01](../BRD/BRD-01.md#BRD-01)
Pattern Analysis :
Suggestion Format :
## Suggested Traceability Entries
**SPEC-003** (Missing BDD reference):
- Add to Section 7.2: `[BDD-003](../BDD/BDD-003_file.feature#scenario-id) - Test scenarios (To Be Created)`
**REQ-042** (No upstream):
- Add to Section 7.1: `[BRD-004](../BRD/BRD-004_file.md#BRD-004) - Source requirement (Verify)`
Command :
cd {project_root}/docs
tar -czf ../backups/docs_backup_$(date +%Y%m%d_%H%M%S).tar.gz .
Verification :
ls -lh ../backups/docs_backup_20251111_174001.tar.gz
# Output: 15M Nov 11 17:40 docs_backup_20251111_174001.tar.gz
Rollback Command (provided in report):
cd {project_root}/docs
tar -xzf ../backups/docs_backup_20251111_174001.tar.gz
Primary References :
Workflow Sequence (v2.0): BRD → PRD → EARS → BDD → ADR → SYS → REQ → IMPL → CTR (optional) → SPEC → TASKS → Code → Tests → Validation
Complementary Skills :
Workflow Integration :
doc-flow to create new artifactstrace-check to validate traceabilityadr-roadmap to generate implementation plansproject-mngt for release planningTemplate Locations :
{project_root}/ai_dev_flow/BRD/{project_root}/ai_dev_flow/PRD/{project_root}/ai_dev_flow/EARS/{project_root}/ai_dev_flow/BDD/{project_root}/ai_dev_flow/ADR/{project_root}/ai_dev_flow/SYS/{project_root}/ai_dev_flow/REQ/{project_root}/ai_dev_flow/SPEC/All templates include :
Available Validators :
Framework Guides :
Version : 2.1.0 Last Updated : 2025-12-13 Created : 2025-11-11 Status : Active Author : SDD Framework Team
| Version | Date | Changes |
|---|---|---|
| 2.1.1 | 2025-12-15 | Architecture Decision Topic format update: Updated ADT format from BRD.NNN.NN to {DOC_TYPE}.NN.EE.SS |
| 2.1.0 | 2025-12-13 | Added Step 3.6 Architecture Decision Topic validation; cross-reference and content validation |
| 2.0.1 | 2025-11-13 | Added Step 3.5 CTR dual-file format validation; clarity improvements |
| 2.0.0 | 2025-11-13 | Major update: cumulative tagging hierarchy validation, 11-layer structure alignment |
| 1.0.0 | 2025-11-11 | Initial release with full validation and auto-fix capabilities |
Weekly Installs
47
Repository
GitHub Stars
10
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli42
codex41
opencode40
github-copilot39
claude-code39
cursor38
GitHub Actions 官方文档查询助手 - 精准解答 CI/CD 工作流问题
53,800 周安装
macOS应用公证完整指南:使用App Store Connect CLI进行开发者ID签名与公证
1,500 周安装
React 19专家 | 服务器组件、性能优化与生产级架构实战指南
1,500 周安装
Playwright浏览器自动化教程:Python爬虫、UI测试、数据采集与定时任务
45 周安装
微信公众号文章发布器 - 通过API将Markdown/HTML内容发布到公众号草稿箱
1,400 周安装
全栈安全开发指南 - Fullstack Guardian 安全编码与三视角设计实践
1,400 周安装
Vercel Workflow 开发指南:持久化异步函数与可缓存步骤函数
1,400 周安装
| validate_cumulative | Optional | NEW : Validate cumulative tagging hierarchy | true or false (default) |
| auto_fix | Optional | Auto-fix broken links | true or false (default) |
| report_format | Optional | Output report format | "markdown" (default), "json", "text" |