Personas & Executable BDD User Story Specifications

SpecOps models user needs and verifiable acceptance contracts as version-locked Markdown documents under docs/project/user_stories/ (Area 3 of the Declarative Specification Grammar defined in ADR-0022).

This reference specification defines the canonical directory topology, YAML frontmatter schemas, Markdown AST section grammars, regex extraction patterns, frontdoor Gherkin verification rules, and registry table format for User Personas and Executable BDD User Stories.


1. Directory Layout & File Topology

All persona and user story artifacts reside under docs/project/user_stories/:


docs/project/user_stories/
β”œβ”€β”€ PERSONAS.md                           # Canonical user archetype profiles
β”œβ”€β”€ REGISTRY.md                           # Sequential pipe-table index of all user stories
└── accepted/                             # Active executable BDD user story specifications
    β”œβ”€β”€ us-0001-project-init.md
    β”œβ”€β”€ us-0002-invariant-health.md
    └── us-XXXX-<slug>.md                 # Four-digit zero-padded story ID + kebab-case slug

Topology & Naming Rules

Artifact Class Path Pattern Filename Regex Frontmatter Policy
Persona Catalog docs/project/user_stories/PERSONAS.md ^PERSONAS\.md$ Optional / Ignored by schema audit (is_specification_file() -> False)
Story Registry docs/project/user_stories/REGISTRY.md ^REGISTRY\.md$ Forbidden (is_specification_file() -> False)
Executable User Story docs/project/user_stories/accepted/us-XXXX-.md ^us-\d{4}-[a-z0-9-]+\.md$ Required (UserStoryFrontmatter, extra="forbid")

2. `PERSONAS.md` Document Structure & Grammar

docs/project/user_stories/PERSONAS.md is a single multi-section Markdown document that defines every human stakeholder and autonomous agent archetype interacting with the system.

2.1 Document AST Grammar

  1. H1 Document Header:
  1. H2 Persona Archetype Sections:
  1. Required Bullet Sub-sections:

2.2 Canonical `PERSONAS.md` Example


# SpecOps User Personas

Archetypes representing the software architects, engineering leads, and autonomous AI agents who interact with and rely on SpecOps.

---

## 1. Alex β€” The Agentic Systems Architect
- **Role**: Staff engineer and platform architect building complex, distributed systems with AI coding assistants.
- **Pain Points**:
  - Context rot when specifications stored in external SaaS tools (Jira, Linear) drift from git code.
  - Monolithic file sprawl (>500 lines) causing LLMs to lose context and introduce subtle bugs.
- **Goals with SpecOps**:
  - Version-lock all project specifications (Personas, PRDs, Stories, Tasks, ADRs) in git alongside code.
  - Non-negotiable file length caps (<500 lines) keeping codebases modular and LLM-friendly.

2.3 Parser Extraction Rules (`parse_personas` & `PersonaDocument`)

SpecOps provides two complementary parsers for PERSONAS.md:

  1. Graph & Core Domain Parser (parse_personas in src/spec_ops/core/parser.py):
  1. Round-Trip Document Model (PersonaDocument.parse in src/spec_ops/core/persona_models.py):
  1. Composite Persona Mention Resolution (PersonaEngine.extract_persona_mentions):

3. User Story YAML Frontmatter Schema (`UserStoryFrontmatter`)

Every file in docs/project/user_stories/accepted/us-XXXX-.md must begin with a YAML frontmatter block (--- ... ---) validated against UserStoryFrontmatter in src/spec_ops/core/schema_validator.py.

3.1 Field Reference Table

