sage-mem 2.23.0 → 2.24.0
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 +1 -1
- package/README.md +1 -1
- 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/lib/memory/naming.js +28 -1
- 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.0`** — 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.
|
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.0`** —— 顶部 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 是最直接的反馈。
|
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/lib/memory/naming.js
CHANGED
|
@@ -27,9 +27,36 @@ export function isNonEntry(raw) {
|
|
|
27
27
|
return NON_ENTRY_FILES.has(nameKey(raw))
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 同步冲突副本:**不是记忆条目**。
|
|
32
|
+
*
|
|
33
|
+
* 为什么必须单独认:任何同步工具撞到「两边都改了」都会在同一个目录里落一份副本,
|
|
34
|
+
* 而副本的名字仍以 `.md` 结尾 —— 只按后缀判断的旧判据会把它当正常记忆读进去、
|
|
35
|
+
* 参与检索、参与注入。3.0 调研 §2.1 用仓库自己的函数实测过:
|
|
36
|
+
* `isMemoryEntry('x.sync-conflict-….md')` 返回 true。
|
|
37
|
+
*
|
|
38
|
+
* 认的模式都带**具体来源的专有标记**,不按「像不像副本」猜:
|
|
39
|
+
* - Syncthing:`<name>.sync-conflict-YYYYMMDD-HHMMSS-XXXXX.md`
|
|
40
|
+
* - Dropbox:`<name> (conflicted copy …).md`
|
|
41
|
+
* - 资源管理器中文 / 英文:`<name> - 副本.md`、`<name> - Copy.md`
|
|
42
|
+
*
|
|
43
|
+
* **故意不认** `x (1).md` 这种纯编号:太宽,会把正常按序号命名的文件误伤;
|
|
44
|
+
* 也不认 `~$x.md`(那是 Word 锁文件,不以 .md 结尾的场景更多)。
|
|
45
|
+
*/
|
|
46
|
+
export function isConflictCopy(raw) {
|
|
47
|
+
const n = nameKey(raw)
|
|
48
|
+
return (
|
|
49
|
+
n.includes('.sync-conflict-') ||
|
|
50
|
+
n.includes('conflicted copy') ||
|
|
51
|
+
n.includes(' - 副本') ||
|
|
52
|
+
n.includes(' - copy')
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
30
56
|
/** 目录扫描过滤:这个名字算不算一条记忆条目。 */
|
|
31
57
|
export function isMemoryEntry(name) {
|
|
32
|
-
|
|
58
|
+
const s = String(name ?? '')
|
|
59
|
+
return /\.md$/i.test(s) && !isNonEntry(s) && !isConflictCopy(s)
|
|
33
60
|
}
|
|
34
61
|
|
|
35
62
|
/**
|
package/package.json
CHANGED