--- description: Clean up and standardize generated files allowed-tools: Edit(40 - Generated/**), MultiEdit(40 - Generated/**), Write(40 - Generated/Analysis/cleanup-log.md), Bash --- You are performing maintenance and cleanup on the Universalis generated files to ensure consistency, remove orphaned content, and standardize formatting. ## Objectives: 1. **Remove orphaned files** with no valid references 2. **Standardize formatting** across all generated cards 3. **Fix broken internal references** and update links 4. **Consolidate duplicate content** where appropriate 5. **Ensure file organization** follows established conventions ## Cleanup Operations: ### 1. Orphaned File Detection Identify files to remove: - **Unreferenced cards**: Files with no incoming links from other cards or chapters - **Duplicate files**: Multiple files for the same entity (keep most complete) - **Invalid files**: Malformed or empty card files - **Outdated files**: Files for entities no longer in the story ### 2. Formatting Standardization Apply consistent formatting: - **YAML frontmatter**: Standardize field order, naming, and values - **Markdown headers**: Ensure consistent heading hierarchy (H1, H2, H3) - **Section structure**: Match established card templates - **Link formatting**: Standardize wiki-style link format - **Date formatting**: Ensure consistent date format in frontmatter ### 3. Reference Cleanup Fix broken connections: - **Dead links**: Remove links to non-existent files - **Incorrect references**: Fix links pointing to wrong files - **Missing backlinks**: Add missing reciprocal references - **Outdated aliases**: Update references using old entity names ### 4. Content Consolidation Merge related content: - **Duplicate entities**: Combine multiple cards for same character/location - **Alias resolution**: Merge cards that represent the same entity - **Related content**: Move misplaced content to correct files ### 5. File Organization Ensure proper structure: - **Directory placement**: Move files to correct category directories - **Filename conventions**: Standardize naming patterns - **Category consistency**: Ensure files match their directory category ## Cleanup Process: ### Phase 1: Analysis & Detection 1. **Inventory all files** in 40 - Generated/ 2. **Map all references** between files and from manuscript chapters 3. **Identify orphaned content** with no incoming references 4. **Detect formatting inconsistencies** against templates 5. **Find duplicate entities** across different files ### Phase 2: Automated Cleanup 1. **Standardize frontmatter** fields and formatting 2. **Fix link syntax** and formatting issues 3. **Update date formats** to consistent pattern 4. **Normalize section headers** to match templates 5. **Apply consistent indentation** and spacing ### Phase 3: Content Consolidation 1. **Merge duplicate files** (keep most complete version) 2. **Resolve alias conflicts** by consolidating references 3. **Move misplaced content** to appropriate files 4. **Update all references** to consolidated files ### Phase 4: File Organization 1. **Move files** to correct directories if needed 2. **Rename files** to follow naming conventions 3. **Update references** to reflect any file moves/renames 4. **Remove empty directories** ### Phase 5: Validation 1. **Verify all links** work correctly 2. **Check frontmatter** completeness and validity 3. **Confirm file organization** follows conventions 4. **Test cross-references** between all files ## Cleanup Log: Generate detailed log at `40 - Generated/Analysis/cleanup-log.md`: ```markdown # Generated Files Cleanup Log *Cleanup performed: {{current_date}}* ## Cleanup Summary - **Files Processed**: {{total_files_processed}} - **Files Removed**: {{files_removed}} (orphaned/duplicate) - **Files Modified**: {{files_modified}} (formatting/content) - **Files Moved**: {{files_moved}} (reorganization) - **Links Fixed**: {{links_fixed}} - **References Updated**: {{references_updated}} ## Orphaned Files Removed ### No Incoming References {{list_orphaned_files_removed_with_reason}} ### Duplicate Content {{list_duplicate_files_consolidated}} ### Invalid Files {{list_malformed_files_removed}} ## Formatting Standardization ### YAML Frontmatter Fixes {{list_frontmatter_standardization_changes}} ### Markdown Structure Fixes {{list_structure_standardization_changes}} ### Link Format Corrections {{list_link_formatting_fixes}} ## Content Consolidation ### Entity Merges {{list_entity_consolidations_performed}} ### Alias Resolutions {{list_alias_consolidations}} ### Content Relocations {{list_content_moved_between_files}} ## File Organization ### Directory Reorganization {{list_files_moved_between_directories}} ### Filename Standardization {{list_filename_changes}} ### Category Corrections {{list_category_corrections}} ## Reference Updates ### Broken Links Fixed {{list_broken_links_repaired}} ### Dead References Removed {{list_dead_references_removed}} ### Missing Backlinks Added {{list_backlinks_added}} ## Quality Improvements ### Completeness Enhancements {{list_incomplete_sections_improved}} ### Consistency Fixes {{list_consistency_improvements}} ### Format Standardization {{list_format_improvements}} ## Files Requiring Manual Review ### Complex Duplicates {{list_files_needing_manual_merge_review}} ### Ambiguous References {{list_references_needing_clarification}} ### Content Questions {{list_content_requiring_author_decision}} ## Post-Cleanup Statistics ### File Counts by Category - **Characters**: {{character_file_count}} - **Locations**: {{location_file_count}} - **Ships**: {{ship_file_count}} - **Technology**: {{tech_file_count}} - **Species**: {{species_file_count}} - **Plotlines**: {{plotline_file_count}} - **Events**: {{event_file_count}} - **Conflicts**: {{conflict_file_count}} - **Themes**: {{theme_file_count}} ### Link Health - **Total Links**: {{total_link_count}} - **Valid Links**: {{valid_link_count}} - **Broken Links**: {{broken_link_count}} - **Cross-References**: {{cross_reference_count}} ### Quality Metrics - **Complete Cards**: {{complete_cards_count}} - **Standardized Format**: {{standardized_format_count}} - **Orphaned Files**: {{remaining_orphaned_count}} ## Recommendations ### Immediate Actions {{list_urgent_cleanup_items_remaining}} ### Future Maintenance {{list_ongoing_maintenance_recommendations}} ### Prevention Strategies {{list_strategies_to_prevent_future_issues}} ## Cleanup Methodology ### Detection Criteria {{criteria_used_for_identifying_cleanup_needs}} ### Automated vs Manual {{description_of_automated_vs_manual_cleanup_steps}} ### Validation Process {{process_for_verifying_cleanup_quality}} --- Generated by Claude Code cleanup system for Universalis writing project. ``` ## Cleanup Methodology: 1. **Comprehensive file scanning** for all generated content 2. **Reference mapping** to identify connections and orphans 3. **Pattern matching** for formatting inconsistencies 4. **Automated standardization** where safe to do so 5. **Manual review flagging** for complex cases 6. **Validation testing** after cleanup operations 7. **Documentation** of all changes made ## Safety Measures: ### Backup and Recovery - Create list of all changes for potential rollback - Preserve original content when merging duplicates - Flag complex cases for manual review - Validate all automated changes ### Content Preservation - Never delete content without clear justification - Merge rather than delete when combining duplicates - Preserve aliases and alternative names - Maintain all legitimate cross-references ## Cleanup Standards: ### File Naming Conventions - Consistent capitalization and spacing - Standard character replacements for special characters - Category-appropriate prefixes if needed - Meaningful, searchable filenames ### Content Standards - Complete frontmatter with all required fields - Consistent section structure per card type - Proper wiki-style linking format - Appropriate content categorization ## Output Requirements: - Fixed filename: `40 - Generated/Analysis/cleanup-log.md` - Detailed logging of all changes made - Statistics on files processed and improvements made - Recommendations for future maintenance - Flagged items requiring manual review **IMPORTANT**: Prioritize content preservation over aggressive cleanup. When in doubt about removing or merging content, flag for manual review rather than auto-delete. Always validate that cleanup operations improve rather than break the generated file system.