Behavior Spec Writing
Write Gherkin-based behavior specifications that define expected system behavior across features and core modules. Specs serve dual purpose: verification criteria and agent memory for understanding system behavior.
Workflow
- •Read the implementation plan from
docs/plan/to understand the change scope - •Identify affected dimensions:
- •Feature spec: new/changed feature →
docs/spec/feature-spec/{feature-name}.feature - •Core specs: evaluate impact on each core module →
docs/spec/core-spec/{module}.feature
- •Feature spec: new/changed feature →
- •Read existing spec files for affected modules (if they exist)
- •Draft new/updated specs as standard Gherkin
.featurefiles (seereferences/spec-format.md) - •Ensure gherkin-lint config exists in the repo root:
- •If
.gherkin-lintcdoes not exist, copy the bundled config from this skill:cp "$HOME/.agents/skills/behavior-spec-writing/.gherkin-lintc" ./.gherkin-lintc
- •If
- •Lint the drafted spec content (use a temp file if you haven't written the final path yet):
- •
npx -y gherkin-lint -c .gherkin-lintc <path/to/spec.feature> - •Fix lint issues and re-run until clean
- •
- •Present specs to user for review before writing
- •Write approved specs to the correct file paths
- •After writing, lint the created/updated
.featurefiles again with gherkin-lint (must be clean)
File Structure
Feature Specs — per feature, created/updated with each feature change
docs/spec/feature-spec/{feature-name}.feature
Example: docs/spec/feature-spec/order-strategy.feature
One file per feature. Created when a new feature is introduced. Updated when the feature changes.
Core Specs — per core module, long-lived and stable
docs/spec/core-spec/{module}.feature
Example: Fixed core modules (create only when first needed, then maintain):
- •
docs/spec/core-spec/predict.feature— prediction engine behavior - •
docs/spec/core-spec/bet.feature— betting logic behavior - •
docs/spec/core-spec/order.feature— order processing behavior - •
docs/spec/core-spec/data-sync.feature— data synchronization behavior - •
docs/spec/core-spec/trigger.feature— trigger/event behavior
After any feature change, evaluate ALL core modules for behavioral impact. Update affected core specs to keep them consistent. Do NOT update core specs that are unaffected.
Spec File Format
Use standard Gherkin .feature format. See references/spec-format.md for the complete format reference and examples.
Key rules:
- •Write in declarative style — describe WHAT the system does, not HOW
- •Use business language, not implementation details
- •Cover happy path, edge cases, and error handling
- •Use
Scenario Outline+Examplesfor parameterized cases - •Tag scenarios:
@happy-path,@edge-case,@error-handling,@regression - •Write specs in the language matching the project (Chinese comments OK if project uses Chinese)
Impact Assessment Checklist
When a new feature or change is planned, evaluate each core module: Mark affected modules → read their current specs → draft updates → present to user.
Review Protocol
ALWAYS present drafted specs to the user before writing files:
- •Show the impact assessment checklist result
- •For each affected file, show the full
.featurecontent - •Highlight what changed vs. previous version (if updating)
- •Wait for user approval or revision requests
- •Only write files after approval