thefoldwithin-earth/.github/scripts/generate-daily-report.py
Solaria Lumis Havens d0cf2e3061
Some checks are pending
Auto Changelog / changelog (push) Waiting to run
Coherence Check / coherence-check (push) Waiting to run
Coherence Check / coherence (push) Waiting to run
Security Scan / security (push) Waiting to run
Semantic Versioning / version (push) Waiting to run
refactor: Replace generator with enhanced version
- Extracts full frontmatter metadata (originalDate, notion_*, authors, source)
- Correct date priority: frontmatter → filename → mtime → ctime
- All metadata exposed in index.json for frontend use

Phase 1 quick win complete.
2026-02-14 14:45:51 +00:00

154 lines
4.8 KiB
Python

#!/usr/bin/env python3
"""
Generate Daily Report Script
Creates a markdown report and JSON summary for daily coherence reporting.
"""
import json
import os
from datetime import datetime, timedelta
def load_coherence_report():
"""Load the latest coherence report."""
report_path = "coherence-report.json"
if not os.path.exists(report_path):
return None
with open(report_path) as f:
return json.load(f)
def generate_markdown_report(report):
"""Generate markdown report for GitHub Discussion."""
if not report:
return "# Daily Coherence Report\n\nNo coherence report available."
summary = report.get("summary", {})
issues_by_type = report.get("issues_by_type", {})
timestamp = report.get("timestamp", datetime.now().isoformat())
score = report.get("coherence_score", 0)
status = report.get("status", "unknown")
# Determine health emoji
if status == "healthy":
health_emoji = ""
elif status == "warning":
health_emoji = "⚠️"
else:
health_emoji = "🚨"
lines = [
f"# Daily Coherence Report",
f"**Date:** {datetime.fromisoformat(timestamp).strftime('%Y-%m-%d')}",
f"**Health:** {health_emoji} {status.upper()}",
f"**Coherence Score:** {score}/100",
"",
"## Summary",
"",
f"- **Files Validated:** {summary.get('total_files_validated', 0)}",
f"- **Total Issues:** {summary.get('total_issues', 0)}",
"",
"### Issue Breakdown",
"",
f"- 🔴 Critical: {summary.get('critical_issues', 0)}",
f"- 🟠 High: {summary.get('high_issues', 0)}",
f"- 🟡 Medium: {summary.get('medium_issues', 0)}",
f"- 🟢 Low: {summary.get('low_issues', 0)}",
"",
]
# Issues by type
if issues_by_type:
lines.extend([
"### Issues by Type",
"",
])
for issue_type, count in sorted(issues_by_type.items(), key=lambda x: -x[1]):
lines.append(f"- `{issue_type}`: {count}")
lines.append("")
# Auto-fixable issues
auto_fixable = report.get("auto_fixable", [])
if auto_fixable:
lines.extend([
"### Auto-Fixable Issues",
"",
f"The following {len(auto_fixable)} issues can be fixed automatically:",
"",
])
for issue in auto_fixable[:5]: # Limit to 5 examples
lines.append(f"- `{issue.get('file', 'unknown')}`: {issue.get('type', 'unknown')}")
lines.append("")
# Recent changes
lines.extend([
"## Actions Taken",
"",
"- Index regenerated",
"- Metadata validated",
"- Links checked",
"",
"---",
f"*Generated by Coherence Loop at {timestamp}*",
])
return "\n".join(lines)
def generate_json_summary(report):
"""Generate JSON summary for project board updates."""
if not report:
return {"status": "no_data", "date": datetime.now().isoformat()}
summary = report.get("summary", {})
return {
"date": report.get("timestamp", datetime.now().isoformat()),
"status": report.get("status", "unknown"),
"coherence_score": report.get("coherence_score", 0),
"metrics": {
"files_validated": summary.get("total_files_validated", 0),
"total_issues": summary.get("total_issues", 0),
"critical": summary.get("critical_issues", 0),
"high": summary.get("high_issues", 0),
"medium": summary.get("medium_issues", 0),
"low": summary.get("low_issues", 0),
},
"issues_by_type": report.get("issues_by_type", {}),
"new_issues": [
{"title": f"[{i.get('severity', 'medium').upper()}] {i.get('type', 'unknown')}: {i.get('file', 'unknown')}",
"body": i.get("message", ""),
"severity": i.get("severity", "medium"),
"type": i.get("type", "unknown")}
for i in report.get("issues", [])[:10] # Limit to 10 new issues
],
}
def main():
report = load_coherence_report()
# Generate markdown report
md_report = generate_markdown_report(report)
with open("daily-report.md", "w") as f:
f.write(md_report)
print("✅ Daily report saved to: daily-report.md")
# Generate JSON summary
json_summary = generate_json_summary(report)
with open("daily-report.json", "w") as f:
json.dump(json_summary, f, indent=2)
print("✅ JSON summary saved to: daily-report.json")
# Print summary
print(f"\n📊 Report Summary:")
print(f" Status: {json_summary.get('status', 'N/A')}")
print(f" Score: {json_summary.get('coherence_score', 0)}/100")
print(f" Issues: {json_summary.get('metrics', {}).get('total_issues', 0)}")
if __name__ == "__main__":
main()