skill-system-behavior

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Skill 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.yaml
:
yaml
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.yaml
For v2 behavior specs (
*.behavior.yaml
), you can also include an optional
interaction_diagram
Mermaid block to describe cross-node interactions.
yaml
interaction_diagram: |
  flowchart LR
    Script["runtime-doctor"] -->|"reads"| Config["config/memory.yaml"]
每个Skill的行为都定义在
SKILL.spec.yaml
文件中:
yaml
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版本的行为规范文件(
*.behavior.yaml
),你还可以选择性添加
interaction_diagram
Mermaid代码块,用于描述跨节点交互逻辑。
yaml
interaction_diagram: |
  flowchart LR
    Script["runtime-doctor"] -->|"reads"| Config["config/memory.yaml"]

Operations

核心操作

create-spec

create-spec

Scaffold a new
SKILL.spec.yaml
from the schema template.
  1. Read
    schema/spec-v1.yaml
    for the format
  2. Ask user for: skill name, description, operations (name + intent + inputs/outputs)
  3. Generate
    SKILL.spec.yaml
    in the target skill directory
  4. Include placeholder acceptance tests (structural defaults + behavioral stubs)
基于Schema模板快速生成新的
SKILL.spec.yaml
文件。
  1. 读取
    schema/spec-v1.yaml
    文件获取格式规范
  2. 向用户收集信息:Skill名称、描述、操作(名称+意图+输入/输出)
  3. 在目标Skill目录中生成
    SKILL.spec.yaml
    文件
  4. 包含占位符验收测试(默认结构化测试+行为测试桩)

validate-spec

validate-spec

Validate a
SKILL.spec.yaml
against the v1 schema.
  1. Read the target
    SKILL.spec.yaml
  2. Check required fields:
    schema_version
    ,
    skill_name
    ,
    description
    ,
    operations
  3. For each operation: verify
    name
    ,
    intent
    , at least one input or output, constraints present
  4. For acceptance_tests: verify structural tests include
    manifest-valid
    and
    scripts-exist
  5. 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
文件的合法性。
  1. 读取目标
    SKILL.spec.yaml
    文件
  2. 检查必填字段:
    schema_version
    skill_name
    description
    operations
  3. 针对每个操作:验证
    name
    intent
    字段,确保至少包含一个输入或输出,且存在约束条件
  4. 针对验收测试:验证结构化测试包含
    manifest-valid
    scripts-exist
    用例
  5. 输出结果:验证通过则返回摘要,失败则列出具体违规项
运行命令:
python3 scripts/validate_spec.py <path-to-SKILL.spec.yaml>

verify-structural

verify-structural

Run structural acceptance tests against a built skill.
  1. Read the skill's
    SKILL.spec.yaml
    for declared operations
  2. Read the skill's
    SKILL.md
    for the
    skill-manifest
    block
  3. Verify:
    • Every operation in spec has a matching operation in manifest
    • Every entrypoint script referenced in manifest exists on disk
    • skills-index.json
      includes this skill's capabilities
  4. Report: checklist with PASS/FAIL per test
针对已构建的Skill运行结构化验收测试。
  1. 读取Skill的
    SKILL.spec.yaml
    文件获取声明的操作
  2. 读取Skill的
    SKILL.md
    文件中的
    skill-manifest
  3. 验证以下内容:
    • 规范中声明的每个操作都在manifest中有对应项
    • manifest中引用的所有入口脚本都存在于磁盘上
    • skills-index.json
      文件包含该Skill的能力描述
  4. 输出结果:包含每个测试项通过/失败状态的检查清单

generate-contract

generate-contract

Generate a
SKILL.behavior.yaml
(Mermaid DAG) from a completed spec + implementation.
  1. Read
    SKILL.spec.yaml
    for operations, inputs, outputs, constraints
  2. Map operations → stages in a flowchart
  3. Map inputs → input nodes, outputs → output nodes
  4. Map constraints → error paths
  5. Write
    SKILL.behavior.yaml
    with embedded Mermaid diagram
This is the last step — only run after implementation is complete and tests pass.
根据已完成的规范和代码实现,生成
SKILL.behavior.yaml
文件(包含Mermaid DAG图)。
  1. 读取
    SKILL.spec.yaml
    文件中的操作、输入、输出和约束条件
  2. 将操作映射为流程图中的阶段节点
  3. 将输入映射为输入节点,输出映射为输出节点
  4. 将约束条件映射为错误路径
  5. 写入包含嵌入式Mermaid图的
    SKILL.behavior.yaml
    文件
这是最后一步 — 仅在代码实现完成且所有测试通过后运行。

Coverage Gate

覆盖率检查

Scan a project tree for scripts/modules that are missing behavior specs.
  1. Scan
    project_dir
    for scripts that match the configured patterns
  2. Scan for
    *.behavior.yaml
    files in the same tree
  3. Report covered/uncovered scripts using exact-name and SKILL convention matching
  4. 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."
扫描项目目录,找出缺少行为规范的脚本/模块。
  1. 扫描
    project_dir
    目录,匹配配置的文件模式
  2. 在同一目录树中扫描
    *.behavior.yaml
    文件
  3. 通过精确名称匹配和SKILL命名约定,报告已覆盖/未覆盖的脚本
  4. 输出人类可读的摘要,最后一行输出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:package
1. 理解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:package

Spec as Single Source of Truth

规范作为单一可信源

  • SKILL.spec.yaml
    — the authoritative definition (human-written, reviewed)
  • SKILL.md
    + manifest — implementation (must conform to spec)
  • SKILL.behavior.yaml
    — generated documentation (derived from spec)
  • SKILL.spec.yaml
    — 权威定义(人工编写、经过评审)
  • SKILL.md
    + manifest — 代码实现(必须符合规范要求)
  • 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
acceptance_tests.behavioral[].tested_by
in
SKILL.spec.yaml
to point to validating tests.
For cross-tier references, use optional
governance.tier
and
governance.traces_to
in
SKILL.spec.yaml
to declare where a spec sits and what higher/lower artifacts it traces to.
使用以下三级架构作为跨文件治理文档的组织指南:
一级架构 — 系统架构
  ├── SYSTEM_ARCHITECTURE.md    (系统边界与数据流)
  └── PIPELINE_DAG.md           (细节补充:状态机)

二级架构 — 行为契约
  ├── *.behavior.yaml           (单脚本:输入/输出/阶段/错误路径)
  └── BEHAVIOR_RUNTIME.md       (仅用于跨脚本交互场景)

三级架构 — 测试用例
  └── test_*.py                 (每个测试用例对应一个具体行为场景)
为了实现二级到三级架构的可追溯性,可在
SKILL.spec.yaml
文件中使用
acceptance_tests.behavioral[].tested_by
字段,指向对应的验证测试用例。
对于跨层级引用,可在
SKILL.spec.yaml
文件中选择性添加
governance.tier
governance.traces_to
字段,声明当前规范所属层级,以及它可追溯到的更高/更低层级的工件。

Cross-File Boundary Rules

跨文件边界规则

  • *.behavior.yaml
    defines single-script behavior only (inputs, outputs, stages, error paths for one script).
  • BEHAVIOR_RUNTIME.md
    is for cross-script scenarios only (2+ scripts interacting).
  • If a scenario involves only one script, place it in that script's
    .behavior.yaml
    , not in
    BEHAVIOR_RUNTIME.md
    .
  • When extending to new phases, avoid full-copy duplication; use references/overlay patterns so shared flows stay canonical.
  • *.behavior.yaml
    仅定义单脚本行为(单个脚本的输入、输出、阶段和错误路径)。
  • BEHAVIOR_RUNTIME.md
    仅用于跨脚本交互场景(涉及2个及以上脚本的交互)。
  • 如果场景仅涉及单个脚本,请将其放在该脚本的
    .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
  • intent
    describes WHY, not HOW — implementation details go in SKILL.md
  • 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
  • intent
    字段描述原因,而非实现方式 — 实现细节请放在SKILL.md文件中
  • 验收测试:行为测试使用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
  }
}