Field Type Required Default Description & Constraints
id `str \ int (Any`) Yes β€” Four-digit zero-padded string ('0133') or canonical ID ('US-0133'). Normalized to US-XXXX by parse_user_story.
title str Yes β€” Human-readable user story title matching the H1 heading and REGISTRY.md entry.
persona str Yes β€” Target persona name or composite reference (e.g., "Alex", "Alex (The Agentic Systems Architect)", "Alex & Jordan"). Must resolve to a known persona in PERSONAS.md.
governing_prd str Yes β€” Canonical ID of the parent PRD in docs/project/product/ (e.g., "PRD-0008"). Verified for relational existence by StoryEngine.trace().
status str No "Accepted" Lifecycle status of the story ("Accepted" for active stories in accepted/).
created `date \ str \ None` No None ISO-8601 creation date (YYYY-MM-DD).
feature Optional[str] No None Feature cluster identifier (FEAT--, e.g., "FEAT-SPEC-01"). Displayed in REGISTRY.md.
target_bc Optional[str] No None Target DDD bounded context slug (e.g., "core", "docs", "cli").
scenarios Optional[list[str]] No None Summary list of Gherkin scenario titles covered by this user story.
outcome_id `Optional[int \ str]` No None Optional 1-indexed PRD Checkable Outcome identifier used by src/spec_ops/prd/delta.py during incremental PRD delta decomposition (find_existing_stories). Note: under strict UserStoryFrontmatter (extra="forbid"), persisted stories in accepted/ omit outcome_id unless explicitly permitted by schema extensions.

3.2 Strict `extra="forbid"` Policy: What Can and Cannot Be Tracked

UserStoryFrontmatter enforces model_config = ConfigDict(extra="forbid") under SpecOps Schema v2.0 (src/spec_ops/core/schema_validator.py). Any unrecognized YAML key raises a SchemaDiagnosticError with err_type == "extra_forbidden" pinpointing the exact file, line, and column:


error: Schema Validation Error in docs/project/user_stories/accepted/us-0133-example.md:11:1
|
11 | dependencies: [TASK-0001]
| ^ Forbidden extra field 'dependencies' in schema v2.0

4. User Story Markdown Body AST Grammar

Following the closing --- frontmatter delimiter, the Markdown body of a user story must follow a deterministic section structure so parse_user_story (src/spec_ops/core/parser.py) and StoryEngine (src/spec_ops/core/story_engine.py) can extract domain attributes without ambiguity.

