sage-mem 2.15.3 → 2.15.4
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/memory/archive.js +24 -6
- 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.
|
|
15
|
+
**Current release: `2.15.4`** — 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.15.
|
|
17
|
+
**当前发布版本:`2.15.4`** —— 顶部 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/memory/archive.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* 就是临时目录),拿模块级常量会写错地方 —— 那是会碰到真实记忆的危险错误。
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { ARCHIVE_DIR_NAME, addArchiveMeta, inspectDir, inspectMemoryEntry, localStamp, readArchivedMeta, stripArchiveMeta } from './scan.js'
|
|
18
|
+
import { ARCHIVE_DIR_NAME, addArchiveMeta, inspectDir, inspectMemoryEntry, localStamp, readArchivedMeta, shadowsReserved, stripArchiveMeta } from './scan.js'
|
|
19
19
|
import { isReserved, nameKey, safeName } from './naming.js'
|
|
20
20
|
import { revisionOf } from './chunks.js'
|
|
21
21
|
import { retireTaken, returnSource, takeOverSource, writeFileAtomic, writeFileExclusive } from './util.js'
|
|
@@ -28,13 +28,31 @@ import { randomUUID } from 'node:crypto'
|
|
|
28
28
|
/** 归档区绝对路径(按调用方给的记忆目录算)。 */
|
|
29
29
|
export const archiveDirOf = (memoryDir) => join(memoryDir, ARCHIVE_DIR_NAME)
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* 名字闸门:保留名 → 非 .md / 带路径成分 → **保留名的另一个名字**(8.3 短名 / 硬链接)。
|
|
33
|
+
*
|
|
34
|
+
* 返回 `{ ok:true, safe }` 或 `{ ok:false, code, error }`。
|
|
35
|
+
*
|
|
36
|
+
* ⚠️ 2.15.4:第三条原先只在 read / write / delete 三条路径上做(`index.js`、`write-protocol.js`),
|
|
37
|
+
* 归档 / 恢复 / 彻底删除这一侧漏了 —— 于是 `archive('MEMORY~1.MD')`(或一个指向索引的硬链接名)
|
|
38
|
+
* 能把**索引本体**搬进归档区,`deleteArchived` 那条更是不可逆。三处入口现在共用这一份判据。
|
|
39
|
+
*
|
|
40
|
+
* @param {string} dir — 名字所在目录(归档时是记忆根,恢复 / 删除时是归档区):
|
|
41
|
+
* 身份判据必须对着**真正要动的那个文件所在目录**算,否则算出来的是另一棵树的保留名身份。
|
|
42
|
+
*/
|
|
43
|
+
async function checkName(dir, name, verb) {
|
|
33
44
|
if (isReserved(name)) {
|
|
34
45
|
return { ok: false, code: 'reserved', error: `sage-mem: reserved file, refusing to ${verb}: ${nameKey(name)}` }
|
|
35
46
|
}
|
|
36
47
|
const safe = safeName(name)
|
|
37
48
|
if (!safe) return { ok: false, code: 'invalid_name', error: `sage-mem: invalid file name: ${String(name)}` }
|
|
49
|
+
if (await shadowsReserved(join(dir, safe))) {
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
code: 'reserved',
|
|
53
|
+
error: `sage-mem: reserved file (它的另一个名字是 ${safe}),拒绝${verb}`,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
38
56
|
return { ok: true, safe }
|
|
39
57
|
}
|
|
40
58
|
|
|
@@ -48,7 +66,7 @@ function checkName(name, verb) {
|
|
|
48
66
|
* @returns {Promise<{ok:true,file:string,archivedReason:string}|{ok:false,code:string,error:string}>}
|
|
49
67
|
*/
|
|
50
68
|
export async function archiveMemory(memoryDir, name, reason, at = localStamp()) {
|
|
51
|
-
const gate = checkName(name, '
|
|
69
|
+
const gate = await checkName(memoryDir, name, '归档')
|
|
52
70
|
if (!gate.ok) return gate
|
|
53
71
|
const safe = gate.safe
|
|
54
72
|
/**
|
|
@@ -231,7 +249,7 @@ export async function archiveMemory(memoryDir, name, reason, at = localStamp())
|
|
|
231
249
|
* 覆盖等于悄悄改掉一条活记忆。
|
|
232
250
|
*/
|
|
233
251
|
export async function restoreMemory(memoryDir, name) {
|
|
234
|
-
const gate = checkName(name, '
|
|
252
|
+
const gate = await checkName(archiveDirOf(memoryDir), name, '恢复')
|
|
235
253
|
if (!gate.ok) return gate
|
|
236
254
|
const safe = gate.safe
|
|
237
255
|
const dst = join(memoryDir, safe)
|
|
@@ -414,7 +432,7 @@ export function archivedRevisionOf(content) {
|
|
|
414
432
|
* @returns {Promise<{ok:true,file:string}|{ok:false,code:string,error:string}>}
|
|
415
433
|
*/
|
|
416
434
|
export async function deleteArchivedMemory(memoryDir, name, expectedArchivedAt = '', expectedRevision = '') {
|
|
417
|
-
const gate = checkName(name, '
|
|
435
|
+
const gate = await checkName(archiveDirOf(memoryDir), name, '彻底删除')
|
|
418
436
|
if (!gate.ok) return gate
|
|
419
437
|
const safe = gate.safe
|
|
420
438
|
const dirGate = await inspectDir(archiveDirOf(memoryDir))
|
package/package.json
CHANGED