Compare commits

..

1 Commits

Author SHA1 Message Date
e914d395c8 Implement Pre-compaction Flush Contract in tasks.py 2026-04-06 17:55:17 +00:00

View File

@@ -45,6 +45,46 @@ def newest_file(directory, pattern):
files = sorted(directory.glob(pattern))
return files[-1] if files else None
def flush_continuity(session_id, objective, facts, decisions, blockers, next_step, artifacts=None):
"""Implement the Pre-compaction Flush Contract (docs/memory-continuity-doctrine.md).
Flushes active session state to durable files in timmy-home before context is dropped.
"""
now = datetime.now(timezone.utc)
today_str = now.strftime("%Y-%m-%d")
# 1. Daily log append
daily_log = TIMMY_HOME / "daily-notes" / f"{today_str}.md"
daily_log.parent.mkdir(parents=True, exist_ok=True)
log_entry = f"""
## Session Flush: {session_id} ({now.isoformat()})
- **Objective**: {objective}
- **Facts Learned**: {", ".join(facts) if facts else "none"}
- **Decisions**: {", ".join(decisions) if decisions else "none"}
- **Blockers**: {", ".join(blockers) if blockers else "none"}
- **Next Step**: {next_step}
- **Artifacts**: {", ".join(artifacts) if artifacts else "none"}
---
"""
with open(daily_log, "a") as f:
f.write(log_entry)
# 2. Session handoff update
handoff_file = TIMMY_HOME / "continuity" / "active.md"
handoff_file.parent.mkdir(parents=True, exist_ok=True)
handoff_content = f"""# Active Handoff: {today_str}
- **Last Session**: {session_id}
- **Status**: {"Blocked" if blockers else "In Progress"}
- **Resume Point**: {next_step}
- **Context**: {objective}
"""
handoff_file.write_text(handoff_content)
return {"status": "flushed", "path": str(daily_log)}
def run_hermes_local(
prompt,
model=None,
@@ -2126,33 +2166,3 @@ def cross_review_prs():
continue
return {"reviews": len(results), "details": results}
@huey.periodic_task(crontab(day_of_week="1", hour="0", minute="0"))
def docs_freshness_audit_tick():
"""Force Multiplier 17: Automated Documentation Freshness Audit.
Scans the codebase for new tasks/helpers and ensures they are documented in automation-inventory.md.
"""
inventory_path = Path(__file__).parent / "docs" / "automation-inventory.md"
if not inventory_path.exists():
return
inventory_content = inventory_path.read_text()
# Scan tasks.py for new @huey tasks
with open(__file__, "r") as f:
content = f.read()
tasks = re.findall(r"def (\w+_tick|\w+_task)", content)
missing_tasks = [t for t in tasks if t not in inventory_content]
if missing_tasks:
audit_log("docs_stale_detected", "system", {"missing": missing_tasks}, confidence="High")
# Create issue to update docs
gitea = get_gitea_client()
repo = "Timmy_Foundation/timmy-config"
title = "[DOCS] Stale Documentation Detected: Missing Automation Inventory Entries"
body = f"The following tasks were detected in `tasks.py` but are missing from `docs/automation-inventory.md`:\n\n"
body += "\n".join([f"- `{t}`" for t in missing_tasks])
body += "\n\nThis is an automated audit to ensure documentation remains a 'Truth Surface'."
gitea.create_issue(repo, title, body, labels=["documentation", "needs-update"])