4.1 Required & Optional Sections

  1. H1 Title Heading (# US-XXXX β€” </code>)</strong>:</li> </ol> <ul> <li>Uses an em-dash (<code>β€”</code>) separating the canonical story ID (<code>US-XXXX</code>) and the story title.</li> </ul> <ol> <li><strong>Governing PRD Section (<code>## Governing PRD</code>)</strong>:</li> </ol> <ul> <li>Contains a bulleted relative Markdown link to the governing PRD file in <code>docs/project/product/accepted/</code>: ```markdown ## Governing PRD</li> <li><a href="../../product/accepted/prd-0008-formal-specification-grammar--document-metamo.html"><code>PRD-0008: Formal Specification Grammar, Document Metamodel & Project Directory Schema Engine</code></a> ```</li> </ul> <ol> <li><strong>User Story Narrative Block (<code>## User Story</code>)</strong>:</li> </ol> <ul> <li>Contains the three canonical Connextra narrative clauses (<code><strong>As a</strong></code> / <code><strong>As an</strong></code>, <code><strong>I want</strong></code>, <code><strong>So that</strong></code>).</li> </ul> <ol> <li><strong>Executable Acceptance Criteria (<code>## Acceptance Criteria</code>)</strong>:</li> </ol> <ul> <li>Contains one or more fenced <code> </code>`<code>gherkin </code> code blocks, each defining an executable <code>Scenario:</code> with <code>Given</code>, <code>When</code>, <code>Then</code> steps.</li> </ul> <ol> <li><strong>Optional Rationale Section (<code>## Rationale & Compelling Value</code>)</strong>:</li> </ol> <ul> <li>Provides architectural context or domain rationale below the acceptance criteria.</li> </ul> <h3>4.2 Narrative Clause Regex Extraction Rules</h3> <p><code>parse_user_story(file_path)</code> in <code>src/spec_ops/core/parser.py</code> populates the <code>UserStory(as_a, i_want, so_that, scenarios)</code> fields using case-insensitive regular expressions across the document content:</p> <div class="table-wrapper"><table><thead><tr> <th><code>UserStory</code> Attribute</th> <th>Extraction Regex Pattern (<code>re.IGNORECASE</code>)</th> <th>Termination Delimiter</th> </tr></thead><tbody> <tr> <td><code>as_a</code></td> <td><code>r"\<em>\</em>As an?\<em>\</em>\s*([^\n,]+)"</code></td> <td>Stops at the first comma (<code>,</code>) or newline (<code>\n</code>). Supports both <code><strong>As a</strong></code> and <code><strong>As an</strong></code>.</td> </tr> <tr> <td><code>i_want</code></td> <td><code>r"\<em>\</em>I want\<em>\</em>\s*([^\n,]+)"</code></td> <td>Stops at the first comma (<code>,</code>) or newline (<code>\n</code>).</td> </tr> <tr> <td><code>so_that</code></td> <td><code>r"\<em>\</em>So that\<em>\</em>\s*([^\n.]+)"</code></td> <td>Stops at the first period (<code>.</code>) or newline (<code>\n</code>).</td> </tr> <tr> <td><code>scenarios</code></td> <td><code>r"Scenario:\s*(.+)"</code> (<code>re.findall</code>)</td> <td>Extracts the trimmed title of every <code>Scenario:</code> line inside the document body.</td> </tr> </tbody></table></div> <blockquote> <p>[!IMPORTANT] Because <code>as_a</code> and <code>i_want</code> stop at the first comma (<code>,</code>) and <code>so_that</code> stops at the first period (<code>.</code>), narrative clauses should place their trailing punctuation at the end of the line: ``<code>markdown <strong>As an</strong> Alex (The Agentic Systems Architect), <strong>I want</strong> declarative reference specifications for all project documents, <strong>So that</strong> humans and autonomous agents can author valid specifications without guesswork. </code>``</p> </blockquote> <h3>4.3 Executable Gherkin `Scenario:` Grammar & Frontdoor Verification Rules</h3> <p>Under <a href="../../project/adrs/accepted/adr-0003-blackbox-frontdoor-verification.html">ADR-0003</a> (Blackbox Frontdoor Verification) and <a href="../../project/adrs/accepted/adr-0006-executable-bdd-user-stories.html">ADR-0006</a> (Executable BDD User Stories), every user story in <code>docs/project/user_stories/accepted/</code> acts as an executable specification:</p> <ol> <li><strong>Fenced Gherkin Blocks</strong>:</li> </ol> <ul> <li>Scenarios are enclosed in <code> </code>`<code>gherkin ... </code>`<code> </code> fenced code blocks under <code>## Acceptance Criteria</code>.</li> <li>Each block begins with <code>Scenario: <Descriptive Scenario Title></code> followed by indented step lines beginning with <code>Given </code>, <code>When </code>, <code>Then </code>, or <code>And </code>.</li> </ul> <ol> <li><strong>Public Frontdoor Setup & Assertions Only</strong>:</li> </ol> <ul> <li><strong><code>Given</code> (Preconditions)</strong>: Test setup must initialize state exclusively through public frontdoors (CLI commands, public configuration files, or public domain constructors)β€”never by mutating private attributes or injecting mock objects.</li> <li><strong><code>When</code> (Action)</strong>: Triggers an observable public entry point (e.g., <code>When the architect runs "spec-ops schema check"</code>).</li> <li><strong><code>Then</code> / <code>And</code> (Observable Outcomes)</strong>: Verifies return codes, stdout/stderr diagnostics, generated files, or public domain return values.</li> </ul> <ol> <li><strong>Zero Private Mock Backdoors</strong>:</li> </ol> <ul> <li>Acceptance tests and <code>pytest-bdd</code> step definitions (<code>tests/acceptance/</code>) are audited by <code>spec-ops audit-tests</code> (<code>src/spec_ops/quality/frontdoor_gate.py</code>).</li> <li>Reaching into <code>_private</code> attributes or patching internal module functions (<code>unittest.mock.patch</code> on internal domain methods) is a hard invariant violation.</li> </ul> <h3>4.4 Complete User Story Document Example</h3> <pre><code class="language-markdown"> --- id: '0133' title: "Comprehensive Reference Specifications for Project Document Structures and Configuration" status: Accepted created: 2026-10-15 persona: "Alex" target_bc: "docs" feature: "FEAT-SPEC-01" governing_prd: "PRD-0008" scenarios: - "Authoring reference specifications for PRDs personas user stories ADRs and backlog queues" --- # US-0133 β€” Comprehensive Reference Specifications for Project Document Structures and Configuration ## Governing PRD - [`PRD-0008: Formal Specification Grammar, Document Metamodel & Project Directory Schema Engine`](../../product/accepted/prd-0008-formal-specification-grammar--document-metamo.md) ## User Story **As an** Alex, **I want** an autonomous capability to execute "Comprehensive Reference Specifications for Project Document Structures and Configuration", **So that** business outcomes are delivered reliably across the docs bounded context. ## Acceptance Criteria </code></pre> <p>With the <code>## Acceptance Criteria</code> section containing one or more fenced <code>gherkin</code> scenario blocks:</p> <pre><code class="language-gherkin"> Scenario: Authoring reference specifications for PRDs personas user stories ADRs and backlog queues Given the system is initialized and ready When the user executes the workflow for "Authoring reference specifications for PRDs personas user stories ADRs and backlog queues" Then observable outputs satisfy public contracts without backdoor tampering. </code></pre> <hr /> <h2>5. User Story Registry Specification (`docs/project/user_stories/REGISTRY.md`)</h2> <p><code>docs/project/user_stories/REGISTRY.md</code> maintains a single-file tabular index of all accepted user stories, sorted in ascending numerical order by canonical Story ID (<code>US-0001</code> through <code>US-XXXX</code>).</p> <h3>5.1 Pipe Table Schema & Column Grammar</h3> <p>The document begins with <code># User Stories Registry</code> followed by a 6-column Markdown pipe table:</p> <pre><code class="language-markdown"> # User Stories Registry | ID | Title | Status | Persona | Feature | Governing PRD | |---|---|---|---|---|---| | `US-0001` | Project Initialization with Architectural Profiles | Accepted | Alex | FEAT-CORE-01 | `PRD-0001` | | `US-0117` | Autonomous Full-Lifecycle SDLC Orchestrator Skill & Multi-Agent Coordination | Accepted | Alex & Jordan | FEAT-ORCH-01 | `PRD-0006` | | `US-0133` | Comprehensive Reference Specifications for Project Document Structures and Configuration | Accepted | Alex | FEAT-SPEC-01 | `PRD-0008` | </code></pre> <div class="table-wrapper"><table><thead><tr> <th>Column</th> <th>Format</th> <th>Source & Normalization Rule in <code>StoryEngine.update_registry</code></th> </tr></thead><tbody> <tr> <td><code>ID</code></td> <td>`<code> </code>US-XXXX<code> </code>`</td> <td>Backtick-quoted canonical 4-digit story identifier (`r"\</td> <td>\s<em><code>US-(\d+)</code>\s</em>\</td> <td>"`).</td> </tr> <tr> <td><code>Title</code></td> <td>Plain text</td> <td>Exact story <code>title</code> from frontmatter.</td> </tr> <tr> <td><code>Status</code></td> <td>Plain text</td> <td>Lifecycle status (<code>Accepted</code>).</td> </tr> <tr> <td><code>Persona</code></td> <td>Plain text</td> <td>Short persona display name with parenthetical role descriptions stripped (<code>re.sub(r"\s<em>\([^)]</em>\)", "", persona).strip()</code>).</td> </tr> <tr> <td><code>Feature</code></td> <td>Plain text</td> <td>Feature code (<code>FEAT-<BC>-<NN></code>).</td> </tr> <tr> <td><code>Governing PRD</code></td> <td>`<code> </code>PRD-XXXX<code> </code>`</td> <td>Backtick-quoted canonical PRD identifier (<code>PRD-XXXX</code>).</td> </tr> </tbody></table></div> <h3>5.2 Atomic Update & Traceability Rules</h3> <ul> <li><strong>Atomic File Replacement</strong>: <code>StoryEngine.update_registry()</code> parses existing rows matching <code>| \</code>US-(\d+)\<code> |</code>, inserts or updates the row keyed by integer story number, sorts all rows by integer ID, writes to <code>REGISTRY.md.tmp</code>, and atomically replaces <code>REGISTRY.md</code>.</li> <li><strong>Bidirectional Traceability Audit (<code>StoryEngine.trace</code>)</strong>:</li> <li>Verifies every <code>UserStory</code> in <code>docs/project/user_stories/accepted/</code> links to an existing <code>PRD</code> in <code>docs/project/product/</code> (<code>governing_prd</code>) and a registered <code>Persona</code> in <code>PERSONAS.md</code> (<code>persona</code>).</li> <li>Maps implementing backlog tasks (<code>task.governing_stories</code>) and Git commit hashes (<code>GitMetadataHarvester</code>) back to each story, flagging stories without valid PRD or Persona links as <code>orphaned_stories</code> and <code>broken_references</code>.</li> </ul> <hr /> <h2>6. CLI & Python Verification Reference</h2> <h3>6.1 Public CLI Commands</h3> <pre><code class="language-bash"> # Audit persona coverage across PRDs, user stories, and git commits uv run spec-ops persona audit # Preview synthesized persona profiles for emerging archetypes uv run spec-ops persona sync --diff # Scaffold a new executable BDD user story and update REGISTRY.md uv run spec-ops story create --title "Example Capability" --prd PRD-0008 --persona Alex --bc core --dry-run # Audit bidirectional story traceability across Personas -> PRDs -> Stories -> Tasks -> Commits uv run spec-ops story trace # Validate UserStoryFrontmatter schema conformance across all specifications uv run spec-ops schema check </code></pre> <h3>6.2 Python Domain & Parser API</h3> <pre><code class="language-python"> from pathlib import Path from spec_ops.core.parser import parse_personas, parse_user_story from spec_ops.core.schema_validator import validate_document # 1. Parse PERSONAS.md into Persona(id, name, role, pain_points, goals) objects personas = parse_personas(Path("docs/project/user_stories/PERSONAS.md")) # 2. Parse a User Story file into a UserStory domain model story_path = Path( "docs/project/user_stories/accepted/us-0133-comprehensive-reference-specifications-for-project.md" ) story = parse_user_story(story_path) # 3. Validate UserStoryFrontmatter schema conformance (extra="forbid") errors = validate_document(story_path.read_text(encoding="utf-8"), file_path=story_path) assert len(errors) == 0 </code></pre> </main> <script type="module"> const mermaidNodes = document.querySelectorAll('.mermaid, pre code.language-mermaid'); if (mermaidNodes.length > 0) { document.querySelectorAll('pre code.language-mermaid').forEach(code => { const pre = code.parentElement; if (pre && pre.tagName.toLowerCase() === 'pre') { pre.className = 'mermaid'; pre.textContent = code.textContent; } }); try { const { default: mermaid } = await import('https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs'); mermaid.initialize({ startOnLoad: false, theme: 'dark', securityLevel: 'loose', }); await mermaid.run(); } catch (err) { console.error('Failed to load or render Mermaid diagrams:', err); } } </script> </body> </html>