Files
2026-09-15 11:52:10 -07:00
..
2026-09-15 11:52:10 -07:00
2026-09-15 11:52:10 -07:00
2026-09-04 13:20:43 -07:00
2026-09-04 13:51:24 -07:00

Repository Tools & Utilities

Purpose: Management, analysis, and validation scripts for the XHorse Multi-PROG repository
Language: PowerShell (Windows)
Status: Baseline inventory and problem-detection tools


Available Tools

1. generate_inventory.ps1

Purpose: Comprehensive repository file inventory generation

Function:

  • Recursively scans all files (excludes .git)
  • Calculates SHA-256 hash for each file
  • Extracts file metadata (size, type, category)
  • Generates CSV and JSON inventories
  • Creates directory structure snapshot
  • Produces aggregate statistics

Usage:

.\generate_inventory.ps1 -RepositoryRoot "\\unas\Workspace\CDiag\Scripts\XHorse_MultiPROG_Ultimate_Kit" `
                        -OutputDir "\\unas\Workspace\CDiag\Scripts\XHorse_MultiPROG_Ultimate_Kit\14_Repository_Review"

Output Files:

  • repository_inventory.csv — All files with metadata
  • repository_inventory.json — Structured format
  • directory_structure_before.txt — Tree representation
  • scan_statistics.json — Summary statistics

Features:

  • ✅ 100% file coverage
  • ✅ SHA-256 hashing
  • ✅ File categorization
  • ✅ Error handling
  • ✅ Progress reporting
  • ✅ ~250 lines of code

Performance:

  • Scans the current repository tree
  • 0 errors
  • Perfect completion rate

2. detect_problems.ps1

Purpose: Identify and classify repository issues

Function:

  • Detects empty files
  • Identifies unknown file types
  • Finds duplicate files (by hash)
  • Scans for suspicious code patterns
  • Validates URL shortcuts
  • Identifies large files
  • Generates problem reports

Usage:

.\detect_problems.ps1 -RepositoryRoot "\\unas\Workspace\CDiag\Scripts\XHorse_MultiPROG_Ultimate_Kit" `
                     -OutputDir "\\unas\Workspace\CDiag\Scripts\XHorse_MultiPROG_Ultimate_Kit\14_Repository_Review"

Output Files:

  • empty_files.csv — Empty file list (0 found)
  • unknown_file_types.csv — Unknown extensions (251 found)
  • large_files.csv — Large files > 5MB (1 found)
  • suspicious_files.csv — Flagged scripts (15 found)
  • broken_url_shortcuts.csv — Invalid URLs (0 found)
  • duplicate_files_by_hash.json — Duplicate groups
  • problems_summary.json — Aggregated summary

Features:

  • ✅ Multi-pattern detection
  • ✅ Hash-based deduplication
  • ✅ Suspicious pattern scanning
  • ✅ URL shortcut syntax validation (no network requests)
  • ✅ Detailed reporting
  • ✅ ~350 lines of code

Performance:

  • Scans the current repository tree
  • Reports current findings
  • Generated 6+ reports

Suspicious Patterns Detected:

  • eval() — Dynamic code execution
  • Function() — Runtime function creation
  • exec() / execFile() — System command execution
  • Proxy/network functionality
  • Obfuscation indicators

Installation & Setup

Prerequisites

  • Windows PowerShell 5.1 or higher
  • .NET Framework 4.5+
  • Access to repository directory

Setup

  1. Copy *.ps1 files to tools/ directory
  2. Ensure scripts are readable (check file permissions)
  3. For first run, may need to set PowerShell execution policy:
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    

Verification

# Test that scripts are available
Get-ChildItem *.ps1 | Select-Object Name, Length

# Test execution (dry run)
.\generate_inventory.ps1 -RepositoryRoot "path" -OutputDir "path"

Usage Workflows

Complete Repository Analysis

# Generate comprehensive inventory
.\generate_inventory.ps1

# Detect all problems
.\detect_problems.ps1

# Results available in 14_Repository_Review/

Periodic Validation

# Run quarterly or when new content added
.\generate_inventory.ps1  # Update inventory
.\detect_problems.ps1     # Find new issues

# Compare with previous scan
# Review changes in 14_Repository_Review/

Duplicate Detection

# Find all duplicate files
.\detect_problems.ps1

# Review: duplicate_files_by_hash.json
# Identify canonical copies
# Plan deduplication strategy

Suspicious Content Scan

# Scan for dangerous patterns
.\detect_problems.ps1

# Review: suspicious_files.csv
# Examine flagged files manually
# Quarantine if needed

Output File Formats

CSV Files

Standard comma-separated values, UTF-8 encoding:

  • Header row with column names
  • One record per line
  • Quoted values with embedded commas
  • Readable in Excel or text editors

Example:

