```xml
The workflow execution engine is governed by: {project-root}/bmad/core/tasks/workflow.xml
You MUST have already loaded and processed: {installed_path}/workflow.yaml
Communicate all responses in {communication_language}
Generate all documents in {document_output_language}
This workflow assembles a Story Context file for a single drafted story by extracting acceptance criteria, tasks, relevant docs/code, interfaces, constraints, and testing guidance.
If story_path is provided, use it. Otherwise, find the first story with status "drafted" in sprint-status.yaml. If none found, HALT.
Check if context file already exists. If it does, ask user if they want to replace it, verify it, or cancel.
DOCUMENT OUTPUT: Technical context file (.context.xml). Concise, structured, project-relative paths only.
Use {{story_path}} directly
Read COMPLETE story file and parse sections
Extract story_key from filename or story metadata
Verify Status is "drafted" - if not, HALT with message: "Story status must be 'drafted' to generate context"
MUST read COMPLETE sprint-status.yaml file from start to end to preserve order
Load the FULL file: {{output_folder}}/sprint-status.yaml
Read ALL lines from beginning to end - do not skip any content
Parse the development_status section completely
Find FIRST story (reading in order from top to bottom) where:
- Key matches pattern: number-number-name (e.g., "1-2-user-auth")
- NOT an epic key (epic-X) or retrospective (epic-X-retrospective)
- Status value equals "drafted"
HALT
Use the first drafted story found
Find matching story file in {{story_dir}} using story_key pattern
Read the COMPLETE story file
Extract {{epic_id}}, {{story_id}}, {{story_title}}, {{story_status}} from filename/content
Parse sections: Story, Acceptance Criteria, Tasks/Subtasks, Dev Notes
Extract user story fields (asA, iWant, soThat)
story_tasks
acceptance_criteria
Check if file exists at {default_output_file}
Choose action (replace/verify/cancel):
GOTO validation_step
HALT with message: "Context generation cancelled"
Continue to generate new context file
Store project root path for relative path conversion: extract from {project-root} variable
Define path normalization function: convert any absolute path to project-relative by removing project root prefix
Initialize output by writing template to {default_output_file}
as_a
i_want
so_that
Scan docs and src module docs for items relevant to this story's domain: search keywords from story title, ACs, and tasks.
Prefer authoritative sources: PRD, Architecture, Front-end Spec, Testing standards, module-specific docs.
For each discovered document: convert absolute paths to project-relative format by removing {project-root} prefix. Store only relative paths (e.g., "docs/prd.md" not "/Users/.../docs/prd.md").
Add artifacts.docs entries with {path, title, section, snippet}:
- path: PROJECT-RELATIVE path only (strip {project-root} prefix)
- title: Document title
- section: Relevant section name
- snippet: Brief excerpt (2-3 sentences max, NO invention)
Search source tree for modules, files, and symbols matching story intent and AC keywords (controllers, services, components, tests).
Identify existing interfaces/APIs the story should reuse rather than recreate.
Extract development constraints from Dev Notes and architecture (patterns, layers, testing requirements).
For all discovered code artifacts: convert absolute paths to project-relative format (strip {project-root} prefix).
Add artifacts.code entries with {path, kind, symbol, lines, reason}:
- path: PROJECT-RELATIVE path only (e.g., "src/services/api.js" not full path)
- kind: file type (controller, service, component, test, etc.)
- symbol: function/class/interface name
- lines: line range if specific (e.g., "45-67")
- reason: brief explanation of relevance to this story
Populate interfaces with API/interface signatures:
- name: Interface or API name
- kind: REST endpoint, GraphQL, function signature, class interface
- signature: Full signature or endpoint definition
- path: PROJECT-RELATIVE path to definition
Populate constraints with development rules:
- Extract from Dev Notes and architecture
- Include: required patterns, layer restrictions, testing requirements, coding standards
Detect dependency manifests and frameworks in the repo:
- Node: package.json (dependencies/devDependencies)
- Python: pyproject.toml/requirements.txt
- Go: go.mod
- Unity: Packages/manifest.json, Assets/, ProjectSettings/
- Other: list notable frameworks/configs found
Populate artifacts.dependencies with keys for detected ecosystems and their packages with version ranges where present
From Dev Notes, architecture docs, testing docs, and existing tests, extract testing standards (frameworks, patterns, locations).
Populate tests.standards with a concise paragraph
Populate tests.locations with directories or glob patterns where tests live
Populate tests.ideas with initial test ideas mapped to acceptance criteria IDs
Validate output context file structure and content
Validate against checklist at {installed_path}/checklist.md using bmad/core/tasks/validate-workflow.xml
Open {{story_path}}
Find the "Status:" line (usually at the top)
Update story file: Change Status to "ready-for-dev"
Under 'Dev Agent Record' → 'Context Reference' (create if missing), add or update a list item for {default_output_file}.
Save the story file.
Load the FULL file: {{output_folder}}/sprint-status.yaml
Find development_status key matching {{story_key}}
Verify current status is "drafted" (expected previous state)
Update development_status[{{story_key}}] = "ready-for-dev"
Save file, preserving ALL comments and structure including STATUS DEFINITIONS
```