doc-spec-validator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesedoc-spec-validator
doc-spec-validator
Validate Technical Specifications (SPEC) documents against Layer 9 schema standards.
依据Layer 9 schema标准验证技术规格(SPEC)文档。
Activation
触发时机
Invoke when user requests validation of SPEC documents or after creating/modifying SPEC artifacts.
当用户请求验证SPEC文档,或在创建/修改SPEC工件后调用。
Validation Schema Reference
验证Schema参考
Schema:
Layer: 9
Artifact Type: SPEC
ai_dev_flow/SPEC/SPEC_SCHEMA.yamlSchema:
层级:9
工件类型:SPEC
ai_dev_flow/SPEC/SPEC_SCHEMA.yamlValidation Checklist
验证检查清单
0. Folder Structure Validation (BLOCKING)
0. 文件夹结构验证(阻塞性检查)
Nested Folder Rule: ALL SPEC documents MUST be in nested folders regardless of size.
Required Structure:
| SPEC Type | Required Location |
|---|---|
| YAML | |
Validation:
1. Check document is inside a nested folder: docs/09_SPEC/SPEC-NN_{slug}/
2. Verify folder name matches SPEC ID pattern: SPEC-NN_{slug}
3. Verify file name matches folder: SPEC-NN_{slug}.yaml
4. Parent path must be: docs/09_SPEC/Example Valid Structure:
docs/09_SPEC/
├── SPEC-01_f1_iam/
│ ├── SPEC-01_f1_iam.yaml ✓ Valid
│ ├── SPEC-01.R_review_report_v001.md
│ └── .drift_cache.json
├── SPEC-02_f2_session/
│ └── SPEC-02_f2_session.yaml ✓ ValidInvalid Structure:
docs/09_SPEC/
├── SPEC-01_f1_iam.yaml ✗ NOT in nested folderError Codes:
| Code | Severity | Description |
|---|---|---|
| SPEC-E020 | ERROR | SPEC not in nested folder (BLOCKING) |
| SPEC-E021 | ERROR | Folder name doesn't match SPEC ID |
| SPEC-E022 | ERROR | File name doesn't match folder name |
This check is BLOCKING - SPEC must pass folder structure validation before other checks proceed.
嵌套文件夹规则:所有SPEC文档无论大小,都必须放在嵌套文件夹中。
要求的结构:
| SPEC类型 | 要求的存放位置 |
|---|---|
| YAML | |
验证步骤:
1. 检查文档是否位于嵌套文件夹内:docs/09_SPEC/SPEC-NN_{slug}/
2. 验证文件夹名称是否符合SPEC ID格式:SPEC-NN_{slug}
3. 验证文件名是否与文件夹名称匹配:SPEC-NN_{slug}.yaml
4. 父路径必须为:docs/09_SPEC/有效结构示例:
docs/09_SPEC/
├── SPEC-01_f1_iam/
│ ├── SPEC-01_f1_iam.yaml ✓ 有效
│ ├── SPEC-01.R_review_report_v001.md
│ └── .drift_cache.json
├── SPEC-02_f2_session/
│ └── SPEC-02_f2_session.yaml ✓ 有效无效结构:
docs/09_SPEC/
├── SPEC-01_f1_iam.yaml ✗ 未放在嵌套文件夹中错误代码:
| 代码 | 严重程度 | 描述 |
|---|---|---|
| SPEC-E020 | 错误 | SPEC未放在嵌套文件夹中(阻塞性检查) |
| SPEC-E021 | 错误 | 文件夹名称与SPEC ID不匹配 |
| SPEC-E022 | 错误 | 文件名与文件夹名称不匹配 |
此检查为阻塞性检查 - SPEC必须通过文件夹结构验证后,才能进行其他检查。
1. File Format Validation
1. 文件格式验证
yaml
File Format:
- Extension: .yaml (NOT .md)
- Naming pattern: SPEC-NNN_descriptive_name.yaml
- Encoding: UTF-8
- YAML version: 1.2yaml
File Format:
- Extension: .yaml (NOT .md)
- Naming pattern: SPEC-NNN_descriptive_name.yaml
- Encoding: UTF-8
- YAML version: 1.22. Required Top-Level Fields
2. 必填顶层字段
yaml
Required fields:
- id: Component identifier (snake_case)
- summary: Single-sentence description (10-200 chars)
- metadata: Document control and versioning
- traceability: Upstream and downstream references
- architecture: Component architecture and dependencies
- interfaces: Interface definitions (classes, methods)
- behavior: Behavioral specifications
- performance: Performance targets
- security: Security specifications
- observability: Metrics, logging, health checks
- verification: Test scenarios
- implementation: Implementation specifics
Optional fields:
- caching
- rate_limiting
- circuit_breaker
- operations
- changelog
- maintenance
- notesyaml
Required fields:
- id: 组件标识符(snake_case格式)
- summary: 单句描述(10-200字符)
- metadata: 文档管控与版本信息
- traceability: 上下游关联引用
- architecture: 组件架构与依赖关系
- interfaces: 接口定义(类、方法)
- behavior: 行为规格
- performance: 性能指标
- security: 安全规格
- observability: 指标、日志、健康检查
- verification: 测试场景
- implementation: 实现细节
Optional fields:
- caching
- rate_limiting
- circuit_breaker
- operations
- changelog
- maintenance
- notes3. Metadata Section Validation
3. 元数据(Metadata)部分验证
Required Fields:
- version: Semantic version (MAJOR.MINOR.PATCH)
- status: draft | review | approved | implemented | deprecated
- created_date: YYYY-MM-DD format
- last_updated: YYYY-MM-DD format
- authors: Array with at least one author (name required)
Optional Fields:
- task_ready_score
- reviewers
- owners
必填字段:
- version: 语义化版本(MAJOR.MINOR.PATCH格式)
- status: draft(草稿)| review(评审中)| approved(已批准)| implemented(已实现)| deprecated(已废弃)
- created_date: YYYY-MM-DD格式
- last_updated: YYYY-MM-DD格式
- authors: 数组,至少包含一位作者(必填姓名)
可选字段:
- task_ready_score
- reviewers
- owners
4. Interfaces Section Validation
4. 接口(Interfaces)部分验证
Class Requirements:
- name: PascalCase format
- description: Required
- methods: At least one method required per class
Method Requirements:
- name: snake_case format
- description: Required
- input: Optional parameters object
- output: Optional return object
- errors: Optional error definitions
类要求:
- name: PascalCase格式
- description: 必填
- methods: 每个类至少定义一个方法
方法要求:
- name: snake_case格式
- description: 必填
- input: 可选参数对象
- output: 可选返回对象
- errors: 可选错误定义
5. Performance Section Validation
5. 性能(Performance)部分验证
Required Fields:
- latency_targets:
- p50_milliseconds
- p95_milliseconds
- p99_milliseconds
- throughput_targets:
- sustained_requests_per_second
- resource_limits:
- cpu_cores_allocated
- memory_mb_allocated
Validation Rules:
- p95 must be greater than p50
- p99 must be greater than p95
必填字段:
- latency_targets:
- p50_milliseconds
- p95_milliseconds
- p99_milliseconds
- throughput_targets:
- sustained_requests_per_second
- resource_limits:
- cpu_cores_allocated
- memory_mb_allocated
验证规则:
- p95必须大于p50
- p99必须大于p95
6. Security Section Validation
6. 安全(Security)部分验证
Required Fields:
- authentication.required: boolean
- authentication.methods: array
- authorization.enabled: boolean
- input_validation.strategy: string
必填字段:
- authentication.required: 布尔值
- authentication.methods: 数组
- authorization.enabled: 布尔值
- input_validation.strategy: 字符串
7. Observability Section Validation
7. 可观测性(Observability)部分验证
Required Fields:
- metrics.standard_metrics: array (min 1 item)
- logging.level: DEBUG | INFO | WARN | ERROR
- logging.format: json | text | structured
- health_checks.enabled: boolean
- health_checks.endpoints: array
必填字段:
- metrics.standard_metrics: 数组(至少1项)
- logging.level: DEBUG | INFO | WARN | ERROR
- logging.format: json | text | structured
- health_checks.enabled: 布尔值
- health_checks.endpoints: 数组
8. Traceability Validation
8. 可追溯性(Traceability)验证
Layer 9 Cumulative Tags:
- @brd: BRD-NNN:XXX-NNN (required)
- @prd: PRD-NNN:XXX-NNN (required)
- @ears: EARS-NNN:NNN (required)
- @bdd: BDD-NNN:scenario-name (required)
- @adr: ADR-NN (required)
- @sys: SYS-NNN:XXX-NNN (required)
- @req: REQ-NNN:feature-name (required)
- @ctr: CTR-NNN (optional)
Downstream Expected:
- TASKS documents
- Code (src/...)
- Tests (tests/...)
Same-Type References:
- related_spec: [SPEC-NN]
- depends_spec: [SPEC-NN]
Layer 9 累积标签:
- @brd: BRD-NNN:XXX-NNN(必填)
- @prd: PRD-NNN:XXX-NNN(必填)
- @ears: EARS-NNN:NNN(必填)
- @bdd: BDD-NNN:scenario-name(必填)
- @adr: ADR-NN(必填)
- @sys: SYS-NNN:XXX-NNN(必填)
- @req: REQ-NNN:feature-name(必填)
- @ctr: CTR-NNN(可选)
预期下游关联:
- TASKS文档
- 代码(src/...)
- 测试用例(tests/...)
同类型引用:
- related_spec: [SPEC-NN]
- depends_spec: [SPEC-NN]
Error Codes
错误代码
| Code | Severity | Description |
|---|---|---|
| SPEC-E001 | error | File is not valid YAML |
| SPEC-E002 | error | Missing required top-level field |
| SPEC-E003 | error | Missing required metadata field |
| SPEC-E004 | error | Invalid version format |
| SPEC-E005 | error | Invalid status value |
| SPEC-E006 | error | Invalid date format |
| SPEC-E007 | error | No authors specified |
| SPEC-E008 | error | No classes defined in interfaces |
| SPEC-E009 | error | Class has no methods |
| SPEC-E010 | error | Missing latency_targets in performance |
| SPEC-E011 | error | Missing authentication in security |
| SPEC-E012 | error | Missing metrics in observability |
| SPEC-E013 | warning | File name does not match format |
| SPEC-E014 | error | Missing traceability section |
| SPEC-E015 | error | Missing cumulative_tags in traceability |
| SPEC-W001 | warning | Missing business_requirements in upstream |
| SPEC-W002 | warning | Missing cumulative tags for traceability |
| SPEC-W003 | warning | No BDD scenarios in verification |
| SPEC-W004 | warning | p95 latency not greater than p50 |
| SPEC-W005 | warning | p99 latency not greater than p95 |
| SPEC-W006 | warning | Method name not in snake_case |
| SPEC-W007 | warning | Class name not in PascalCase |
| SPEC-W008 | warning | id field does not match file name |
| SPEC-W009 | warning | task_ready_score below target |
| SPEC-I001 | info | Consider adding caching section |
| SPEC-I002 | info | Consider adding rate_limiting section |
| SPEC-I003 | info | Consider adding circuit_breaker section |
| SPEC-I004 | info | Consider adding operations runbook |
| 代码 | 严重程度 | 描述 |
|---|---|---|
| SPEC-E001 | 错误 | 文件不是有效的YAML格式 |
| SPEC-E002 | 错误 | 缺失必填顶层字段 |
| SPEC-E003 | 错误 | 缺失必填元数据字段 |
| SPEC-E004 | 错误 | 版本格式无效 |
| SPEC-E005 | 错误 | 状态值无效 |
| SPEC-E006 | 错误 | 日期格式无效 |
| SPEC-E007 | 错误 | 未指定作者 |
| SPEC-E008 | 错误 | 接口中未定义类 |
| SPEC-E009 | 错误 | 类中未定义方法 |
| SPEC-E010 | 错误 | 性能部分缺失latency_targets |
| SPEC-E011 | 错误 | 安全部分缺失authentication |
| SPEC-E012 | 错误 | 可观测性部分缺失metrics |
| SPEC-E013 | 警告 | 文件名不符合格式 |
| SPEC-E014 | 错误 | 缺失可追溯性部分 |
| SPEC-E015 | 错误 | 可追溯性部分缺失cumulative_tags |
| SPEC-W001 | 警告 | 上游关联缺失business_requirements |
| SPEC-W002 | 警告 | 可追溯性缺失累积标签 |
| SPEC-W003 | 警告 | 验证部分缺失BDD场景 |
| SPEC-W004 | 警告 | p95延迟不大于p50 |
| SPEC-W005 | 警告 | p99延迟不大于p95 |
| SPEC-W006 | 警告 | 方法名不是snake_case格式 |
| SPEC-W007 | 警告 | 类名不是PascalCase格式 |
| SPEC-W008 | 警告 | id字段与文件名不匹配 |
| SPEC-W009 | 警告 | task_ready_score低于目标值 |
| SPEC-I001 | 信息 | 建议添加caching部分 |
| SPEC-I002 | 信息 | 建议添加rate_limiting部分 |
| SPEC-I003 | 信息 | 建议添加circuit_breaker部分 |
| SPEC-I004 | 信息 | 建议添加运维手册(operations runbook) |
Validation Commands
验证命令
bash
undefinedbash
undefinedValidate single SPEC document
验证单个SPEC文档
python ai_dev_flow/scripts/validate_spec.py docs/09_SPEC/SPEC-001_example.yaml
python ai_dev_flow/scripts/validate_spec.py docs/09_SPEC/SPEC-001_example.yaml
Validate all SPEC documents
验证所有SPEC文档
python ai_dev_flow/scripts/validate_spec.py docs/09_SPEC/
python ai_dev_flow/scripts/validate_spec.py docs/09_SPEC/
Check with verbose output
启用详细输出检查
python ai_dev_flow/scripts/validate_spec.py docs/09_SPEC/ --verbose
undefinedpython ai_dev_flow/scripts/validate_spec.py docs/09_SPEC/ --verbose
undefinedValidation Workflow
验证流程
- Verify file is valid YAML
- Check all required top-level fields present
- Validate metadata section (version, status, dates, authors)
- Check interfaces section (classes with methods)
- Validate performance section (latency targets, p50 < p95 < p99)
- Check security section (authentication, authorization)
- Validate observability section (metrics, logging, health)
- Check traceability cumulative tags (7 required)
- Verify verification section (BDD scenarios)
- Validate implementation section
- Check file naming convention
- Generate validation report
- 验证文件是否为有效的YAML格式
- 检查所有必填顶层字段是否存在
- 验证元数据部分(版本、状态、日期、作者)
- 检查接口部分(包含方法的类)
- 验证性能部分(延迟指标,p50 < p95 < p99)
- 检查安全部分(身份认证、授权)
- 验证可观测性部分(指标、日志、健康检查)
- 检查可追溯性累积标签(7个必填)
- 验证验证部分(BDD场景)
- 验证实现部分
- 检查文件命名规范
- 生成验证报告
Integration
集成方式
- Invoked by: doc-flow, doc-spec (post-creation)
- Feeds into: trace-check (cross-document validation)
- Reports to: quality-advisor
- 调用方:doc-flow、doc-spec(创建后触发)
- 输出至:trace-check(跨文档验证)
- 报告至:quality-advisor
Output Format
输出格式
SPEC Validation Report
======================
Document: SPEC-001_example.yaml
Status: PASS/FAIL
YAML Validity: Valid/Invalid
Required Sections:
- metadata: Present/Missing
- traceability: Present/Missing
- architecture: Present/Missing
- interfaces: Present/Missing
- behavior: Present/Missing
- performance: Present/Missing
- security: Present/Missing
- observability: Present/Missing
- verification: Present/Missing
- implementation: Present/Missing
Interface Summary:
- Classes defined: N
- Methods defined: N
Performance Targets:
- p50: Nms
- p95: Nms (> p50: Yes/No)
- p99: Nms (> p95: Yes/No)
Errors: N
Warnings: N
Info: N
[Details listed by severity]SPEC验证报告
======================
文档:SPEC-001_example.yaml
状态:通过/不通过
YAML有效性:有效/无效
必填章节:
- metadata: 存在/缺失
- traceability: 存在/缺失
- architecture: 存在/缺失
- interfaces: 存在/缺失
- behavior: 存在/缺失
- performance: 存在/缺失
- security: 存在/缺失
- observability: 存在/缺失
- verification: 存在/缺失
- implementation: 存在/缺失
接口摘要:
- 已定义类数量:N
- 已定义方法数量:N
性能指标:
- p50: N毫秒
- p95: N毫秒(大于p50:是/否)
- p99: N毫秒(大于p95:是/否)
错误数:N
警告数:N
信息数:N
[按严重程度列出详细信息]Related Resources
相关资源
- SPEC Skill:
.claude/skills/doc-spec/SKILL.md - Naming Standards: (ID and naming conventions)
.claude/skills/doc-naming/SKILL.md - SPEC Validation Rules:
ai_dev_flow/09_SPEC/SPEC_VALIDATION_RULES.md - SPEC Schema:
ai_dev_flow/SPEC/SPEC_SCHEMA.yaml
- SPEC技能:
.claude/skills/doc-spec/SKILL.md - 命名标准: (ID与命名规范)
.claude/skills/doc-naming/SKILL.md - SPEC验证规则:
ai_dev_flow/09_SPEC/SPEC_VALIDATION_RULES.md - SPEC Schema:
ai_dev_flow/SPEC/SPEC_SCHEMA.yaml
Version History
版本历史
| Version | Date | Changes | Author |
|---|---|---|---|
| 1.2 | 2026-02-11 | Nested Folder Rule: Added Section 0 Folder Structure Validation (BLOCKING); SPEC must be in | |
| 1.1.0 | 2026-02-08 | Updated layer assignment from 10 to 9 per LAYER_REGISTRY v1.6; removed @impl from cumulative tags | System |
| 1.0.0 | 2025-01-15 | Initial validator skill definition | System |
| 版本 | 日期 | 变更内容 | 作者 |
|---|---|---|---|
| 1.2 | 2026-02-11 | 嵌套文件夹规则:新增第0节文件夹结构验证(阻塞性检查);SPEC必须放在 | |
| 1.1.0 | 2026-02-08 | 根据LAYER_REGISTRY v1.6,将层级从10更新为9;移除累积标签中的@impl | 系统 |
| 1.0.0 | 2025-01-15 | 初始验证器技能定义 | 系统 |