skill-system-behavior
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSkill System Behavior — Spec Engine
Skill系统行为规范引擎
Define what a skill does before writing how. This skill enforces a BDD-style workflow:
SKILL.spec.yaml → Acceptance Tests → Implementation → SKILL.behavior.yaml (generated)
(WHAT) (VERIFY) (HOW) (DOCUMENT)在编写实现方式之前,先定义Skill的功能范围。本Skill遵循BDD风格的工作流:
SKILL.spec.yaml → 验收测试 → 代码实现 → SKILL.behavior.yaml (自动生成)
(功能定义) (验证) (实现方式) (文档记录)Spec Format
规范格式
Every skill's behavior is defined in :
SKILL.spec.yamlyaml
schema_version: 1
skill_name: my-skill
description: "What this skill does"
operations:
- name: do-something
intent: "Why this operation exists"
inputs: [...]
outputs: [...]
constraints: ["Must not...", "Must always..."]
expected_effects: [...]
acceptance_tests:
structural:
- id: manifest-valid
assert: "manifest exposes all operations"
behavioral:
- id: happy-path
given: "Valid input"
when: "do-something is called"
then: "Returns expected output"Full schema:
schema/spec-v1.yamlFor v2 behavior specs (), you can also include an optional
Mermaid block to describe cross-node interactions.
*.behavior.yamlinteraction_diagramyaml
interaction_diagram: |
flowchart LR
Script["runtime-doctor"] -->|"reads"| Config["config/memory.yaml"]每个Skill的行为都定义在文件中:
SKILL.spec.yamlyaml
schema_version: 1
skill_name: my-skill
description: "What this skill does"
operations:
- name: do-something
intent: "Why this operation exists"
inputs: [...]
outputs: [...]
constraints: ["Must not...", "Must always..."]
expected_effects: [...]
acceptance_tests:
structural:
- id: manifest-valid
assert: "manifest exposes all operations"
behavioral:
- id: happy-path
given: "Valid input"
when: "do-something is called"
then: "Returns expected output"完整Schema:
schema/spec-v1.yaml对于v2版本的行为规范文件(),你还可以选择性添加 Mermaid代码块,用于描述跨节点交互逻辑。
*.behavior.yamlinteraction_diagramyaml
interaction_diagram: |
flowchart LR
Script["runtime-doctor"] -->|"reads"| Config["config/memory.yaml"]Operations
核心操作
create-spec
create-spec
Scaffold a new from the schema template.
SKILL.spec.yaml- Read for the format
schema/spec-v1.yaml - Ask user for: skill name, description, operations (name + intent + inputs/outputs)
- Generate in the target skill directory
SKILL.spec.yaml - Include placeholder acceptance tests (structural defaults + behavioral stubs)
基于Schema模板快速生成新的文件。
SKILL.spec.yaml- 读取文件获取格式规范
schema/spec-v1.yaml - 向用户收集信息:Skill名称、描述、操作(名称+意图+输入/输出)
- 在目标Skill目录中生成文件
SKILL.spec.yaml - 包含占位符验收测试(默认结构化测试+行为测试桩)
validate-spec
validate-spec
Validate a against the v1 schema.
SKILL.spec.yaml- Read the target
SKILL.spec.yaml - Check required fields: ,
schema_version,skill_name,descriptionoperations - For each operation: verify ,
name, at least one input or output, constraints presentintent - For acceptance_tests: verify structural tests include and
manifest-validscripts-exist - Report: PASS with summary, or FAIL with specific violations
Run via:
python3 scripts/validate_spec.py <path-to-SKILL.spec.yaml>对照v1版本Schema验证文件的合法性。
SKILL.spec.yaml- 读取目标文件
SKILL.spec.yaml - 检查必填字段:、
schema_version、skill_name、descriptionoperations - 针对每个操作:验证、
name字段,确保至少包含一个输入或输出,且存在约束条件intent - 针对验收测试:验证结构化测试包含和
manifest-valid用例scripts-exist - 输出结果:验证通过则返回摘要,失败则列出具体违规项
运行命令:
python3 scripts/validate_spec.py <path-to-SKILL.spec.yaml>verify-structural
verify-structural
Run structural acceptance tests against a built skill.
- Read the skill's for declared operations
SKILL.spec.yaml - Read the skill's for the
SKILL.mdblockskill-manifest - Verify:
- Every operation in spec has a matching operation in manifest
- Every entrypoint script referenced in manifest exists on disk
- includes this skill's capabilities
skills-index.json
- Report: checklist with PASS/FAIL per test
针对已构建的Skill运行结构化验收测试。
- 读取Skill的文件获取声明的操作
SKILL.spec.yaml - 读取Skill的文件中的
SKILL.md块skill-manifest - 验证以下内容:
- 规范中声明的每个操作都在manifest中有对应项
- manifest中引用的所有入口脚本都存在于磁盘上
- 文件包含该Skill的能力描述
skills-index.json
- 输出结果:包含每个测试项通过/失败状态的检查清单
generate-contract
generate-contract
Generate a (Mermaid DAG) from a completed spec + implementation.
SKILL.behavior.yaml- Read for operations, inputs, outputs, constraints
SKILL.spec.yaml - Map operations → stages in a flowchart
- Map inputs → input nodes, outputs → output nodes
- Map constraints → error paths
- Write with embedded Mermaid diagram
SKILL.behavior.yaml
This is the last step — only run after implementation is complete and tests pass.
根据已完成的规范和代码实现,生成文件(包含Mermaid DAG图)。
SKILL.behavior.yaml- 读取文件中的操作、输入、输出和约束条件
SKILL.spec.yaml - 将操作映射为流程图中的阶段节点
- 将输入映射为输入节点,输出映射为输出节点
- 将约束条件映射为错误路径
- 写入包含嵌入式Mermaid图的文件
SKILL.behavior.yaml
这是最后一步 — 仅在代码实现完成且所有测试通过后运行。
Coverage Gate
覆盖率检查
Scan a project tree for scripts/modules that are missing behavior specs.
- Scan for scripts that match the configured patterns
project_dir - Scan for files in the same tree
*.behavior.yaml - Report covered/uncovered scripts using exact-name and SKILL convention matching
- Emit a human-readable summary and last-line JSON report
Run via:
python3 scripts/coverage_gate.py <project_dir> [--patterns ...] [--exclude ...]Use this before declaring "behavior coverage is complete."
扫描项目目录,找出缺少行为规范的脚本/模块。
- 扫描目录,匹配配置的文件模式
project_dir - 在同一目录树中扫描文件
*.behavior.yaml - 通过精确名称匹配和SKILL命名约定,报告已覆盖/未覆盖的脚本
- 输出人类可读的摘要,最后一行输出JSON格式报告
运行命令:
python3 scripts/coverage_gate.py <project_dir> [--patterns ...] [--exclude ...]在宣布"行为规范覆盖率达标"前,请先运行该检查。
Workflow Integration
工作流集成
For skill-system-creator (updated flow)
面向Skill系统创建者(更新后的流程)
1. Understand the skill (examples, triggers)
2. Create spec → skill-system-behavior:create-spec
3. Validate spec → skill-system-behavior:validate-spec
4. Write tests → define acceptance criteria from spec
5. Initialize skill → skill-system-creator:init
6. Implement skill → edit SKILL.md, scripts, references
7. Verify structural → skill-system-behavior:verify-structural
8. Generate contract → skill-system-behavior:generate-contract
9. Package → skill-system-creator:package1. 理解Skill需求(参考示例、触发条件)
2. 生成规范 → skill-system-behavior:create-spec
3. 验证规范 → skill-system-behavior:validate-spec
4. 编写测试用例 → 根据规范定义验收标准
5. 初始化Skill项目 → skill-system-creator:init
6. 实现Skill逻辑 → 编辑SKILL.md、脚本和引用文件
7. 验证结构化测试 → skill-system-behavior:verify-structural
8. 生成行为契约 → skill-system-behavior:generate-contract
9. 打包发布 → skill-system-creator:packageSpec as Single Source of Truth
规范作为单一可信源
- — the authoritative definition (human-written, reviewed)
SKILL.spec.yaml - + manifest — implementation (must conform to spec)
SKILL.md - — generated documentation (derived from spec)
SKILL.behavior.yaml
- — 权威定义(人工编写、经过评审)
SKILL.spec.yaml - + manifest — 代码实现(必须符合规范要求)
SKILL.md - — 自动生成的文档(由规范衍生)
SKILL.behavior.yaml
Governance Tiers
治理层级
Use this 3-tier hierarchy as guidance for organizing cross-file governance docs:
Tier 1 — System Architecture
├── SYSTEM_ARCHITECTURE.md (system boundaries + data flow)
└── PIPELINE_DAG.md (zoom-in companion, state machines)
Tier 2 — Behavior Contracts
├── *.behavior.yaml (single-script: inputs/outputs/stages/error_paths)
└── BEHAVIOR_RUNTIME.md (strictly cross-script scenarios only)
Tier 3 — Tests
└── test_*.py (each test traces to a specific behavior scenario)For Tier 2 → Tier 3 traceability, use in to point to validating tests.
acceptance_tests.behavioral[].tested_bySKILL.spec.yamlFor cross-tier references, use optional and in to declare where a spec sits and what higher/lower artifacts it traces to.
governance.tiergovernance.traces_toSKILL.spec.yaml使用以下三级架构作为跨文件治理文档的组织指南:
一级架构 — 系统架构
├── SYSTEM_ARCHITECTURE.md (系统边界与数据流)
└── PIPELINE_DAG.md (细节补充:状态机)
二级架构 — 行为契约
├── *.behavior.yaml (单脚本:输入/输出/阶段/错误路径)
└── BEHAVIOR_RUNTIME.md (仅用于跨脚本交互场景)
三级架构 — 测试用例
└── test_*.py (每个测试用例对应一个具体行为场景)为了实现二级到三级架构的可追溯性,可在文件中使用字段,指向对应的验证测试用例。
SKILL.spec.yamlacceptance_tests.behavioral[].tested_by对于跨层级引用,可在文件中选择性添加和字段,声明当前规范所属层级,以及它可追溯到的更高/更低层级的工件。
SKILL.spec.yamlgovernance.tiergovernance.traces_toCross-File Boundary Rules
跨文件边界规则
- defines single-script behavior only (inputs, outputs, stages, error paths for one script).
*.behavior.yaml - is for cross-script scenarios only (2+ scripts interacting).
BEHAVIOR_RUNTIME.md - If a scenario involves only one script, place it in that script's , not in
.behavior.yaml.BEHAVIOR_RUNTIME.md - When extending to new phases, avoid full-copy duplication; use references/overlay patterns so shared flows stay canonical.
- 仅定义单脚本行为(单个脚本的输入、输出、阶段和错误路径)。
*.behavior.yaml - 仅用于跨脚本交互场景(涉及2个及以上脚本的交互)。
BEHAVIOR_RUNTIME.md - 如果场景仅涉及单个脚本,请将其放在该脚本的文件中,而非
.behavior.yaml。BEHAVIOR_RUNTIME.md - 扩展到新阶段时,避免完全复制粘贴;使用引用/覆盖模式,确保共享流程保持统一规范。
Guidelines
编写指南
- Write specs in the language your team uses (English, Chinese, mixed — consistency within a spec)
- Constraints are invariants: if violated, the skill has a bug
- describes WHY, not HOW — implementation details go in SKILL.md
intent - Acceptance tests use Given/When/Then for behavioral, assert-statements for structural
- Generate contracts only after all tests pass — contracts are docs, not specs
skill
{
"schema_version": "2.0",
"id": "skill-system-behavior",
"version": "2.0.0",
"capabilities": ["spec-create", "spec-validate", "spec-verify", "contract-generate", "coverage-gate", "skill-graph-build"],
"effects": ["fs.read", "fs.write", "proc.exec"],
"operations": {
"create-spec": {
"description": "Scaffold a new SKILL.spec.yaml from the schema template.",
"input": {
"skill_name": { "type": "string", "required": true, "description": "Name of the skill to spec" },
"skill_dir": { "type": "string", "required": false, "description": "Target directory (default: skills/<skill_name>)" }
},
"output": {
"description": "Path to created SKILL.spec.yaml",
"fields": { "path": "string" }
},
"entrypoints": {
"agent": "Read schema/spec-v1.yaml, then scaffold SKILL.spec.yaml in skill_dir"
}
},
"validate-spec": {
"description": "Validate a SKILL.spec.yaml against the v1 schema.",
"input": {
"spec_path": { "type": "string", "required": true, "description": "Path to SKILL.spec.yaml" }
},
"output": {
"description": "Validation result with pass/fail and violations list",
"fields": { "status": "string", "violations": "array" }
},
"entrypoints": {
"unix": ["python3", "scripts/validate_spec.py", "{spec_path}"],
"windows": ["python", "scripts/validate_spec.py", "{spec_path}"]
}
},
"verify-structural": {
"description": "Run structural acceptance tests against a built skill.",
"input": {
"skill_dir": { "type": "string", "required": true, "description": "Path to skill directory" }
},
"output": {
"description": "Test results checklist",
"fields": { "status": "string", "results": "array" }
},
"entrypoints": {
"unix": ["python3", "scripts/verify_structural.py", "{skill_dir}"],
"windows": ["python", "scripts/verify_structural.py", "{skill_dir}"]
}
},
"generate-contract": {
"description": "Generate SKILL.behavior.yaml (Mermaid DAG) from a completed spec.",
"input": {
"skill_dir": { "type": "string", "required": true, "description": "Path to skill directory with SKILL.spec.yaml" }
},
"output": {
"description": "Path to generated SKILL.behavior.yaml",
"fields": { "path": "string" }
},
"entrypoints": {
"unix": ["python3", "scripts/generate_contract.py", "{skill_dir}"],
"windows": ["python", "scripts/generate_contract.py", "{skill_dir}"]
}
},
"coverage-gate": {
"description": "Scan project for scripts/modules missing behavior specs.",
"input": {
"project_dir": { "type": "string", "required": true, "description": "Root directory to scan" },
"patterns": { "type": "string", "required": false, "description": "Comma-separated glob patterns (default: **/*.py,**/*.sh)" },
"exclude": { "type": "string", "required": false, "description": "Patterns to exclude (default: test_*,__pycache__,.*)" }
},
"output": {
"description": "Coverage report with covered/uncovered lists and percentage",
"fields": { "covered": "array", "uncovered": "array", "coverage_pct": "number" }
},
"entrypoints": {
"unix": ["python3", "scripts/coverage_gate.py", "{project_dir}"],
"windows": ["python", "scripts/coverage_gate.py", "{project_dir}"]
}
},
"build-graph": {
"description": "Build a cross-skill dependency graph from SKILL.spec.yaml files.",
"input": {
"skills_dir": { "type": "string", "required": false, "description": "Root directory to scan (default: ./skills)" },
"output_format": { "type": "string", "required": false, "description": "mermaid, json, or sql" }
},
"output": {
"description": "Graph output in the requested format",
"fields": { "graph": "string|json" }
},
"entrypoints": {
"unix": ["python3", "scripts/build_graph.py", "--skills-dir", "{skills_dir}", "--format", "{output_format}"]
}
},
"refresh-projections": {
"description": "Refresh behavior projection bundles from SKILL.spec.yaml files for behavior_* tables.",
"input": {
"skills_dir": { "type": "string", "required": false, "description": "Root directory to scan (default: ./skills)" },
"output_format": { "type": "string", "required": false, "description": "json or sql" }
},
"output": {
"description": "Projection bundle or SQL statements for behavior_* refresh",
"fields": { "bundle": "json|string" }
},
"entrypoints": {
"unix": ["python3", "scripts/refresh_behavior_projections.py", "--skills-dir", "{skills_dir}", "--format", "{output_format}"]
}
}
},
"stdout_contract": {
"last_line_json": true
}
}- 使用团队通用的语言编写规范(英文、中文或混合语言 — 同一规范内保持一致)
- 约束条件是不变量:如果被违反,说明Skill存在Bug
- 字段描述原因,而非实现方式 — 实现细节请放在SKILL.md文件中
intent - 验收测试:行为测试使用Given/When/Then格式,结构化测试使用断言语句
- 仅在所有测试通过后生成契约 — 契约是文档,而非规范
skill
{
"schema_version": "2.0",
"id": "skill-system-behavior",
"version": "2.0.0",
"capabilities": ["spec-create", "spec-validate", "spec-verify", "contract-generate", "coverage-gate", "skill-graph-build"],
"effects": ["fs.read", "fs.write", "proc.exec"],
"operations": {
"create-spec": {
"description": "Scaffold a new SKILL.spec.yaml from the schema template.",
"input": {
"skill_name": { "type": "string", "required": true, "description": "Name of the skill to spec" },
"skill_dir": { "type": "string", "required": false, "description": "Target directory (default: skills/<skill_name>)" }
},
"output": {
"description": "Path to created SKILL.spec.yaml",
"fields": { "path": "string" }
},
"entrypoints": {
"agent": "Read schema/spec-v1.yaml, then scaffold SKILL.spec.yaml in skill_dir"
}
},
"validate-spec": {
"description": "Validate a SKILL.spec.yaml against the v1 schema.",
"input": {
"spec_path": { "type": "string", "required": true, "description": "Path to SKILL.spec.yaml" }
},
"output": {
"description": "Validation result with pass/fail and violations list",
"fields": { "status": "string", "violations": "array" }
},
"entrypoints": {
"unix": ["python3", "scripts/validate_spec.py", "{spec_path}"],
"windows": ["python", "scripts/validate_spec.py", "{spec_path}"]
}
},
"verify-structural": {
"description": "Run structural acceptance tests against a built skill.",
"input": {
"skill_dir": { "type": "string", "required": true, "description": "Path to skill directory" }
},
"output": {
"description": "Test results checklist",
"fields": { "status": "string", "results": "array" }
},
"entrypoints": {
"unix": ["python3", "scripts/verify_structural.py", "{skill_dir}"],
"windows": ["python", "scripts/verify_structural.py", "{skill_dir}"]
}
},
"generate-contract": {
"description": "Generate SKILL.behavior.yaml (Mermaid DAG) from a completed spec.",
"input": {
"skill_dir": { "type": "string", "required": true, "description": "Path to skill directory with SKILL.spec.yaml" }
},
"output": {
"description": "Path to generated SKILL.behavior.yaml",
"fields": { "path": "string" }
},
"entrypoints": {
"unix": ["python3", "scripts/generate_contract.py", "{skill_dir}"],
"windows": ["python", "scripts/generate_contract.py", "{skill_dir}"]
}
},
"coverage-gate": {
"description": "Scan project for scripts/modules missing behavior specs.",
"input": {
"project_dir": { "type": "string", "required": true, "description": "Root directory to scan" },
"patterns": { "type": "string", "required": false, "description": "Comma-separated glob patterns (default: **/*.py,**/*.sh)" },
"exclude": { "type": "string", "required": false, "description": "Patterns to exclude (default: test_*,__pycache__,.*)" }
},
"output": {
"description": "Coverage report with covered/uncovered lists and percentage",
"fields": { "covered": "array", "uncovered": "array", "coverage_pct": "number" }
},
"entrypoints": {
"unix": ["python3", "scripts/coverage_gate.py", "{project_dir}"],
"windows": ["python", "scripts/coverage_gate.py", "{project_dir}"]
}
},
"build-graph": {
"description": "Build a cross-skill dependency graph from SKILL.spec.yaml files.",
"input": {
"skills_dir": { "type": "string", "required": false, "description": "Root directory to scan (default: ./skills)" },
"output_format": { "type": "string", "required": false, "description": "mermaid, json, or sql" }
},
"output": {
"description": "Graph output in the requested format",
"fields": { "graph": "string|json" }
},
"entrypoints": {
"unix": ["python3", "scripts/build_graph.py", "--skills-dir", "{skills_dir}", "--format", "{output_format}"]
}
},
"refresh-projections": {
"description": "Refresh behavior projection bundles from SKILL.spec.yaml files for behavior_* tables.",
"input": {
"skills_dir": { "type": "string", "required": false, "description": "Root directory to scan (default: ./skills)" },
"output_format": { "type": "string", "required": false, "description": "json or sql" }
},
"output": {
"description": "Projection bundle or SQL statements for behavior_* refresh",
"fields": { "bundle": "json|string" }
},
"entrypoints": {
"unix": ["python3", "scripts/refresh_behavior_projections.py", "--skills-dir", "{skills_dir}", "--format", "{output_format}"]
}
}
},
"stdout_contract": {
"last_line_json": true
}
}