Logo vun Memory Gc

Memory Gc

Communautéit
exiao
memory-gc

Daily memory garbage collection for MEMORY.md / USER.md. Apply decay rules, drain .pending.md, consolidate near-duplicates, maintain canonical theme tags, prune old episode and session files. Invoke when asked to "run memory GC", "clean up memory", "apply memory decay", or from the scheduled cron job.

Iwwersiicht

Editeurexiao
Repositoryskills
Skill-Nummmemory-gc
Stären
40
Forks
12
Matgeliwwert Fichieren
Nëmmen Instruktiounen
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Vum exiao op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Memory Gc an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/exiao/skills/tree/main/memory/memory-gc
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/exiao/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/memory/memory-gc .claude/skills/memory-gc
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Memory Gc an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Memory Gc automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Memory Gc net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

memory-gc

Daily garbage collection pass for the Hermes memory system. Read this whole skill before taking any action. Execute steps in order. Use the memory tool for MEMORY.md / USER.md mutations; use the terminal for filesystem pruning.

Inputs you already have

  • MEMORY.md and USER.md are already in your system prompt (the snapshot shown at the top of this session). Read them there. Each entry looks like:
    [YYYY-MM-DD][cat] content

Tool availability

The memory tool (MemoryStore) may not be available in all environments (e.g., cron jobs). If it returns "Memory is not available", fall back to direct file editing via FilePatch on ~/.hermes/memories/MEMORY.md. When using FilePatch:

  • Remove entries by replacing the entry text AND its trailing § separator line together in one replacement (match <entry text>\n§ → empty string). This avoids orphaned separators.
  • If the entry is the LAST in the file (no trailing §), remove just the entry text and the preceding \n§\n from the entry above it.
  • Clean up resulting blank lines with sed -i '' '/^$/d' afterward.
  • The same safety rails apply: never touch [rule] or [meta] entries (except the step-8 protected-floor guard, which may losslessly shorten them, never remove).

Pitfall — multibyte characters: MEMORY.md may contain unicode (arrows, special chars in old entries). Use Python for age computation rather than awk, which chokes on multibyte sequences in some locales.

Pitfall — FilePatch § uniqueness: The § separator appears on every entry boundary. old_string containing just <text>\n§ will often match multiple locations. Always include enough surrounding context (adjacent entry text on both sides) to make the match unique. Alternatively, batch multiple adjacent removals into a single FilePatch that replaces the whole multi-entry block at once — this is more reliable than individual removals.

Pitfall — pending drain in cron: The memory tool (MemoryStore) is typically unavailable in cron. Pending entries accumulate across cron GC runs. Do NOT clear .pending.md unless entries were actually drained successfully. They will drain during the next interactive session.

Decay rules (from the [meta] Memory format entry)

cataction
fact, prefreview at 60d: still true? keep or remove
envreview at 30d: still accurate? keep or remove
proj:<path>review at 21d; remove if path no longer exists
rel:<name>review at 90d; remove if name unmentioned lately
taskreview at 14d; remove if completed or abandoned
tmphard remove at 7d — no review
rule, metanever decay

"Review" = a judgment call by you. Err on the side of keeping. When removing, log the removal in the final report.

Procedure

1. Compute ages

For each entry in MEMORY.md and USER.md, parse the leading [YYYY-MM-DD] and compute the age in days relative to today. Skip any entry without a parseable date — report it as unparseable.

2. Apply hard drops (no review, no judgment)

  • [tmp] entries older than 7 days → memory tool, action: remove, old_text = shortest unique substring.
  • [proj:<path>] entries where the path does not exist on disk → remove.

3. Apply review rules

For each entry past its review threshold (from the table above):

  • If it's still plausibly accurate / still used → keep.
  • If it is obviously stale (refers to resolved tmp state, abandoned project, superseded decision) → remove.

Do not remove anything you are not confident is stale. "Unsure" = keep.

4. Drain .pending.md

bash
test -s ~/.hermes/episodes/.pending.md && cat ~/.hermes/episodes/.pending.md

Each non-empty line is TARGET\tLINE. For each line:

  • Try to add via memory tool (target = first field, content = second field).
  • If it still fails for capacity, either (a) consolidate with an existing similar entry via replace, or (b) skip and report.

Once ALL entries are processed successfully, clear the file:

bash
: > ~/.hermes/episodes/.pending.md

If memory tool is unavailable (cron), skip this step entirely. Do not clear the file. Pending entries will accumulate and drain during the next interactive session where the memory tool works.

5. Consolidate near-duplicates

Scan MEMORY.md and USER.md for entries that say essentially the same thing (different dates or phrasing). Merge into one entry using memory tool action: replace. Keep the earliest creation date.

6. Maintain canonical themes

Collect every tag used in episode files:

bash
grep -h "^tags:" ~/.hermes/episodes/*.md 2>/dev/null \
  | sed 's/^tags:[[:space:]]*//' | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
  | sort | uniq -c | sort -rn

Read the current canonical list from MEMORY.md (the [meta] Episode tags (canonical) entry).

  • Any tag used in ≥3 episodes but missing from the canonical list → memory replace to add it to the [meta] entry.
  • Near-duplicate tags in use (debug/debugging, cron/crons, skill/skills) → pick one canonical spelling. Note the merge in your final report (episode-file rewrite is future work, not this pass).

Keep the [meta] Episode tags line under ~250 characters. If it starts to bust, drop themes that have not been used in the last 30 days.

