# Audit Workflow - Workflow Quality Audit Instructions
The workflow execution engine is governed by: {project-root}/bmad/core/tasks/workflow.xml
You MUST have already loaded and processed: {project-root}/bmad/bmb/workflows/audit-workflow/workflow.yaml
  
    What is the path to the workflow you want to audit? (provide path to workflow.yaml or workflow folder)
    Load the workflow.yaml file from the provided path
    Identify the workflow type (document, action, interactive, autonomous, meta)
    List all associated files:
    - instructions.md (required for most workflows)
    - template.md (if document workflow)
    - checklist.md (if validation exists)
    - Any data files referenced in yaml
    Load all discovered files
    Display summary:
    - Workflow name and description
    - Type of workflow
    - Files present
    - Module assignment
  
  
    Check workflow.yaml for the standard config block:
    **Required variables:**
    - `config_source: "{project-root}/bmad/[module]/config.yaml"`
    - `output_folder: "{config_source}:output_folder"`
    - `user_name: "{config_source}:user_name"`
    - `communication_language: "{config_source}:communication_language"`
    - `date: system-generated`
    Validate each variable:
    **Config Source Check:**
    - [ ] `config_source` is defined
    - [ ] Points to correct module config path
    - [ ] Uses {project-root} variable
    **Standard Variables Check:**
    - [ ] `output_folder` pulls from config_source
    - [ ] `user_name` pulls from config_source
    - [ ] `communication_language` pulls from config_source
    - [ ] `date` is set to system-generated
    Record any missing or incorrect config variables
    config_issues
    Add to issues list with severity: CRITICAL
  
  
    Extract all variables defined in workflow.yaml (excluding standard config block)
    Scan instructions.md for variable usage: {variable_name} pattern
    Scan template.md for variable usage: {{variable_name}} pattern (if exists)
    Cross-reference analysis:
    **For each yaml variable:**
    1. Is it used in instructions.md? (mark as INSTRUCTION_USED)
    2. Is it used in template.md? (mark as TEMPLATE_USED)
    3. Is it neither? (mark as UNUSED_BLOAT)
    **Special cases to ignore:**
    - Standard config variables (config_source, output_folder, user_name, communication_language, date)
    - Workflow metadata (name, description, author)
    - Path variables (installed_path, template, instructions, validation)
    - Web bundle configuration (web_bundle block itself)
    Identify unused yaml fields (bloat)
    Identify hardcoded values in instructions that should be variables
    alignment_issues
    Add to issues list with severity: BLOAT
  
  
    Analyze instructions.md for proper config variable usage:
    **Communication Language Check:**
    - Search for phrases like "communicate in {communication_language}"
    - Check if greetings/responses use language-aware patterns
    - Verify NO usage of {{communication_language}} in template headers
    **User Name Check:**
    - Look for user addressing patterns using {user_name}
    - Check if summaries or greetings personalize with {user_name}
    - Verify optional usage in template metadata (not required)
    **Output Folder Check:**
    - Search for file write operations
    - Verify all outputs go to {output_folder} or subdirectories
    - Check for hardcoded paths like "/output/" or "/generated/"
    **Date Usage Check:**
    - Verify date is available for agent date awareness
    - Check optional usage in template metadata
    - Ensure no confusion between date and model training cutoff
    **Nested Tag Reference Check:**
    - Search for XML tag references within tags (e.g., `Scan for  tags`)
    - Identify patterns like: ` tags`, ` calls`, `content` within content
    - Common problematic tags to check: action, ask, check, template-output, invoke-workflow, goto
    - Flag any instances where angle brackets appear in content describing tags
    **Best Practice:** Use descriptive text without brackets (e.g., "action tags" instead of " tags")
    **Rationale:**
    - Prevents XML parsing ambiguity
    - Improves readability for humans and LLMs
    - LLMs understand "action tags" = `` tags from context
    **Conditional Execution Antipattern Check:**
    - Scan for self-closing check tags: `condition text` (invalid antipattern)
    - Detect pattern: check tag on one line, followed by action/ask/goto tags (indicates incorrect nesting)
    - Flag sequences like: `If X:` followed by `do Y`
    **Correct Patterns:**
    - Single conditional: `Do something`
    - Multiple actions: `` followed by nested actions with closing `` tag
    **Antipattern Example (WRONG):**
    ```xml
    If condition met:
    Do something
    ```
    **Correct Example:**
    ```xml
    
      Do something
      Do something else
    
    ```
    **Or for single action:**
    ```xml
    Do something
    ```
    Scan instructions.md for nested tag references using pattern: <(action|ask|check|template-output|invoke-workflow|goto|step|elicit-required)> within text content
    Record any instances of nested tag references with line numbers
    Scan instructions.md for conditional execution antipattern: self-closing check tags
    Detect pattern: `<check>.*</check>` on single line (self-closing check)
    Record any antipattern instances with line numbers and suggest corrections
    Record any improper config variable usage
    config_usage_issues
    Add to issues list with severity: IMPORTANT
    Add to issues list with severity: CLARITY (recommend using descriptive text without angle brackets)
    Add to issues list with severity: CRITICAL (invalid XML structure - must use action if="" or proper check wrapper)
  
  
    
      Validate web_bundle structure:
      **Path Validation:**
      - [ ] All paths use bmad/-relative format (NOT {project-root})
      - [ ] No {config_source} variables in web_bundle section
      - [ ] Paths match actual file locations
      **Completeness Check:**
      - [ ] instructions file listed in web_bundle_files
      - [ ] template file listed (if document workflow)
      - [ ] validation/checklist file listed (if exists)
      - [ ] All data files referenced in yaml listed
      - [ ] All files referenced in instructions listed
      **Workflow Dependency Scan:**
      Scan instructions.md for invoke-workflow tags
      Extract workflow paths from invocations
      Verify each called workflow.yaml is in web_bundle_files
      **CRITICAL**: Check if existing_workflows field is present when workflows are invoked
      If invoke-workflow calls exist, existing_workflows MUST map workflow variables to paths
      Example: If instructions use {core_brainstorming}, web_bundle needs: existing_workflows: - core_brainstorming: "bmad/core/workflows/brainstorming/workflow.yaml"
      **File Reference Scan:**
      Scan instructions.md for file references in action tags
      Check for CSV, JSON, YAML, MD files referenced
      Verify all referenced files are in web_bundle_files
      Record any missing files or incorrect paths
      web_bundle_issues
      Add to issues list with severity: CRITICAL
      Note: "No web_bundle configured (may be intentional for local-only workflows)"
    
  
  
    Identify bloat patterns:
    **Unused YAML Fields:**
    - Variables defined but not used in instructions OR template
    - Duplicate fields between top-level and web_bundle section
    - Commented-out variables that should be removed
    **Hardcoded Values:**
    - File paths that should use {output_folder}
    - Generic greetings that should use {user_name}
    - Language-specific text that should use {communication_language}
    - Static dates that should use {date}
    **Redundant Configuration:**
    - Variables that duplicate web_bundle fields
    - Metadata repeated across sections
    Calculate bloat metrics:
    - Total yaml fields: {{total_yaml_fields}}
    - Used fields: {{used_fields}}
    - Unused fields: {{unused_fields}}
    - Bloat percentage: {{bloat_percentage}}%
    Record all bloat items with recommendations
    bloat_items
    Add to issues list with severity: CLEANUP
  
  
    Extract all template variables from template.md: {{variable_name}} pattern
    Scan instructions.md for corresponding template-output tags
    Cross-reference mapping:
    **For each template variable:**
    1. Is there a matching template-output tag? (mark as MAPPED)
    2. Is it a standard config variable? (mark as CONFIG_VAR - optional)
    3. Is it unmapped? (mark as MISSING_OUTPUT)
    **For each template-output tag:**
    1. Is there a matching template variable? (mark as USED)
    2. Is it orphaned? (mark as UNUSED_OUTPUT)
    Verify variable naming conventions:
    - [ ] All template variables use snake_case
    - [ ] Variable names are descriptive (not abbreviated)
    - [ ] Standard config variables properly formatted
    Record any mapping issues
    template_issues
    Add to issues list with severity: IMPORTANT
  
  
    Compile all findings and calculate summary metrics
    Generate executive summary based on issue counts and severity levels
    workflow_type
    overall_status
    critical_count
    important_count
    cleanup_count
    Generate status summaries for each audit section
    config_status
    total_variables
    instruction_usage_count
    template_usage_count
    bloat_count
    Generate config variable usage status indicators
    comm_lang_status
    user_name_status
    output_folder_status
    date_status
    nested_tag_count
    Generate web bundle metrics
    web_bundle_exists
    web_bundle_file_count
    missing_files_count
    Generate bloat metrics
    bloat_percentage
    cleanup_potential
    Generate template mapping metrics
    template_var_count
    mapped_count
    missing_mapping_count
    Compile prioritized recommendations by severity
    critical_recommendations
    important_recommendations
    cleanup_recommendations
    Display summary to {user_name} in {communication_language}
    Provide path to full audit report: {output_folder}/audit-report-{{workflow_name}}-{{date}}.md
    Would you like to:
    - View the full audit report
    - Fix issues automatically (invoke edit-workflow)
    - Audit another workflow
    - Exit