# Work Directory Index Generator

## Purpose

Generate an index of current reports in the `.bmad-workspace/ck-jira-integration/` directory for easy discovery and navigation of temporal reports.

## Index Generation Commands

### Generate Simple Index

```bash
# List all reports with timestamps
find .bmad-workspace/ck-jira-integration -name "*.md" -type f -printf "%TY-%Tm-%Td %TH:%TM %p\n" | sort -r > .bmad-workspace/ck-jira-integration/INDEX.md
```

### Generate Categorized Index

```bash
# Create detailed index by category
cat > .bmad-workspace/ck-jira-integration/INDEX.md << 'EOF'
# Work Directory Index
Generated: $(date)

## Report Categories
EOF

# Add each category
for dir in .bmad-workspace/ck-jira-integration/*/; do
  if [ -d "$dir" ]; then
    echo -e "\n### $(basename "$dir")" >> .bmad-workspace/ck-jira-integration/INDEX.md
    find "$dir" -name "*.md" -type f -printf "- %TY-%Tm-%Td %TH:%TM - [%f](%p)\n" | sort -r >> .bmad-workspace/ck-jira-integration/INDEX.md
  fi
done
```

### Generate HTML Index

```bash
# Create browsable HTML index
cat > .bmad-workspace/ck-jira-integration/index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
    <title>Work Reports Index</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        h2 { color: #333; }
        .category { margin: 20px 0; }
        .report { margin: 5px 0; }
        .date { color: #666; }
    </style>
</head>
<body>
    <h1>Work Reports Index</h1>
    <p>Generated: <span id="date"></span></p>
EOF

echo "<script>document.getElementById('date').textContent = new Date().toLocaleString();</script>" >> .bmad-workspace/ck-jira-integration/index.html

for dir in .bmad-workspace/ck-jira-integration/*/; do
  if [ -d "$dir" ] && [ "$dir" != ".bmad-workspace/ck-jira-integration/" ]; then
    echo "<div class='category'><h2>$(basename "$dir")</h2>" >> .bmad-workspace/ck-jira-integration/index.html
    find "$dir" -name "*.md" -type f -printf "<div class='report'><span class='date'>%TY-%Tm-%Td %TH:%TM</span> - <a href='%p'>%f</a></div>\n" | sort -r >> .bmad-workspace/ck-jira-integration/index.html
    echo "</div>" >> .bmad-workspace/ck-jira-integration/index.html
  fi
done

echo "</body></html>" >> .bmad-workspace/ck-jira-integration/index.html
```

## Advanced Index Features

### Index with Summary Stats

```bash
#!/bin/bash
# Generate index with statistics

cat > .bmad-workspace/ck-jira-integration/INDEX.md << EOF
# Work Directory Index
Generated: $(date)

## Summary Statistics
- Total Reports: $(find .bmad-workspace/ck-jira-integration -name "*.md" -type f | wc -l)
- Total Size: $(du -sh .bmad-workspace/ck-jira-integration | cut -f1)
- Oldest Report: $(find .bmad-workspace/ck-jira-integration -name "*.md" -type f -printf '%T+ %p\n' | sort | head -1)
- Newest Report: $(find .bmad-workspace/ck-jira-integration -name "*.md" -type f -printf '%T+ %p\n' | sort -r | head -1)

## Reports by Category
EOF

# Category statistics
for dir in .bmad-workspace/ck-jira-integration/*/; do
  if [ -d "$dir" ]; then
    category=$(basename "$dir")
    count=$(find "$dir" -name "*.md" -type f | wc -l)
    size=$(du -sh "$dir" | cut -f1)
    echo "- **$category**: $count reports ($size)" >> .bmad-workspace/ck-jira-integration/INDEX.md
  fi
done

echo -e "\n## Recent Reports (Last 7 Days)" >> .bmad-workspace/ck-jira-integration/INDEX.md
find .bmad-workspace/ck-jira-integration -name "*.md" -type f -mtime -7 -printf "- %TY-%Tm-%Td %TH:%TM - [%p](%p)\n" | sort -r >> .bmad-workspace/ck-jira-integration/INDEX.md

echo -e "\n## All Reports by Date" >> .bmad-workspace/ck-jira-integration/INDEX.md
# ... rest of categorized listing
```

### Search Function

```bash
# Create searchable index function
work_search() {
  local pattern="$1"
  echo "Searching for: $pattern"
  echo "===================="
  find .bmad-workspace/ck-jira-integration -name "*.md" -type f -exec grep -l "$pattern" {} \; | while read file; do
    echo -e "\n📄 $file"
    grep -n "$pattern" "$file" | head -3
  done
}

# Usage
work_search "Sprint-15"
work_search "blocked"
```

## Integration with JIRA Agent

```markdown
[[LLM: Generate work index task

1. Use Bash tool to scan .bmad-workspace/ck-jira-integration/ directory
2. Count reports by category
3. Calculate storage usage
4. Find recent reports (last 7 days)
5. Generate formatted index
6. Optional: Create HTML version for browser viewing
   ]]

# Work Directory Report Index

**Generated**: {{current timestamp via MCP time tool}}

## 📊 Summary

- **Total Reports**: {{count}}
- **Storage Used**: {{size}}
- **Date Range**: {{oldest}} to {{newest}}

## 📁 Categories

### Daily Sync Reports ({{sync_count}})

Latest reports for three-way synchronization analysis

### Sprint Reports ({{sprint_count}})

Sprint health, velocity, and progress tracking

### Standup Records ({{standup_count}})

Daily standup agendas and meeting notes

### Analysis Reports ({{analysis_count}})

Variance analysis and reconciliation reports

## 🔥 Recent Activity (Last 7 Days)

{{list of recent reports with links}}

## 🔍 Quick Links

- [Latest Sprint Health Report]({{latest_sprint_health}})
- [Today's Sync Status]({{today_sync}})
- [Current Week Performance]({{week_performance}})
```

## Automation Script

Create `.bmad-workspace/ck-jira-integration/generate-index.sh`:

```bash
#!/bin/bash
# Automated index generation

WORK_DIR=".bmad-workspace/ck-jira-integration"
INDEX_FILE="$WORK_DIR/INDEX.md"

# Function to generate index
generate_index() {
  echo "# Work Directory Index" > "$INDEX_FILE"
  echo "Generated: $(date)" >> "$INDEX_FILE"
  echo "" >> "$INDEX_FILE"

  # Add your index generation logic here
  # ...

  echo "Index generated: $INDEX_FILE"
}

# Run if called directly
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
  generate_index
fi
```

## Best Practices

1. **Regular Updates**: Regenerate index daily or after major report generation
2. **Include Metadata**: Show file sizes, dates, and counts
3. **Searchable Format**: Use consistent naming for easy grep/search
4. **Quick Access**: Link to most commonly needed reports
5. **Clean Layout**: Organize by category and date for easy scanning
