sage-mem 2.23.1 → 2.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +12 -5
- package/README.md +12 -5
- package/lib/autodream/engine.js +2 -0
- package/lib/autodream/llm-loop.js +10 -4
- package/lib/autodream/reconcile.js +20 -5
- package/lib/autodream/report.js +34 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
**Cross-session memory for DeepSeek Harness — plain markdown files, no database, no worker.**
|
|
14
14
|
|
|
15
|
-
**Current release: `2.
|
|
15
|
+
**Current release: `2.24.1`** — the npm badge above is the dynamic source of truth. **Contract baseline: `1.0.0`** — the first stable release, whose public commitments, the capability boundaries and the list of things it explicitly cannot do are frozen in the
|
|
16
16
|
[frozen contract](https://github.com/gezi-wen/sage-mem/blob/main/docs/1.0.0-contract.md).
|
|
17
17
|
|
|
18
18
|
If it is useful to you, a Star is the most direct feedback.
|
|
@@ -774,10 +774,17 @@ Or manually delete the `sage-mem` dependency from the profile's `package.json` a
|
|
|
774
774
|
|
|
775
775
|
## Credits
|
|
776
776
|
|
|
777
|
-
- [@bjvgukv25842-cmyk](https://github.com/bjvgukv25842-cmyk) (LITMUS) — the earliest Web memory management UI
|
|
778
|
-
- [@miztizm](https://github.com/miztizm) (mjztjzm) — i18n for the memory panel: the dictionary shard
|
|
779
|
-
- [@DDDMUC](https://github.com/DDDMUC) — three
|
|
780
|
-
-
|
|
777
|
+
- [@bjvgukv25842-cmyk](https://github.com/bjvgukv25842-cmyk) (LITMUS) — the earliest Web memory management UI: pagination, type badges, expandable bodies, two-step delete confirmation, and the `get_observations` read path. **No build tooling was added to the repository** — it was hand-written to match the host's artifact format, and that trade-off still shapes the project.
|
|
778
|
+
- [@miztizm](https://github.com/miztizm) (mjztjzm) — i18n for the memory panel: the dictionary shard plus the `ctx.locale` wiring, so three screens follow the harness language (1.9.0). It became the template for every later i18n batch.
|
|
779
|
+
- [@DDDMUC](https://github.com/DDDMUC) — three fixes, each closing a failure that looked random:
|
|
780
|
+
- **`interpolate: false` on the recall context** (2.4.2): a memory body containing double braces made the host throw `malformed prompt variable reference` while assembling the prompt, so the turn failed before the model even started — it looked like "sometimes it chats, sometimes any question fails", depending on which memories that turn happened to recall.
|
|
781
|
+
- **A short-circuit gate in the recall chain** (2.4.3): `system-prompt/assemble` fires on every step, and the old implementation ran the whole "scan → summary scoring → body BM25 → signature" chain before deduplicating. The decision inputs are all available before scoring.
|
|
782
|
+
- **The "open memory folder" entry** (2.4.0): no more hunting for the path in a file manager.
|
|
783
|
+
- **[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)** — not merely the host; this plugin's shape was forced by several of its designs:
|
|
784
|
+
- **Everything is a plugin, plus Cordis's service / event / fiber model** — file-based memory therefore needs no worker, port, or database;
|
|
785
|
+
- **`ctx.systemPrompt.section` and `agent/pre-step`** — injection and the pre-compaction reminder land on the right seams, instead of a prompt line saying "remember to read the files";
|
|
786
|
+
- **The typert remote protocol** — the type-safe channel between panel and host; the delete guard in 2.21.0 and the rollback guard in 2.22.0 both rely on it to carry "the version you confirmed" over to the host side;
|
|
787
|
+
- **The official docs (AGENTS.md / cordis-api / persistence)** — plugin authors can verify for themselves instead of guessing.
|
|
781
788
|
|
|
782
789
|
This plugin is alive today because of more than one person; the list above follows the order their code entered the repository. If I missed someone, open an issue and tell me off — I will add them.
|
|
783
790
|
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
> File-based cross-session memory for DeepSeek Harness — every memory is a plain markdown file you can open, edit and delete. No database, no worker, no port.
|
|
16
16
|
|
|
17
|
-
**当前发布版本:`2.
|
|
17
|
+
**当前发布版本:`2.24.1`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
|
|
18
18
|
[契约冻结](https://github.com/gezi-wen/sage-mem/blob/main/docs/1.0.0-contract.md)。
|
|
19
19
|
|
|
20
20
|
如果它对你有用,给个 Star 是最直接的反馈。
|
|
@@ -779,10 +779,17 @@ dsh plugin --profile web remove sage-mem
|
|
|
779
779
|
|
|
780
780
|
## 致谢
|
|
781
781
|
|
|
782
|
-
- [@bjvgukv25842-cmyk](https://github.com/bjvgukv25842-cmyk)(LITMUS)—— 最早的 Web
|
|
783
|
-
- [@miztizm](https://github.com/miztizm)(mjztjzm)—— 记忆管理面板的 i18n
|
|
784
|
-
- [@DDDMUC](https://github.com/DDDMUC)(暮迟)——
|
|
785
|
-
-
|
|
782
|
+
- [@bjvgukv25842-cmyk](https://github.com/bjvgukv25842-cmyk)(LITMUS)—— 最早的 Web 记忆管理界面:分页、类型徽章、展开正文、两步确认删除,以及 `get_observations` 这条读取通道。**没给仓库引入任何构建工具**,照着宿主产物的格式手写 —— 这个取舍一直影响到现在。
|
|
783
|
+
- [@miztizm](https://github.com/miztizm)(mjztjzm)—— 记忆管理面板的 i18n:字典分片 + `ctx.locale` 接线,三屏跟随宿主语言(1.9.0)。它是这个项目 i18n 的样板,后面几批照它的形状做。
|
|
784
|
+
- [@DDDMUC](https://github.com/DDDMUC)(暮迟)—— 三处,每处都堵掉一个「看起来像随机」的故障:
|
|
785
|
+
- **注入段声明 `interpolate: false`**(2.4.2):记忆正文里出现双大括号,宿主组装 prompt 时抛 `malformed prompt variable reference`,模型还没开始跑整轮就失败 —— 表现成「有时能聊、有时一提问就挂」,取决于这一轮召回到了哪些记忆。
|
|
786
|
+
- **注入链的短路闸门**(2.4.3):`system-prompt/assemble` 每个 step 都派发,旧实现每一步都把「扫描 → 摘要打分 → 正文 BM25 → 算签名」整条跑完再判重;而判据其实在打分之前就全拿得到。
|
|
787
|
+
- **「打开记忆文件夹」入口**(2.4.0):记忆目录不必再去文件管理器里翻路径。
|
|
788
|
+
- **[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)** —— 不只是宿主;这个插件的形态是被它的几处设计逼出来的:
|
|
789
|
+
- **一切皆插件 + Cordis 的 service / event / fiber** —— 文件式记忆因此不必自带 worker、端口或数据库;
|
|
790
|
+
- **`ctx.systemPrompt.section` 与 `agent/pre-step`** —— 注入与压缩前提醒能挂在正确的接缝上,而不是靠 prompt 里写「记得读文件」;
|
|
791
|
+
- **typert 远程协议** —— 面板与宿主之间那条类型安全的通道;2.21.0 的删除守卫、2.22.0 的回滚守卫都靠它把「你确认过的那一版」带到宿主侧;
|
|
792
|
+
- **官方文档(AGENTS.md / cordis-api / persistence)** —— 让插件作者能自己查证,而不是猜。
|
|
786
793
|
|
|
787
794
|
这个插件活到今天,靠的不只是我一个人。上面按代码进入仓库的顺序排。漏了谁的话开个 issue 骂我,我补上。
|
|
788
795
|
|
package/lib/autodream/engine.js
CHANGED
|
@@ -354,6 +354,8 @@ export class AutodreamEngine {
|
|
|
354
354
|
tokensOut: result.tokensOut,
|
|
355
355
|
snapshot,
|
|
356
356
|
changes: result.changes,
|
|
357
|
+
// 2.23.1:对账候选(`{rows, freshDays, staleDays}`)原样进声明 —— 「挑了几条」要可查。
|
|
358
|
+
reconcile: result.reconcile,
|
|
357
359
|
warnings: result.warnings,
|
|
358
360
|
notes: result.notes,
|
|
359
361
|
auditBefore,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { buildAutodreamSystemPrompt, buildAutodreamUserPrompt } from './prompt.js'
|
|
12
|
-
import {
|
|
12
|
+
import { buildReconcileDetail } from './reconcile.js'
|
|
13
13
|
import { readAccessLedger, ledgerFileFor } from '../memory/access.js'
|
|
14
14
|
import { scanMemoryDir } from '../memory/scan.js'
|
|
15
15
|
import { randomUUID } from 'node:crypto'
|
|
@@ -221,10 +221,10 @@ export async function agentLoop(cfg, runOpts) {
|
|
|
221
221
|
* 2.18.0「对账」:只在**会话记录也在输入源里**时,挑几条「还在被注入、内容却很久没动」
|
|
222
222
|
* 的记忆,让模型拿会话去核对它们。这是「查字典」之外的新切口 —— 字典补漏,对账纠错。
|
|
223
223
|
*
|
|
224
|
-
* 「什么时候算、算不出来怎么办」都在 `
|
|
224
|
+
* 「什么时候算、算不出来怎么办」都在 `buildReconcileDetail` 里(含静默降级),
|
|
225
225
|
* 这里只负责把真实 IO 递进去:扫目录拿 mtime,读 access 台账拿「最近被注入过没有」。
|
|
226
226
|
*/
|
|
227
|
-
const
|
|
227
|
+
const reconcile = await buildReconcileDetail({
|
|
228
228
|
source: cfg.source,
|
|
229
229
|
// 粗细刚好:这里只需要 mtime 做粗筛,正文一个字都不读(扫描层有目录缓存)。
|
|
230
230
|
listEntries: async () =>
|
|
@@ -238,7 +238,7 @@ export async function agentLoop(cfg, runOpts) {
|
|
|
238
238
|
hoursSince: runOpts.hoursSince ?? 0,
|
|
239
239
|
sessionCount: runOpts.sessionCount ?? 0,
|
|
240
240
|
now: Date.now(),
|
|
241
|
-
reconcileList,
|
|
241
|
+
reconcileList: reconcile.text,
|
|
242
242
|
})
|
|
243
243
|
const messages = [userMessage(userText)]
|
|
244
244
|
|
|
@@ -411,6 +411,12 @@ export async function agentLoop(cfg, runOpts) {
|
|
|
411
411
|
toolsUsed: allToolsUsed,
|
|
412
412
|
touched: runner.touchedFiles(),
|
|
413
413
|
changes: runner.changes(),
|
|
414
|
+
/**
|
|
415
|
+
* 2.23.1:对账候选与判据参数**原样带回**,让「这趟挑了几条」进整理声明。
|
|
416
|
+
* 不带的话,2.18.0 定的验收标准(挑 5 条、改 1–2 条算有用、全改算瞎改)无从验证 ——
|
|
417
|
+
* 报告里只有「改了什么」,看不出「本来要核对什么」。
|
|
418
|
+
*/
|
|
419
|
+
reconcile,
|
|
414
420
|
// warnings = 改动**没发生**(被拒);notes = 改动**发生了**但有话要说。两者不可混。
|
|
415
421
|
warnings: runner.warnings(),
|
|
416
422
|
notes: typeof runner.notes === 'function' ? runner.notes() : [],
|
|
@@ -125,6 +125,10 @@ export const RECONCILE_SOURCE = 'memory+sessions'
|
|
|
125
125
|
*
|
|
126
126
|
* ⚠️ 降级是**静默**的:对账是附加价值,它挂了不该让整趟做梦失败,也不该往报告里塞错误。
|
|
127
127
|
*
|
|
128
|
+
* 2.23.1:返回**结构**而不是纯文本。原因 —— `report.js` 里 grep 不到 `reconcile`,
|
|
129
|
+
* 于是「这趟挑了几条候选」永远不出现在整理声明里,2.18.0 定的验收标准无法验证。
|
|
130
|
+
* `rows` 进声明,`text` 仍拼进 prompt。
|
|
131
|
+
*
|
|
128
132
|
* @param {object} input
|
|
129
133
|
* @param {string} input.source — 本次输入源
|
|
130
134
|
* @param {() => Promise<Array<{file: string, mtime: number}>>} input.listEntries
|
|
@@ -132,14 +136,25 @@ export const RECONCILE_SOURCE = 'memory+sessions'
|
|
|
132
136
|
* @param {string} input.ledgerFile
|
|
133
137
|
* @param {number} [input.limit]
|
|
134
138
|
* @param {number} [input.now]
|
|
135
|
-
* @returns {Promise<string>}
|
|
139
|
+
* @returns {Promise<{rows: Array<object>, text: string, freshDays: number, staleDays: number}>}
|
|
136
140
|
*/
|
|
137
|
-
export async function
|
|
138
|
-
|
|
141
|
+
export async function buildReconcileDetail({ source, listEntries, readLedger, ledgerFile, limit, now = Date.now() }) {
|
|
142
|
+
const empty = { rows: [], text: '', freshDays: DEFAULT_FRESH_DAYS, staleDays: DEFAULT_STALE_DAYS }
|
|
143
|
+
if (source !== RECONCILE_SOURCE) return empty
|
|
139
144
|
try {
|
|
140
145
|
const rows = await collectReconcileCandidates({ listEntries, readLedger, ledgerFile, limit, now })
|
|
141
|
-
return renderReconcileList(rows)
|
|
146
|
+
return { ...empty, rows, text: renderReconcileList(rows) }
|
|
142
147
|
} catch {
|
|
143
|
-
return
|
|
148
|
+
return empty
|
|
144
149
|
}
|
|
145
150
|
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 只取列表文本的旧入口。**故意保持返回字符串**:`prompt.js` 直接拼它,六处测试按
|
|
154
|
+
* `=== ''` 断言,改返回类型的破坏面大于收益。新代码请用 `buildReconcileDetail`。
|
|
155
|
+
*
|
|
156
|
+
* @returns {Promise<string>} 列表文本;不该有或算不出来时是空串
|
|
157
|
+
*/
|
|
158
|
+
export async function buildReconcileList(opts) {
|
|
159
|
+
return (await buildReconcileDetail(opts)).text
|
|
160
|
+
}
|
package/lib/autodream/report.js
CHANGED
|
@@ -42,6 +42,11 @@ export async function writeDeclaration(payload) {
|
|
|
42
42
|
after: { problems: payload.auditAfter?.problems ?? 0 },
|
|
43
43
|
},
|
|
44
44
|
changes: payload.changes,
|
|
45
|
+
/**
|
|
46
|
+
* 2.23.1:对账段(`{rows, freshDays, staleDays}`)。没有候选时是空结构 ——
|
|
47
|
+
* 那种情况声明里整节不出现,与 prompt 的阶段 2.5 同一条件。
|
|
48
|
+
*/
|
|
49
|
+
reconcile: payload.reconcile ?? { rows: [], freshDays: 0, staleDays: 0 },
|
|
45
50
|
warnings: payload.warnings,
|
|
46
51
|
notes: payload.notes ?? [],
|
|
47
52
|
// 自动归档策略那一段:候选清单是**确定性算出来的**(访问台账 → updated → mtime),
|
|
@@ -335,6 +340,33 @@ function renderTrim(lines, trim, H) {
|
|
|
335
340
|
}
|
|
336
341
|
}
|
|
337
342
|
|
|
343
|
+
/**
|
|
344
|
+
* 对账候选清单(2.23.1,阶段 2.5)。
|
|
345
|
+
*
|
|
346
|
+
* 为什么必须有这一节:2.18.0 的对账真的在跑(2026-11-28 那趟改对了三处过时版本号),
|
|
347
|
+
* 但报告里 grep 不到 `reconcile` —— 「挑了几条、结论如何」永远查不到,记忆里定的
|
|
348
|
+
* 验收标准(挑 5 条、改 1–2 条算有用、5 条全改算模型在瞎改)根本没法用。
|
|
349
|
+
*
|
|
350
|
+
* 放在改动表之前:先看「本来要核对哪几条」,再看「实际改了什么」,两个数一比才有意义。
|
|
351
|
+
* 没有候选时整节不出现,避免在每份报告里挂一张空表。
|
|
352
|
+
*/
|
|
353
|
+
function renderReconcile(lines, m, H) {
|
|
354
|
+
const r = m.reconcile ?? {}
|
|
355
|
+
const rows = Array.isArray(r.rows) ? r.rows : []
|
|
356
|
+
if (!rows.length) return
|
|
357
|
+
lines.push(`${H}# 对账候选(阶段 2.5)`, '')
|
|
358
|
+
if (r.freshDays && r.staleDays) {
|
|
359
|
+
lines.push(`判据:注入台账在 **${r.freshDays} 天**内仍在服役 + 文件内容 **${r.staleDays} 天**没动。`, '')
|
|
360
|
+
}
|
|
361
|
+
lines.push('| 文件 | 距上次注入 | 内容闲置 |', '|---|---|---|')
|
|
362
|
+
for (const row of rows) {
|
|
363
|
+
lines.push(`| \`${row.file}\` | ${row.injectedDays ?? '?'} 天 | ${row.idleDays ?? '?'} 天 |`)
|
|
364
|
+
}
|
|
365
|
+
lines.push('')
|
|
366
|
+
lines.push('> 这几条**未必被改**:全部核对通过、一条不改也是正常结果(说明记忆还准)。')
|
|
367
|
+
lines.push('> 对照下面的改动表看:改 1–2 条 = 有用;全改 = 大概率在瞎改。', '')
|
|
368
|
+
}
|
|
369
|
+
|
|
338
370
|
/** 渲染人读声明(报告里内嵌,所以标题层级可以从外面压)。 */
|
|
339
371
|
export function renderDeclaration(m, headingLevel = 1) { const H = '#'.repeat(Math.max(1, Math.min(6, headingLevel)))
|
|
340
372
|
const lines = [
|
|
@@ -358,6 +390,8 @@ export function renderDeclaration(m, headingLevel = 1) { const H = '#'.repeat(M
|
|
|
358
390
|
`${H}# 改了什么、为什么`,
|
|
359
391
|
'',
|
|
360
392
|
]
|
|
393
|
+
// 对账候选放在改动表**之前**:先看「本来要核对哪几条」,再看「实际改了什么」。
|
|
394
|
+
renderReconcile(lines, m, H)
|
|
361
395
|
if (!m.changes.length) {
|
|
362
396
|
lines.push(m.mode === 'apply' ? '(本次没有改动任何文件)' : '(只出报告模式,未改动文件)', '')
|
|
363
397
|
} else {
|
package/package.json
CHANGED