Memory Gcのロゴ

Memory Gc

コミュニティ
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.

概要

公開者exiao
リポジトリskills
スキル名memory-gc
スター
40
フォーク
12
同梱ファイル
指示のみ
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    exiaoがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルMemory GcをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/exiao/skills/tree/main/memory/memory-gc
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでMemory Gcを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にMemory Gcを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Memory Gcは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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.

よくある質問

AIスキル「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.

TypingMindでMemory Gcを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Memory Gcはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにMemory Gcをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/exiao/skills/tree/main/memory/memory-gcを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Memory Gcを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Memory Gcは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもMemory Gcを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Memory Gc」は無料ですか?

exiaoがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