Optimization: If the tag output is large and the canonical list hasn't changed recently, scan only the top ~30 tags for missing canonicals. Don't waste tokens on the long tail.

7. Prune old files

bash
find ~/.hermes/episodes -name "*.md" -mtime +90 -delete
find ~/.hermes/sessions -name "*.jsonl" -mtime +180 -delete

8. Enforce capacity target

After all removals and drains, check the current size of MEMORY.md and read the configured limit from config (do NOT hardcode it — it has changed over time, e.g. 6000 → 8000):

bash
wc -c ~/.hermes/memories/MEMORY.md
LIMIT=$(grep -E '^\s*memory_char_limit:' ~/.hermes/config.yaml 2>/dev/null | grep -oE '[0-9]+' | head -1)
LIMIT=${LIMIT:-8000}
echo "limit=$LIMIT target(70%)=$((LIMIT*70/100))"

The target is 70% of the configured limit (limit 8000 → target 5600). Compute it from $LIMIT, never from a memorized number. GC must always leave the file below 100% of the limit — parking at 99% is the exact failure mode this step exists to prevent.

If the file exceeds the target, evict entries. Eviction priority (evict from top priority first):

  1. [env] entries older than 21 days (even if still accurate; they can be re-added if needed)
  2. [proj:*] entries older than 14 days
  3. [fact] entries older than 45 days
  4. Longest entries first (within the same priority tier)

When no entries meet age thresholds but file is over target: Fall back to evicting the longest [env] entries first, then longest [proj:*] entries, regardless of age. Prefer entries whose content is also captured in a dedicated memory file (e.g., ~/.hermes/memories/cpe-research.md) or in a skill, since those can be re-derived.

[pref] relocation (the file-stays-at-98% failure mode). A hot-memory file dominated by [rule] + [meta] + long project [pref] entries cannot be brought to target by the env/proj/fact ladder above — those are a small slice of the bytes. When the file is still over target after that ladder, treat long project-scoped [pref] entries as relocation candidates (NOT eviction — prefs encode user-approved decisions, so move them, don't drop them): append the content as a dated bullet to the project's dedicated memory file (e.g. Bloom prefs → bloom-architecture.md) via the memory tool (target = the filename, like Step 4 — never a raw shell append, which would trip the filesystem-scope safety rail), archive the original to ~/.hermes/episodes/.gc.log, then remove it from MEMORY.md. Generic cross-project prefs stay hot but get a lossless shortening pass. Never relocate a [rule] — rules are behavioral constraints that must stay in the system prompt every session.

Protected-floor guard (never silently park at 98%). Compute the byte total of [rule] + [meta] entries alone. If that floor already exceeds the 70% target, the target is unreachable without shortening protected entries:

  1. Losslessly shorten the longest [rule]/[meta] entries (preserve dates, categories, force, and behavioral meaning) until the file is under 100% of the limit.
  2. Relocate every project-scoped [pref] per the rule above.
  3. If still over the 70% target, do not loop forever — stop at the lowest achievable byte count and flag it in the final report ("protected floor N chars exceeds 70% target M; durable rule set has outgrown hot memory, consider raising memory_char_limit"). Parking just-under-limit with a flag is correct here; parking at 98% with no flag is the bug this guard prevents.

Before removing, archive evicted entries to ~/.hermes/episodes/.gc.log. Do NOT copy evicted entries back to .pending.md — that creates a feedback loop where entries bounce between MEMORY.md and pending indefinitely.

Keep evicting/relocating until the file is at or below the 70% target, or only [rule] and [meta] entries remain.

9. Log and report

Append a one-line summary to ~/.hermes/episodes/.gc.log:

bash
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) memory-gc removed=N drained=N consolidated=N themes_added=N files_pruned=N" \
  >> ~/.hermes/episodes/.gc.log

Your final response:

  • One short paragraph summarizing what changed.
  • Only mention anomalies (parse failures, unexpected state, consolidations you are unsure about). If everything was routine, say "routine pass, N entries removed, M drained, K pruned" and stop.

Safety rails

  • Never remove a [rule] or [meta] entry. They may be losslessly shortened (preserving date, category, and behavioral meaning) only under the protected-floor guard in step 8 — shortened, never removed.
  • Never remove something whose content you do not understand. Keep it.
  • If MEMORY.md / USER.md is malformed (no entries parse), stop immediately and report. Do not attempt repair.
  • All filesystem writes/deletes target only ~/.hermes/episodes and ~/.hermes/sessions. Never modify hermes-agent, skills, plans, config.yaml, .env, or anything outside those two directories. Read-only reads needed by this skill are exempt: reading config.yaml for the size limit (step 8) and reading ~/.hermes/memories/*.md for byte counts is fine — the rail forbids writing outside the two dirs, not reading.

Heefeg gestallte Froen

Wat mécht de KI-Skill Memory Gc?

Daily memory garbage collection for MEMORY.md / USER.md. Apply decay rules, drain .pending.md, consolidate near-duplicates, maintain canonical theme tags, prune old episode and session files. Invoke when asked to "run memory GC", "clean up memory", "apply memory decay", or from the scheduled cron job.

Firwat Memory Gc op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Memory Gc besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Memory Gc an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/exiao/skills/tree/main/memory/memory-gc an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Memory Gc benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Memory Gc benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Memory Gc domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Memory Gc gratis?

De Skill gëtt vum exiao op GitHub publizéiert. Kuckt am Repository no de Lizenzbedéngungen. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