T02 · Agent Memory Poisoning
- Location
scripts/memos_dreaming.py:304- Finding
Untrusted content can be promoted into persistent agent memory
- Content
View full analysis
list[dict]: """Scan recent daily memory logs for high-value entries.""" candidates = [] today = datetime.now() cutoff = today - timedelta(days=7) for log_file in sorted(MEMORY_DIR.glob("2026-*.md")): try: log_date = datetime.strptime(log_file.stem[:10], "%Y-%m-%d") if log_date < cutoff: continue except ValueError: continue content = log_file.read_text() ``` ```python def format_memory_promotion(c: dict) -> str: """Format entry for MEMORY.md.""" ts = ts_to_date(c.get("updated_at", get_now_ts())) if c["type"] == "skill": return ( f"\n- **{c['title']}** (skill, {ts})\n" f" {c.get('summary', '')[:200]}" ) elif c["type"] == "task": return ( f"\n- **{c['title']}** (task, {ts})\n" f" {c.get('summary', '')[:200]}" ) else: return f"\n- {c.get('summary', c.get('title', ''))} (daily log, {ts})" ``` ```python if apply: # Append to MEMORY.md ensure_dir(MEMORY_FILE) existing = MEMORY_FILE.read_text() if MEMORY_FILE.exists() else "" # Find last section if "## Promoted" in existing: insert_pos = existing.rfind("## Promoted") elif "## Lessons Learned" in existing: insert_pos = existing.rfind("## Lessons Learned") else: insert_pos = len(existing) new_entries = [] for c in to_promote: new_entries.append(format_memory_promotion(c)) append_promoted(c["entry_hash"], c.get("title", ""), c["type"]) promoted_block = ( f"\n\n## Promoted ...[truncated 2774 chars]- Remediation
View remediation
