前言¶
DSH(DeepSeek Harness)在處理編碼任務時,常面臨 AI 遺忘之前被否決的實現方案、重複踩坑以及丟失項目工程約束的問題。dsh-plugin-memos-code-retrospect 插件復刻了 mneme 的編碼對話復盤蒸餾業務邏輯,通過提取被否決方案、踩坑記錄和工程約束,解決上述問題。它不引入 mneme 二進制或創建獨立數據庫,而是完全複用 MemOS 記憶底座進行數據持久化。
是什麼¶
該插件由 ai-fu-cn 維護,是一個 MIT 許可的開源插件。它通過在對話結束時(turn/end)提取被否決方案、踩坑記錄和工程約束,並將其打上 type:rejected_solution 標籤寫入 MemOS;在編碼任務推理前(agent/pre-step),對這些記憶進行加權召回並注入上下文,從而讓 AI 避開歷史陷阱。
核心功能¶
- turn/end 蒸餾:一輪交互結束後,插件從
session.events組裝完整對話上下文(可配置截斷長度),調用 LLM 提取三類實體:rejected_solution(被否決方案)、pitfall(踩坑記錄)、constraint(工程約束)。 - agent/pre-step 加權召回:Agent 推理前判斷任務類型,僅對編碼類任務檢索
type:rejected_solution記憶,提升權重(默認 2 倍)後注入提示詞。 - v2 健壯版:包含 LLM JSON 解析降級重試(≤1 次)、寫入前相似度去重(閾值 0.82)、低價值內容過濾以及 14/14 單元測試通過。
安裝與啓用¶
- 前置條件:確保已安裝 DSH(web profile)和 MemOS 本地插件(
@memtensor/memos-local-plugin),且 Node.js 版本 >= 18。 - 安裝插件:
dsh plugin --profile web install https://github.com/<your-github-name>/dsh-plugin-memos-code-retrospect
- 註冊到 DSH:將以下配置追加到
<profile>/cordis.patch.yml:
- insert:
- id: dsh-plugin-memos-code-retrospect
name: './plugins/dsh-plugin-memos-code-retrospect/dist/index.js'
config:
enabled: true
profileId: default
recallEnabled: true
captureEnabled: true
boostFactor: 2
recallTopK: 6
contextMaxChars: 3000
maxDistillContextChars: 8192
distillMaxTokens: 2048
distillRetries: 1
dedupeEnabled: true
dedupeThreshold: 0.82
valueFilterEnabled: true
sync_to_tencentdb: false
- 重啓服務:
Stop-Process -Name dsh -Force
dsh web --port 3080
啓動後日志中出現 `[retrospect]` 前綴即加載成功。
典型用法¶
- 編碼任務中報錯或否決方案,turn/end 後日志出現
[retrospect] distilled trace=...。 - 在 MemOS viewer 中檢索
tags: type:rejected_solution查看新 trace。 - 下一輪發起相關編碼任務,pre-step 日誌出現
injected rejected_solution recall,模型上下文包含<retrospect_context>。
注意事項¶
- 蒸餾質量:蒸餾質量依賴 LLM 指令跟隨能力,建議
distillMaxTokens >= 2048。 - 記憶延遲:記憶寫入發生在 turn/end,本輪寫入的記憶下一輪纔可被召回。
- 任務過濾:非編碼任務默認不注入
type:rejected_solution記憶,防止噪聲污染(codingKeywords可配)。 - 擴展預留:
sync_to_tencentdb爲預留擴展,本次未實現。 - MemOS 依賴:MemOS 不可用時插件 fail-open(可加載但記憶讀寫失效)。
- 數據隔離:插件只做邏輯處理,所有持久化操作全部調用 MemOS 接口,內部不保存數據;禁止拉起 mneme 子進程。