[MEM] Implement Pre-compaction Flush Contract #301
40
tasks.py
40
tasks.py
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user