# Work Directory Cleanup Utility

## Purpose

Clean up old temporal reports from the `.bmad-workspace/ck-jira-integration/` directory to prevent disk space issues while preserving recent reports that may still be needed.

## Usage

### Automatic Cleanup (Recommended)

Configure your system to run cleanup daily or weekly:

```bash
# Add to crontab or scheduled tasks
0 2 * * * cd /path/to/project && find .bmad-workspace/ck-jira-integration -name "*.md" -mtime +30 -delete
```

### Manual Cleanup Commands

#### Remove reports older than 30 days

```bash
find .bmad-workspace/ck-jira-integration -name "*.md" -mtime +30 -delete
```

#### Remove reports older than 7 days (aggressive)

```bash
find .bmad-workspace/ck-jira-integration -name "*.md" -mtime +7 -delete
```

#### Clean specific report types

```bash
# Remove old standup reports
find .bmad-workspace/ck-jira-integration/standups -name "*.md" -mtime +14 -delete

# Remove old sync reports
find .bmad-workspace/ck-jira-integration/sync -name "*.md" -mtime +30 -delete

# Remove old dashboards (regenerate on demand)
rm -rf .bmad-workspace/ck-jira-integration/dashboards/*
```

#### Archive before cleanup

```bash
# Create archive of reports before deletion
tar -czf work-archive-$(date +%Y%m%d).tar.gz .bmad-workspace/ck-jira-integration/
find .bmad-workspace/ck-jira-integration -name "*.md" -mtime +30 -delete
```

## Safety Checks

### Preview what will be deleted

```bash
# Dry run - show files that would be deleted
find .bmad-workspace/ck-jira-integration -name "*.md" -mtime +30 -print
```

### Check disk usage

```bash
# Check .bmad-workspace/ck-jira-integration directory size
du -sh .bmad-workspace/ck-jira-integration/

# Check by subdirectory
du -sh .bmad-workspace/ck-jira-integration/*/
```

## Integration with BMAD Agents

When implementing in an agent task:

```markdown
[[LLM: Cleanup old .work reports

1. Use Bash tool to check .bmad-workspace/ck-jira-integration/ directory size
2. If size > 100MB, suggest cleanup
3. Archive important reports if requested
4. Remove files older than retention period
5. Report cleanup summary
   ]]

## Cleanup Summary

**Pre-cleanup size**: {{size before}}
**Post-cleanup size**: {{size after}}
**Files removed**: {{count}}
**Space reclaimed**: {{MB reclaimed}}
```

## Best Practices

1. **Regular Schedule**: Run cleanup weekly or monthly
2. **Archive First**: Always archive before bulk deletion
3. **Retention Policy**: Keep 30 days minimum for audit trails
4. **Monitor Growth**: Check directory size regularly
5. **Selective Cleanup**: Some reports (audits) may need longer retention

## Configuration

Create `.bmad-workspace/ck-jira-integration/.cleanup-config` for custom settings:

```yaml
retention:
  default: 30 # days
  standups: 14
  dashboards: 7
  audits: 90

archive:
  enabled: true
  location: ./archives/work/

size_limit: 1024 # MB
```
