Repository navigation
Plugin|Zero-Token Deterministic Engineering Memory & Session Digest Plugin | 零 Token 消耗的仓库级确定性工程记忆与历史会话摘要插件 #15845
kentzjh-cmd
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
一句话总结:对话压缩(compact)或长日志被截断时,
tmem顺手把完整现场存进仓库本地,只在上下文里内联一张极短的历史路标,由模型自己判断要不要、以及要找回多少历史;记忆来自真实的工具执行轨迹,不请 LLM 写总结,0 总结 Token。项目地址
https://github.com/kentzjh-cmd/tmem
项目介绍
tmem(Trace Memory,npm 包名dsh-tmem)是专门为@deepseek-ai/dsh(DeepSeek Harness)打造的本地代码记忆插件,纯 Node.js 实现、零第三方依赖,所有记录都存在当前仓库的.tmem/目录里。用 Coding Agent 长期维护同一个仓库时,常见 4 个痛点:
compact或测试日志被截断后,前面定好的方案、改过的代码行、关键报错被一起折叠,模型只好重新满仓库找文件、重踩一遍坑。tmem的做法:git checkout/rm清掉的临时改动和测试通过后未验证的尾巴,保留下来的路径、符号、报错原文 100% 真实发生过。compaction/summary、compaction/end、compaction/prune事件,把被折叠的完整片段存进.tmem/episodes/;跨 commit 或多任务自动拆分子片段,并用prev_episode_id+phase_index串成#1 → #2 → #3时间线。压缩后在<compact-checkpoint>旁内联一张<tmem_compacted_index>路标——摘要够用就零消耗,不够时模型自己按需召回。node:sqlite(FTS5)建 8 类倒排索引(intent / error / decision / symbol / file / command / diff / raw_output):tmem_search快速定位;tmem_expand(level="slice")阶段目标、关键决策、Turn 目录、改动文件;tmem_expand(level="turn" | "diff")逐轮对话与精确补丁;tmem_expand(level="raw", query=...)被截断的长日志原文 / 未裁剪原始执行历史,可沿时间线全量拼回。.tmem/episodes/(全量会话备份,不进 Git,30 天 / 200MB 自动清理);.tmem/traces/+MEMORIES.md(只沉淀跨文件修复、典型报错修法等高价值 Playbook,可提交 Git 团队共享)。L0_FULL降级为L1_TOPOLOGY/L2_INVARIANT,只保留思路不塞过时代码。与 DSH 的集成方式
tmem通过package.json(dsh-tmem)与cordis.patch.yml原生接入 DSH Cordis 插件生命周期(入口tmem/dsh_plugin.mjs),进程内直接调用,无子进程冷启动:session/event,兼容 CLI / Headless / Web)tmem_search、tmem_expand两个模型工具,由模型自主决定看梗概还是全量找回历史。agent/pre-step).tmem/env_facts.json、压缩后内联<tmem_compacted_index>,或输入中含显式文件路径 / 报错类型锚点时才召回;泛自然语言提问误注入率 0.0%。tools/post-execute)read/grep/glob);<tmem_cochange_hint>提醒搭档文件(连续忽略 3 次自动闭嘴);编辑 → 验证通过时触发<tmem_milestone_reached>,并在.tmem/telemetry.jsonl记录 L2 转绿率与 L1 采纳率。/tmem斜杠命令(commands.register)/tmem [status|search|episodes|expand|list|inspect|replay|diff|sync|gc|forget|telemetry|evaluate](兼容/remember、/trace)。session.v4.jsonl与git diff,配合tmem init安装的post-commit钩子自动增量切片与合并记忆。快速安装与使用
常用命令:
可复现评测表现(
benchmarks/内脚本,CI 通过node scripts/verify_benchmarks.mjs自动校验)node benchmarks/eval_compact_recall.mjs):4 类“压缩即遗忘”场景关键细节找回率 0.0% → 100.0%(0/4→4/4);仅 L0 路标节省上下文 91.6%(7,157 → 603 tok),加上按需 L1/L2 展开仍节省 87.0%;检索 ~6 ms,展开 < 10 ms。node benchmarks/eval_dsh_e2e.mjs):交互步数减少 37.5%(8 → 5 步);L2 转绿率 / L1 采纳率 100%;泛自然语言负例误注入 0.0%(0/10);21 次高频钩子总耗时 ~5 ms。eval_slicing_fidelity.mjs/eval_llm_judge.mjs):Precision 93.8% / Recall 95.0% / F1 93.6%,盲测均分 4.80/5,成对胜率 49:1(98.0%)(基线 F1 71.4%)。eval_plugin_scale.mjs/eval_retrieval.mjs):898 → 157 步(82.5% 精简,字符压缩 94.8%);49 条库规模下显式锚点召回 100%(48/48)、L2 拦截转绿 100%(7/7);原始需求检索 Recall@1 100% / MRR 1.0。signature_match能拦住签名变化,但“签名不变、内部逻辑重写”仍需靠测试兜底。Unofficial project, independently developed and maintained by community members, with no affiliation with DeepSeek.
Project URL
https://github.com/kentzjh-cmd/tmem
Introduction
tmem(Trace Memory, published on npm asdsh-tmem) is a zero-dependency, pure Node.js, repository-scoped (.tmem/) memory plugin built specifically for@deepseek-ai/dsh(DeepSeek Harness).In plain words: whenever a long chat gets compacted or a huge terminal log gets truncated,
tmemsaves a complete snapshot on the spot and keeps an ultra-compact inline roadmap in the conversation. The model decides for itself whether the summary is enough—or whether to pull back specific diffs, pruned logs, or the full prior session history. It spends zero summarization tokens: memory is trimmed from real tool executions, not paraphrased by an LLM.Key ideas:
compaction/summary,compaction/end,compaction/prune; saves folded chunks into.tmem/episodes/, splits across commits/modules, and chains them (prev_episode_id+phase_index:#1 → #2 → #3), leaving an inline<tmem_compacted_index>next to<compact-checkpoint>.node:sqliteFTS5 index: L0 inline index /tmem_search; L1tmem_expand(level="slice"); L2level="turn" | "diff"; L3level="raw"for untruncated logs and full history..tmem/episodes/(full archive, gitignored, 30-day TTL / 200MB LRU) vs..tmem/traces/+MEMORIES.md(git-friendly, high-value team playbooks).L0_FULLtoL1_TOPOLOGY/L2_INVARIANT.How It Integrates with DSH
Native Cordis integration via
package.json(dsh-tmem) andcordis.patch.yml(entry:tmem/dsh_plugin.mjs), running in-process with zero cold start:session/event, CLI / Headless / Web): registerstmem_searchandtmem_expandso the model drives recall.agent/pre-step): only on Turn 1 (env_facts.json), right after compaction, or on explicit file / error anchors — 0.0% false injection on casual prompts.tools/post-execute): skipsread/grep/glob; instant same-origin L2 error fixes; L1 co-change hints (<tmem_cochange_hint>, auto-mute after 3 ignores);<tmem_milestone_reached>and.tmem/telemetry.jsonltracking./tmemslash commands:/tmem [status|search|episodes|expand|list|inspect|replay|diff|sync|gc|forget|telemetry|evaluate](also/remember,/trace).session.v4.jsonlandgit diff;tmem initinstalls apost-commithook for incremental capture.Quick Start
Reproducible Benchmarks (in
benchmarks/, verified in CI)eval_compact_recall.mjs): key detail recall 0.0% → 100.0% (0/4→4/4); L0 index saves 91.6% context tokens (7,157 → 603), L0 + targeted L1/L2 still saves 87.0%; ~6 ms search, < 10 ms expansion.eval_dsh_e2e.mjs): 37.5% step reduction (8 → 5); 100% L2 resolution / L1 adoption; 0.0% (0/10) holdout false positives; ~5 ms across 21 hot-path events.48/48), 100% L2 interception (7/7); Recall@1 100% / MRR 1.0.All reactions