前言¶
coding agent 在项目中会反复询问相同或相关的问题,但每次都需要重新阅读文件、搜索代码或翻阅历史对话,效率较低。Cluster Memory 记录 agent 之前询问过什么、在哪些文件中找到答案、得出了什么结论,下次提问时通过一次关键字查找即可回答。
插件定位¶
Cluster Memory 是一个为 coding agent 提供记忆功能的 DeepSeek Harness 插件,分类为「记忆」。它通过关键字 trail(线索)+ 分层搜索(trail → graph → files → history)的方式,让 agent 在项目中记住答案来源。插件由 Granit1846 维护,版本 1.2.0,基于 Node 20+,MIT 许可证。
核心功能¶
分层搜索¶
Cluster Memory 按成本从低到高分层搜索:
- 关键字 trail:从记录的 trail 中查找关键字,成本约 230 tokens
- 代码图 / grep:使用 graphify 或 grep 搜索代码结构,成本 100–600 tokens
- 源文件:读取目标文件,成本 1.5–2.5k tokens/文件
- 历史对话:搜索会话历史,成本 3–6k tokens
第一次搜索命中后即停止,避免不必要的成本。
记录答案¶
每次 agent 回答问题后,可以将答案记录到 trail 中,包括:
- 问题内容
- 结论摘要
- 关键字列表
- 相关文件
- 图节点名称
- 记录结果(useful / not useful)
记录后,后续相同或相关的问题可以直接通过关键字查找得到答案,无需重新阅读文件或搜索代码。
存储结构¶
项目根目录下生成 .cluster-memory/ 目录:
- trail.jsonl:追加式日志,每行一个 JSON 对象
- index.json:关键字索引,由 rebuild 命令生成
trail.jsonl 是真相来源,index.json 是派生索引。索引只保留 1200 个关键字,日志最大 4MB 并自动压缩。关键字每条记录最多 12 个。
安装与启用¶
通过 DSH 插件安装¶
DSH 0.2.0-rc.1+ 支持直接从 GitHub 安装 bundle,无需构建或 npm 发布。在 DSH 会话中执行:
Install the cluster-memory bundle from github:Granit1846/cluster-memory
这会运行 plugin_manager 的 install_bundle 动作,目标为 github:Granit1846/cluster-memory。也可以通过 GUI:Plugins → Add plugin → 输入相同 spec → 安装 → 按提示重启。
或从终端使用命令:
dsh plugin --profile <name> add github:Granit1846/cluster-memory
安装后会在 profile 中生效,下次启动该 profile 时自动激活。
配置¶
插件通过 profile patch 或环境变量配置。主要配置项:
| Key | Default | Effect |
|---|---|---|
trail |
true |
是否自动记录每次 settled tool call |
autobuild |
true |
首次读取时是否自动构建代码图 |
autobuildFileLimit |
4000 |
自动构建时的文件上限 |
autobuildTimeoutMs |
300000 |
自动构建超时时间 |
bin |
auto | graphify 可执行文件路径 |
captureDir |
OS temp | CLI 输出捕获目录 |
historyHint |
auto |
是否提示使用历史对话工具 |
tools |
all 15 | 允许使用的工具列表 |
环境变量命名格式为 DSH_GRAPHIFY_ 前缀,如 DSH_GRAPHIFY_TRAIL=0。
典型用法¶
手动查询¶
# 第一层:查找关键字 trail
node scripts/cluster-memory.mjs where "how is the invoice total computed"
# 记录答案
node scripts/cluster-memory.mjs remember \
--question "how is the invoice total computed" \
--answer "parseInvoice strips non-digits; total lives on the invoice object." \
--keywords invoice,total,parse \
--files src/invoice.js --nodes parseInvoice --outcome useful
# 查看摘要和近期记录
node scripts/cluster-memory.mjs summary
node scripts/cluster-memory.mjs recent --limit 10
# 重建索引
node scripts/cluster-memory.mjs rebuild
当 agent 运行在项目根目录外时,通过 --cwd DIR 指定项目目录。
作为 agent skill 使用¶
作为 skill 时,通过 git clone 安装到 agent 的 skills 目录:
git clone https://github.com/Granit1846/cluster-memory.git ~/.claude/skills/cluster-memory
安装后运行 node ~/.claude/skills/cluster-memory/scripts/cluster-memory.mjs summary 验证。
skill 支持的 agent:Claude Code、Codex、Cursor、Gemini CLI 等。
适用场景与注意¶
Cluster Memory 适合需要在多个 agent 之间共享项目记忆的场景,例如:
- 多个 coding agent 在同一项目中协作
- 需要跨会话记住代码结构和决策的场景
注意:
- 插件以当前 DSH 进程权限运行,安装前应检查源码与许可证
- trail 只记录明确写入的内容,未记录的决策不会出现在记忆中
- 索引是词法匹配(前缀、词干),不是语义匹配,无法通过 embeddings 查询
- 插件依赖 Node 20+,不依赖数据库、服务器或模型调用
结语¶
Cluster Memory 通过关键字 trail 和分层搜索,让 coding agent 在项目中记住答案来源,减少重复阅读和搜索的成本。作为 DeepSeek Harness 插件,它集成在 DSH 工作流中,可与 graphify CLI 协同,也可独立作为 skill 使用。
更多细节见:GitHub 仓库