# story-context Workflow Rule

This rule defines the story-context workflow.

## Workflow Description

Assemble a dynamic Story Context XML by pulling latest documentation and existing code/library artifacts relevant to a drafted story

## Workflow Definition

# Story Context Creation Workflow
name: story-context
description: "Assemble a dynamic Story Context XML by pulling latest documentation and existing code/library artifacts relevant to a drafted story"
author: "BMad"

# Critical variables
config_source: "{project-root}/.bmad/bmm/config.yaml"
output_folder: "{config_source}:output_folder"
user_name: "{config_source}:user_name"
communication_language: "{config_source}:communication_language"
document_output_language: "{config_source}:document_output_language"
story_path: "{config_source}:sprint_artifacts"
date: system-generated
sprint_artifacts: "{config_source}:sprint_artifacts"
sprint_status: "{sprint_artifacts}/sprint-status.yaml || {output_folder}/sprint-status.yaml"

# Workflow components
installed_path: "{project-root}/.bmad/bmm/workflows/4-implementation/story-context"
template: "{installed_path}/context-template.xml"
instructions: "{installed_path}/instructions.md"
validation: "{installed_path}/checklist.md"

# Smart input file references - handles both whole docs and sharded docs
# Priority: Whole document first, then sharded version
# Strategy: SELECTIVE LOAD - only load the specific epic needed for this story
input_file_patterns:
  prd:
    description: "Product requirements (optional)"
    whole: "{output_folder}/*prd*.md"
    sharded: "{output_folder}/*prd*/*.md"
    load_strategy: "FULL_LOAD"
  tech_spec:
    description: "Technical specification (Quick Flow track)"
    whole: "{output_folder}/tech-spec.md"
    load_strategy: "FULL_LOAD"
  architecture:
    description: "System architecture and decisions"
    whole: "{output_folder}/*architecture*.md"
    sharded: "{output_folder}/*architecture*/*.md"
    load_strategy: "FULL_LOAD"
  ux_design:
    description: "UX design specification (if UI)"
    whole: "{output_folder}/*ux*.md"
    sharded: "{output_folder}/*ux*/*.md"
    load_strategy: "FULL_LOAD"
  epics:
    description: "Epic containing this story"
    whole: "{output_folder}/*epic*.md"
    sharded_index: "{output_folder}/*epic*/index.md"
    sharded_single: "{output_folder}/*epic*/epic-{{epic_num}}.md"
    load_strategy: "SELECTIVE_LOAD"
  document_project:
    description: "Brownfield project documentation (optional)"
    sharded: "{output_folder}/index.md"
    load_strategy: "INDEX_GUIDED"

# Output configuration
# Uses story_key from sprint-status.yaml (e.g., "1-2-user-authentication")
default_output_file: "{story_path}/{{story_key}}.context.xml"

standalone: true


## Usage

Reference this workflow with `@workflow-story-context` to execute the guided workflow.

## Module

Part of the BMAD BMM module.