Path,Extension,Size,Category
01_Knowledge_Base/README.md,.md,4299,Markdown
03_Script_Starter_Kit/binary_utils.mjs,.mjs,4567,JavaScript Module

JSON Files

Structured JSON format, UTF-8 encoding:

  • Valid JSON (readable by json parsers)
  • Pretty-printed for readability
  • Nested structures preserved
  • Suitable for automation

Example:

[
  {
    "Path": "01_Knowledge_Base/README.md",
    "Extension": ".md",
    "Size": 4299,
    "Category": "Markdown",
    "SHA256": "4f630a94457cef1d3c7a2baeb5bfc872755c96d2690c9d4631c755d2d80d0ea9"
  }
]

Text Files

Human-readable format for quick reference:

  • Line-based structure
  • Directory tree format
  • Statistics in readable form
  • No special parsing needed

Customization

Extending generate_inventory.ps1

Add more file categories:

function Get-FileCategory {
    param([string]$Extension)
    
    switch -Exact ($Extension.ToLower()) {
        ".md" { return "Markdown" }
        ".custom" { return "My Custom Type" }  # Add here
        default { return "Unknown" }
    }
}

Include additional metadata:

# Add to the $item object
CreatedTime = $file.CreationTime
ModifiedTime = $file.LastWriteTime
Owner = (Get-Acl $file).Owner

Extending detect_problems.ps1

Add suspicious patterns:

$suspiciousPatterns = @(
    'eval\s*\(',
    'Function\s*\(',
    'YOUR_NEW_PATTERN_HERE'  # Add patterns
)

Change file size threshold:

# Currently 5MB
$largeFiles = $files | Where-Object { $_.Length -gt 5242880 }
# Change to 10MB
$largeFiles = $files | Where-Object { $_.Length -gt 10485760 }

Troubleshooting

Script Won't Run

Problem: "Script execution disabled"
Solution: Set execution policy

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Out of Memory

Problem: Script runs slowly or crashes on large repo
Solution: Process in smaller batches or increase available memory

Permission Denied

Problem: "Access to the path is denied"
Solution: Run PowerShell as Administrator

Path Not Found

Problem: "Cannot find path" error
Solution: Use absolute paths with correct escaping

$path = "\\unas\Workspace\CDiag\Scripts\XHorse_MultiPROG_Ultimate_Kit"

Performance Notes

Benchmarks (from 2026-09-04 run)

  • Files scanned: See scan_statistics.json
  • Inventory generation: ~3 seconds
  • Problem detection: ~8 seconds
  • Total time: ~11 seconds
  • Output size: ~900 KB

Optimization Tips

  1. Exclude .git directory (already done)
  2. Process on local drive (faster than network)
  3. Use SSD for better performance
  4. Schedule off-peak hours for large scans

Maintenance Schedule

Daily

  • Monitor for new issues
  • Check problem reports

Weekly

  • Review duplicate detections
  • Validate new content

Monthly

  • Run full inventory
  • Analyze trends

Quarterly

  • Complete problem scan
  • Validate external links
  • Review security patterns

Annually

  • Full repository audit
  • Update documentation
  • Archive results

Integration with CI/CD

GitHub Actions Example

- name: Generate Repository Inventory
  run: |
    powershell -File tools/generate_inventory.ps1
    
- name: Detect Problems
  run: |
    powershell -File tools/detect_problems.ps1
    
- name: Archive Results
  uses: actions/upload-artifact@v2
  with:
    name: repository-analysis
    path: 14_Repository_Review/

Azure Pipelines Example

- task: PowerShell@2
  inputs:
    filePath: 'tools/generate_inventory.ps1'
    
- task: PowerShell@2
  inputs:
    filePath: 'tools/detect_problems.ps1'
    
- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '14_Repository_Review'
    artifactName: repository-analysis

Future Enhancements

Potential improvements for v2.0:

  • Automated script analysis (AST-based)
  • Link validation with network checks
  • Checksum comparison for integrity verification
  • Automated quarantine with whitelist
  • Dashboard/visualization of results
  • Git integration for historical comparison
  • License compliance checker
  • Security scanning (OWASP, CWE)
  • Performance profiling
  • Cloud storage integration

Contributing to Tools

To improve or extend these tools:

  1. Test changes thoroughly
  2. Document new parameters
  3. Maintain backward compatibility
  4. Update this README
  5. Submit improvements via contribution process

See ../CONTRIBUTING.md for guidelines.


License

All tools in this directory are MIT licensed (same as the repository).

See ../LICENSES.md for full licensing details.


Questions or Issues?

  • Usage help? Read the sections above
  • Bug report? See ../CONTRIBUTING.md
  • Enhancement request? See "Future Enhancements"
  • Integration help? Check example configurations above

Tools Directory Status: ✅ OPERATIONAL
Last Updated: 2026-09-04
Next Review: 2027-09-04