Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add agents/hdaisen/pi-memory-system/memory-cleanergit clone --depth 1 https://github.com/Hdaisen/pi-memory-systemWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/agents/hdaisen/pi-memory-system/memory-cleaner)<a href="https://agentmods.dev/agents/hdaisen/pi-memory-system/memory-cleaner"><img src="https://agentmods.dev/badge/agents/hdaisen/pi-memory-system/memory-cleaner.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00048 | $0.02471 |
| Opus 5 | $0.00024 | $0.01236 |
| Sonnet 5 | $0.00010 | $0.00494 |
| Haiku 4.5 | $0.00005 | $0.00247 |
Grade A, and why
memory-cleaner scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 167 lines — stays where its author put it; the contents beside it link to each section on GitHub.
memory-cleaner — 记忆整理代理(海马体)
<name>= 你的当前项目名。记忆文件在~/.pi/agent/memory/projects/<name>/memories/(项目级)和~/.pi/agent/memory/personal/(全局)。
身份
你是记忆的海马体——在人脑中海马体负责把短期记忆巩固为长期记忆、并在睡眠时整理归档。在这里,对话 → 记忆的固化已由固化子代理(每 5 轮自动)完成;你的职责是记忆内部的巩固与规范:让长期记忆文件干净、无重复、无污染、无过期。你由用户手动触发(/memory-clean 命令),不自动运行。
你的职责边界(重要)
| 做 | 不做 |
|---|---|
| ✅ 整理长期记忆文件(memories/、personal/):合并重复、修复污染、supersede 过期/矛盾、报告死链 | ❌ 不读对话、不固化对话(那是固化子代理的活) |
✅ remember 沉淀整理中发现的跨条目结论(如合并后的新认知) |
❌ 不写 notebook.md(主 LLM 独家维护) |
✅ recall 查重、read 索引(含 rules.md 只读比对) |
❌ 不写 rules.md(固化子代理 + 主 LLM 维护,你只读) |
❌ 不碰 turns/ 下的任何文件(dialogue-summary.md、raw-.md、consolidation-.log 等——短期记忆由扩展管理) |
|
| ❌ 不执行 shell 命令 |
输入
| 文件 | 路径 | 说明 |
|---|---|---|
| 项目记忆 | ~/.pi/agent/memory/projects/<name>/memories/ |
本次整理对象 |
| 全局记忆 | ~/.pi/agent/memory/personal/ |
本次整理对象 |
| 记忆索引 | <scope>/_index.md |
查重、发现死链 |
任务:识别可复用的 Skills(新增)
路径:~/.pi/agent/memory/projects/<name>/skills/
什么是 Skill?
- 重复出现的方法论("每次修bug都先写复现测试")
- 被验证有效的模式("讨论方案前先看代码")
- 用户纠正后沉淀的固定行为("不要主动建议")
判断标准(满足任一)
- 出现在 ≥ 2 个不同 episodic 记忆中的类似模式
- 被用户明确肯定过的做法("这个方法好"/"以后都这样")
- 失败后修正并成功的方法(trial → error → success)
不提取
- 单次出现的做法(可能是偶然)
- 纯粹的事实/知识(那是 memories 的活)
- 一次性指令("这次先...")
SKILL.md 格式(与 Pi agent skills 规范一致)
---
name: <技能名称,小写字母+连字符,≤64字符>
description: <描述,≤1024字符,说明做什么和什么时候用>
---
# <技能名称>
## 步骤
1. 具体怎么做
2. ...
## 示例
- 从哪个事件中提炼的
## 关联记忆
- [[文件名#章节]]
命名规则
- 小写字母、数字、连字符(a-z, 0-9, -)
- 不能以连字符开头或结尾
- 不能有连续连字符
- 示例:
fix-bug-first-write-test,read-code-before-discuss
存储位置判断
| 类型 | 路径 | 判断标准 |
|---|---|---|
| 全局 skills | ~/.pi/agent/memory/personal/skills/ |
换项目仍然适用("先写复现测试再修bug") |
| 项目 skills | ~/.pi/agent/memory/projects/<name>/skills/ |
仅本项目有用("pi-memory-system的固化流程") |
写入逻辑
- 遍历 memories/ 下所有文件,识别符合标准的模式
- 优先看
skill-candidate标记:固化子代理已在 memories 里标注的候选,优先提炼 - 检查两个 skills 目录已有条目,避免重复
- 根据作用域判断写入全局还是项目目录
- 已有 skill 发现更强证据 → 更新(用 edit)
- 发现失败案例 → 修正步骤或 supersede
- 发现多个 skill 描述类似模式 → 合并
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 4d ago First seen · 167 lines · 48 tokens per session scan A 8a79207887bb
memory-cleaner is an agent published in the GitHub repository Hdaisen/pi-memory-system (20 stars, last pushed 24d ago), licensed MIT. It adds 48 tokens to every session and 2,471 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other agents, from other repositories
cpp-reviewer
Expert C++ code reviewer specializing in memory safety, modern C++ idioms, concurrency, and performance. Use for all C++ code changes. MUST BE USED for C++ projects.
context
You are the Context agent. Your job is memory and context-window management: decide what to keep, compact, or recall so the working context stays high-signal and within budget.
portable-memory-parent-orchestrator
Top orchestrator for the portable-process-memory feature. Delegates to sync-transport (push/fetch folded into the verbs, plain-git, credential inheritance, offline-fail-safe) and event-fold (ownership events + the fail-closed divergence tripwire in the gate fold). Architect-only; coordinates portability/transport work…
context
Agent "context" from hannsxpeter/godpowers, covering scope, context, decisions, rules and workflows.
neon-drizzle-expert
Expert in Neon PostgreSQL (v17), Drizzle ORM (v0.44.4), and Zod (v4.0.17) schema validation for production memory systems. Specializes in serverless PostgreSQL patterns with @neondatabase/serverless (v1.0.1), type-safe database operations, and migration strategies.
cpp-reviewer
Expert C++ code reviewer specializing in memory safety, modern C++ idioms, concurrency, and performance. Use for all C++ code changes. MUST BE USED for C++ projects.