| id | PRD-005 |
|---|---|
| title | Knowledge Embedding |
| type | PRD |
| status | Accepted |
| version | 1 |
| date | 2026-04-04 |
| last_reviewed | 2026-04-17 |
Phase: 9
Convert 20+ removed static documentation files into living system components: a Claude Code skill, two MCP tools, one new agent, four enriched agents, and enhanced hook coverage. See ADR-006 for the architectural rationale.
File: .claude/skills/specflow.md
Source knowledge: SKILL.md (core operating loop, pre-flight gates, security patterns)
The skill file must include:
- Core operating loop — the sequence every Specflow-aware session follows (check board → pick issue → verify contracts → implement → test → enforce → commit)
- Pre-flight gates — what to check before writing code (issue exists, contracts loaded, doctor passes)
- Security patterns — OWASP-aligned rules that apply to all generated code
- Agent behaviors — when to invoke which agent (e.g., contract-generator for new features, heal-loop for violations)
- Model routing guidance — which tasks benefit from which model tier
- Command quick reference — all
specflowCLI commands with one-line descriptions
- File is included in
package.jsonfilesarray so it ships withnpm install specflow initcopies it to<project>/.claude/skills/specflow.md- If the file already exists,
initchecks for a version marker comment and only overwrites if the shipped version is newer - Claude Code automatically loads files from
.claude/skills/as ambient context
-
.claude/skills/specflow.mdexists in the package -
specflow init .copies it to the target project - Second
initdoes not duplicate or corrupt the file - Claude Code loads the skill and applies its guidance in sessions
Source knowledge: CONTRACT-SCHEMA.md, CONTRACTS-README.md
| Field | Value |
|---|---|
| Tool name | specflow_get_schema |
| Description | Returns the complete YAML contract schema specification |
| Inputs | section (optional): "full" (default), "fields", "patterns", "examples" |
| Output | Markdown-formatted schema documentation |
| Implementation | ts-src/mcp/tools.ts — new handler |
Behavior:
section: "full"— returns complete schema with all fields, types, and descriptionssection: "fields"— returns only the field reference (name, type, required, description)section: "patterns"— returns pattern syntax guide with regex examplessection: "examples"— delegates tospecflow_get_example
The schema content is defined inline in the tool handler (not read from a file), so it stays in sync with the parser.
Source knowledge: Example contracts scattered across removed docs
| Field | Value |
|---|---|
| Tool name | specflow_get_example |
| Description | Returns an annotated example contract |
| Inputs | type (optional): "feature" (default), "journey", "security", "defaults" |
| Output | YAML contract with inline comments explaining each field |
| Implementation | ts-src/mcp/tools.ts — new handler |
Behavior:
- Returns a complete, valid YAML contract of the requested type
- Every field has an inline
# commentexplaining its purpose - The example is hardcoded in the tool (not read from templates/) to ensure annotations are always present
- Both tools appear in
specflow mcp toolsoutput -
specflow_get_schemareturns accurate, complete schema documentation -
specflow_get_examplereturns valid, annotated YAML for each type - Schema matches the actual contract parser behavior
Source knowledge: MID-PROJECT-ADOPTION.md, adoption strategy guidance
---
name: adoption-advisor
description: Guides teams through adopting Specflow in existing projects — from first contract to full enforcement
category: lifecycle
trigger: Adopt Specflow in an existing project
inputs:
- Current project tech stack
- Existing test framework
- Team size and workflow
- Current pain points
outputs:
- Phased adoption plan
- Starter contracts tailored to the project
- Hook installation guide
- Risk assessment
contracts:
- feature_specflow_project
---The agent prompt must cover:
- Assessment phase — what to audit in the existing project (test coverage, CI setup, code structure)
- Contract selection — which default contracts to start with based on the tech stack
- Phased rollout — start with security_defaults (least disruptive), then add feature contracts
- Hook installation — how to install without disrupting existing CI
- Team onboarding — how to introduce contracts to developers who haven't used them
- Escape hatches — how to defer rules during adoption (
specflow defer)
-
agents/adoption-advisor.mdexists with valid frontmatter -
specflow agent listincludes it in the lifecycle category -
specflow agent show adoption-advisorreturns the full prompt - Content covers all 6 sections above
Added knowledge: PROTOCOL.md (TeammateTool usage), WORKFLOW.md (state machine)
Add to the agent prompt body:
- TeammateTool protocol: how to spawn sub-agents, pass context, collect results, handle failures
- State machine: issue states (open → in-progress → review → done), transition rules, who can transition
- Team coordination: which agents form teams, team names, escalation paths
Added knowledge: WORKFLOW.md (state machine, execution sequence)
Add to the agent prompt body:
- Execution sequence: for each issue in a sprint — check contracts → implement → test → enforce → commit → move issue
- Failure handling: what to do when enforce fails (invoke heal-loop), when tests fail (debug before retrying)
- Progress reporting: how to report sprint progress back to the orchestrator
Added knowledge: CONTRACT-SCHEMA.md (full schema), CONTRACT-SCHEMA-EXTENSIONS.md (soft rules, auto_fix)
Add to agent's contracts field or prompt body:
- Complete field reference: all YAML fields, types, required/optional, valid values
- Extension fields:
severity(error/warning/info),auto_fix(regex replacement),soft(advisory-only rules) - Pattern syntax: regex features supported, common patterns, escape rules
- Scope syntax: glob patterns for file targeting
Added knowledge: CONTRACT-SCHEMA-EXTENSIONS.md (auto_fix patterns)
Add to agent's contracts field or prompt body:
- auto_fix protocol: how
auto_fixregex replacements work, when to apply them vs. manual fix - Severity handling: errors block, warnings advise, info is silent
- Remediation strategy: fix violations in order of severity, re-run enforce after each batch
- waves-controller prompt includes TeammateTool protocol and state machine
- sprint-executor prompt includes execution sequence and failure handling
- contract-generator has full schema and extension knowledge in context
- heal-loop has auto_fix and severity knowledge in context
- All enriched agents still have valid frontmatter after changes
File: ts-src/hooks/check-compliance.ts
Source knowledge: Pipeline compliance gaps, simulation Edge 5
Scan for test files that don't have a matching contract:
For each file in tests/**/*.test.{js,ts}:
Extract the feature/journey name from the filename
Check if a matching contract exists in .specflow/contracts/
If no match: report as orphan test (WARNING)
Scan for contracts that don't have a matching test:
For each file in .specflow/contracts/*.yml:
Extract the contract name
Check if a matching test exists in tests/
If no match: report as orphan contract (WARNING)
Scan for journey CSVs that haven't been compiled to contracts + test stubs:
For each file in **/*.csv matching journey pattern:
Check if a corresponding contract exists in .specflow/contracts/
Check if a corresponding test stub exists in tests/
If either missing: report as uncompiled journey (WARNING)
-
check-compliance.tsdetects orphan tests and reports them -
check-compliance.tsdetects orphan contracts and reports them -
check-compliance.tsdetects uncompiled journey CSVs and reports them - Warnings don't block the build (exit 0) but are visible in output
- Integration test covers each detection case
With the adoption of sql.js (WASM SQLite) as the knowledge graph storage backend (ADR-007 Amended, PRD-006), several components specified above gain a persistent, queryable backend:
The Claude Code skill (Component 1) delivers knowledge as ambient context. The knowledge graph extends this with a learned skill library — reusable fix patterns extracted from enforcement history:
- Skills are stored as Skill nodes in the knowledge graph (
.specflow/knowledge.db) - Each skill has a confidence score based on success/failure ratio
- The heal-loop agent queries the skill library before attempting fixes
- New skills are discovered automatically after N successful fixes of the same pattern (frequency-based extraction via SQL GROUP BY)
The static skill file (.claude/skills/specflow.md) provides the operating framework; the SQL-backed skill library provides learned, project-specific fix patterns.
The MCP tools (Component 2) return schema documentation on demand. The knowledge graph extends this with SQL-backed queries:
specflow_get_schema— returns static schema documentation (unchanged)specflow_query_graph— executes SQL queries against contract/rule/pattern nodes in the graphspecflow_get_fix_suggestion— queries the skill library for a specific violation
Schema knowledge is represented in the graph as Contract + Rule + Pattern nodes (rows in the nodes table), enabling queries like "which rules apply to this file?" or "what patterns does SEC-003 check for?"
Agent enrichment (Component 4) embeds coordination knowledge in prompts. The knowledge graph extends this with SQL-backed agent relationships:
- Agents are graph nodes with edges to the contracts they fix
- Agent performance (fix_count, success_rate) is tracked in the graph
- Agent routing queries identify the best agent for a violation type
The specflow_get_example MCP tool (Component 2b) returns hardcoded annotated examples. Future enhancement — graph-derived examples:
- Query the graph for the most common violation patterns
- Generate example contracts that address those patterns
- Include real fix suggestions from the skill library as inline annotations
This is a future enhancement — the static examples remain the default until the graph has sufficient history.