Memory flush

From aaronjmars/miroshark-aeon · View interactive version

Memory flush is an AI agent skill from the GitHub repository aaronjmars/miroshark-aeon. Promote important recent log entries into MEMORY.md and prune stale ones

How to use this skill

Skill file

${var} - Topic to focus on. If empty, flushes all recent activity.

If ${var} is set, only promote entries related to that topic. Pruning (step 3), the index upkeep (step 6), and the deterministic watermark + rotation (steps 0 and 8) still run globally - a focused flush must never leave the rest of the store stale.

Read memory/MEMORY.md for current memory state. The scan window and log rotation are computed for you in step 0 - you no longer parse the watermark or rotate logs by hand.

Steps

0. Prepare (deterministic bookkeeping - run this first)

Run python3 scripts/memory_prep.py window and read its stdout. It:

Read exactly the files it lists. Do not recompute the window or rotate logs yourself - that work is now deterministic and unit-tested (scripts/memory_prep.py), so it never silently falls back to 3 days or gets skipped. This closed two old holes: entries older than 3 days were lost whenever the agent skipped runs, and a daily schedule re-scanned the same 3 days every time.

1. Scan the in-window logs for entries worth promoting to long-term memory

2. Check each candidate against existing MEMORY.md content - dedup precisely

Skip if already recorded. Dedup by the fact's subject, not by string match:

3. Remove stale entries - this is as important as adding new ones

a. Open Improvement PRs section: Run gh pr list --state open --search "improve:" --json number,title,url and compare against any "Open Improvement PRs" section in MEMORY.md.

b. Next Priorities section: Cross-check each listed priority against recent logs and current repo state. Remove priorities that are already done (e.g., "Merge open PRs" if 0 open PRs exist). Add any newly urgent priorities surfaced by recent logs.

c. Lessons Learned: Remove lessons that are now outdated or resolved (e.g., a workaround for a bug that was later fixed).

d. Overflow any section that outgrows its budget (keeps MEMORY.md an index, not a ledger): if a section has grown past the last ~10-15 rows - the Skills Built table is the usual first offender, but the rule is general - archive the oldest rows to memory/topics/<section>-history.md (e.g. skills-history.md) and leave a one-line pointer to that file. Trim newest-kept, oldest-archived.

e. Hold the byte budget (MEMORY.md loads into every skill run, so size is cost): step 0 prints MEMORY.md size against the budget of 8 KB, ~50 lines, no line over 300 chars, and lists the over-long lines by number. When it says OVER BUDGET or names long lines, cut those first: move the detail of a long bullet to its topic file (memory/topics/lessons.md for Lessons Learned, memory/topics/priorities.md for Next Priorities, or the matching topic) and keep a one-line summary with a pointer in MEMORY.md. Keep the [source: ...] tag with the detail you move. A flush that leaves MEMORY.md over budget must say so in its log entry.

4. Update memory

5. Make targeted edits only

Do NOT rewrite the whole file - make targeted additions and removals.

6. Register any new topic files in the index

If step 4 created a new memory/topics/<topic>.md (or a *-history.md archive in step 3d), add a one-line pointer to it under the # Reference section of memory/topics/index.md, matching the existing row format. New topic notes that aren't linked from the index become orphans no other run can find.

7. (Automated) Log rotation

Log rotation now runs deterministically in step 0 (memory_prep.py window): whole calendar months entirely older than the 14-day scan floor are appended to memory/logs/archive/YYYY-MM.md and git rm'd once memory/logs/ passes ~45 files. The archive preserves every line, respecting the append-only contract while bounding the file count. Nothing to do here by hand; a log inside the scan window is never touched.

8. Log the run, then stamp the watermark

Log what you promoted, pruned, and archived, plus the scan window you used (start date to today; note if a >14-day gap was clamped), to memory/logs/${today}.md as bullets under a ### memory-flush heading (the health loop keys entries by slug).

Then run python3 scripts/memory_prep.py stamp as your final action - it writes today's date to memory/memory-flush-state.json and mirrors it into the MEMORY.md *Last consolidated:* line.

If nothing was worth promoting or removing, log MEMORY_FLUSH_OK - but still run memory_prep.py stamp: a clean flush is still a consolidation and must advance the watermark.

Network note

gh pr list uses the gh CLI's built-in auth - no curl env-var expansion. python3 scripts/memory_prep.py and all other work is local file I/O against memory/ (plus git rm for log rotation).

Constraints

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.