src/main/resources/targets/claude/skills/core/dev/x-detect-spec-drift/SKILL.md
Detects spec-code drift by comparing story data contracts, endpoints, and Gherkin scenarios against implemented code. Supports standalone mode (full report) and inline mode (compact output for TDD loop integration in x-implement-story Phase 2).
npx skillsauth add edercnj/claude-environment x-detect-spec-driftInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Compares story specifications (data contracts, endpoints, Gherkin scenarios) against implemented code to detect drift. Operates in two modes:
/x-detect-spec-drift STORY-ID — standalone mode (full report)/x-detect-spec-drift STORY-ID --mode inline — inline mode (compact output)| Parameter | Type | Default | Values | Description |
|-----------|------|---------|--------|-------------|
| STORY-ID | String | required | story identifier | Story to check for drift |
| --mode | String | standalone | standalone, inline | Output mode |
| Mode | When to Use | Output |
|------|-------------|--------|
| standalone | Manual invocation before PR | Full itemized report |
| inline | Automated call in x-implement-story Phase 2 | Single-line compact summary |
1. PARSE -> Read story file, extract data contracts + endpoints + Gherkin
2. SCAN -> Search source code for matching fields, endpoints, tests
3. CHECK -> Compare spec vs code, classify drift (PASS/WARN/FAIL)
4. REPORT -> Generate itemized report with severity
Read the story markdown file and extract:
POST /v1/payments)@GK-N and titlesCONSTITUTION.md exists in project rootFor each extracted item, search the source tree:
@GK-N| Check Type | Severity | Condition |
|-----------|----------|-----------|
| Field Missing (M) | FAIL | Mandatory field from data contract not found in any DTO/Record |
| Field Missing (O) | WARN | Optional field absent from code |
| Field Type Mismatch | WARN | Field found but type differs from spec |
| Endpoint Missing | FAIL | Declared endpoint not found in any controller |
| Scenario Uncovered | WARN | @GK-N without corresponding acceptance test |
| Naming Violation | WARN | CONSTITUTION.md naming convention violated |
Output follows itemized format with severity:
=== Spec Drift Check — STORY-XXXX-YYYY ===
Data Contracts:
PASS FieldName (Type, M) -> found in ClassName
FAIL FieldName (Type, M) -> NOT FOUND
WARN FieldName (Type, O) -> field absent (optional)
Endpoints:
PASS POST /path -> ControllerClass.methodName()
FAIL GET /path -> NOT FOUND in any controller
Gherkin Coverage:
PASS @GK-1 "title" -> AT-1 found (TestClass)
WARN @GK-3 "title" -> no AT found
Constitution Compliance:
PASS No violations detected
Summary: N FAIL, M WARN — DRIFT DETECTED / NO DRIFT
Provides compact, non-blocking drift checks after each RED-GREEN-REFACTOR cycle in x-implement-story Phase 2. Designed for automated integration — not manual invocation.
Inline mode performs a subset of standalone checks:
| Check | Inline Mode | Standalone Mode | |-------|------------|-----------------| | Data Contract fields (M) | Yes | Yes | | Data Contract fields (O) | Yes | Yes | | Field Type Mismatch | Yes | Yes | | Endpoint Missing | Yes | Yes | | Gherkin Coverage | No — reserved for standalone | Yes | | Constitution Compliance | No — reserved for standalone | Yes |
For non-critical results (PASS and WARN only):
Drift Check (inline): N PASS, M WARN — details of first warning
For critical drift (at least one FAIL):
Drift Check (inline): CRITICAL — FieldName (Type, M) NOT FOUND in DTO
Continue TDD loop despite critical drift? (y/n)
Called automatically by x-implement-story after each TDD cycle:
Phase 2 TDD Loop:
2.1 RED — write failing test
2.2 GREEN — make test pass
2.3 REFACTOR — improve design
2.4 DRIFT CHECK (inline) — verify spec alignment
2.5 COMMIT — atomic TDD commit
| Field | Type | Default | Description |
|-------|------|---------|-------------|
| enabled | boolean | true | Activate inline drift check (auto-enabled when story has data contract) |
| blockOnCritical | boolean | true | Pause TDD loop on critical FAIL |
| Field | Type | Description |
|-------|------|-------------|
| passCount | int | Total PASS checks |
| warnCount | int | Total WARN checks |
| failCount | int | Total critical FAIL checks |
| summary | String | Compact single-line message |
| criticalDetails | List | Details of FAIL items (empty if none) |
if story has no data contract:
skip inline check entirely
return
run data contract field checks (M and O)
run endpoint checks
if failCount > 0 and blockOnCritical:
emit CRITICAL message
prompt for confirmation
else:
emit summary message
continue TDD loop
| Scenario | Action | |----------|--------| | Story file not found | Abort with "Story file not found: {path}" | | No data contract in story | Standalone: report "No data contract defined" / Inline: skip silently | | Source root not accessible | Abort with "Source root not accessible: {path}" | | Malformed data contract | WARN with "Unable to parse data contract field: {line}" |
| Skill | Relationship | Context | |-------|-------------|---------| | x-implement-story | Called by | Invoked during Phase 2 TDD loop for inline drift detection | | x-implement-task | Complements | Drift check validates that implementation matches story spec | | x-review-pr | Complements | Standalone drift check provides pre-PR validation of spec alignment |
tools
Documentation automation v2: stack-aware generation from documentation.targets.
development
Generates or updates CI/CD pipelines per project stack with actionlint validation.
tools
Generates ADRs from architecture-plan mini-ADRs with sequential numbering and index update.
development
Formats source code; first step of the pre-commit chain (format -> lint -> compile).