dsh-plugin-memory 0.9.4 → 0.10.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/CHANGELOG.md +26 -0
- package/README.md +16 -0
- package/README.zh.md +16 -0
- package/package.json +1 -1
- package/scripts/memory.mjs +147 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
|
|
4
4
|
|
|
5
|
+
## [0.10.0] - 2026-10-16
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **`dsh-memory doctor` — 环境体检,一条命令定位"感觉哪里不对"**。检查的是**实际会坏的那些东西**,每条结论后面直接跟修复命令:
|
|
10
|
+
| 检查项 | 说明 |
|
|
11
|
+
|---|---|
|
|
12
|
+
| 目录可写 | 用**真实写入探针**判断(不看 mode 位——ACL 下会骗人) |
|
|
13
|
+
| 脚手架 | `SOUL.md` / `MEMORY.md` / `index.md` / `log.md` / `BOOTSTRAP.md` 是否齐全 |
|
|
14
|
+
| 页面 / 孤儿页 | 存在但没进 `index.md` 的页面,附 `index --write` |
|
|
15
|
+
| index 死链 | `index.md` 指向但不存在的页(**硬失败**) |
|
|
16
|
+
| git 状态 | 是否仓库 / 未提交数 / **领先远端多少提交未 push** |
|
|
17
|
+
| boot 预算 | `SOUL+MEMORY+index` 实际字符数 vs 默认 12000(标注"实际以插件配置为准") |
|
|
18
|
+
| 陈旧度 | 复用 `accessSummary`,与 `status` 同源 |
|
|
19
|
+
|
|
20
|
+
**退出码**:有硬失败 → 1(可当 CI 闸门);只有提醒 → 0。
|
|
21
|
+
- **实测立刻见效**:在真实记忆库上首跑就报出「**领先远端 57 个提交**」——正是下面那条建议所指的问题;同时报出 boot 预算已用到 **10729/12000(89%)**。
|
|
22
|
+
|
|
23
|
+
- **README 增加「快速上手 / Quickstart」**(中英双语),放在 Features 之前:三步(装 → 重启说句话看铸魂 → `doctor` 或设置页确认),不必先啃完 20 条特性。两个 README 的 CLI 章节也补上了 `doctor`。
|
|
24
|
+
|
|
25
|
+
### Tests
|
|
26
|
+
|
|
27
|
+
- `test/cli.test.mjs` 新增 4 条(先 RED 后实现):报告脚手架/页面数/git 状态;缺文件时报 `✗` 且不崩;有孤儿页时指向修复命令;`doctor` 出现在 help 里。
|
|
28
|
+
- 全量 **181/181 通过**(0.9.4 时 177);`npm test` self-test 通过。
|
|
29
|
+
- 过程中一条测试写错并已修正:`execFileSync` 在非零退出码时抛异常,断言要从 `error.stdout` 取输出——**是测试写法问题,不是 doctor 的缺陷**。
|
|
30
|
+
|
|
5
31
|
## [0.9.4] - 2026-10-15
|
|
6
32
|
|
|
7
33
|
### Added(中英双语 README)
|
package/README.md
CHANGED
|
@@ -13,6 +13,21 @@
|
|
|
13
13
|
|
|
14
14
|
A Cordis plugin for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) that gives agents persistent, cross-session, migratable long-term memory: a markdown + git store (inspired by Karpathy's *LLM Wiki* pattern) with a `SOUL.md` persona file, **auto-injected at every session start** through the system-prompt runtime context, plus remember / recall / consolidate / forget workflows and portable CLI tooling.
|
|
15
15
|
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
Three steps, about five minutes:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
# 1. install
|
|
22
|
+
dsh plugin --profile <profile> add dsh-plugin-memory
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. **Restart the app**, open a session and say anything. The boot block loads automatically — and because the store has no soul yet, the agent **starts the soul-forging conversation by itself**: what its name is, how to address you, what you are to each other, what personality it should have. Answer as much or as little as you like; each answer is written back.
|
|
26
|
+
|
|
27
|
+
3. **Confirm it took.** `dsh-memory doctor` gives an environment check-up (scaffold, orphan pages, git state, boot budget) and ends with the command that fixes each finding. Or open **Settings → Memory** for the health dashboard and hot-editable options.
|
|
28
|
+
|
|
29
|
+
After that the loop is simple: the agent writes memories back as you work, and you can steer the store by hand whenever you like — it is plain markdown plus git, nothing locked in.
|
|
30
|
+
|
|
16
31
|
## Features
|
|
17
32
|
|
|
18
33
|
- **Mandatory boot injection (with routing-table protection)**: the plugin injects a memory boot block (`SOUL.md` persona + `MEMORY.md` protocol + `index.md` directory + recent activity) into the session context via `ctx.systemPrompt.context()`. The host deduplicates by projection: an unchanged memory is injected once, and a changed memory replaces the previous snapshot — this is the **hard guarantee** that a new session always loads memory first, rather than hoping the model calls a skill. The total budget is `bootMaxChars`, **allocated per file**: every file first gets an equal share (capped by its real size), and the remaining budget goes to `index.md` first, then to files that still have content left — so as the store grows, the tail of the directory is not the first thing to be truncated (see "boot budget allocation"). Two polite gates ship enabled by default: `deferUntilUserSpeaks` (inject only after the user speaks) and `activeSessionOnly` (inject only into the currently active session) — see "Configuration".
|
|
@@ -171,6 +186,7 @@ dsh-memory query --type decision --tag dsh --hot --stale [keywords]
|
|
|
171
186
|
# structured query: filter by frontmatter, then match the body
|
|
172
187
|
dsh-memory checkup [--boot=N] # one report: size/freshness/connectivity/consistency + prioritised actions
|
|
173
188
|
dsh-memory lint # integrity check
|
|
189
|
+
dsh-memory doctor # environment check-up + the command that fixes each finding
|
|
174
190
|
dsh-memory status # health overview (including stale-page counts)
|
|
175
191
|
dsh-memory pack [out.tar.gz] # export an archive (with manifest)
|
|
176
192
|
dsh-memory unpack <archive> [--force] # restore from an archive
|
package/README.zh.md
CHANGED
|
@@ -13,6 +13,21 @@
|
|
|
13
13
|
|
|
14
14
|
**English TL;DR** — A Cordis plugin for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) that gives agents a persistent, cross-session, migratable long-term memory: a markdown + git store (inspired by Karpathy's *LLM Wiki* pattern) with a `SOUL.md` persona file, **auto-injected at every session start** via the system-prompt runtime context, plus remember / recall / consolidate / forget workflows and portable CLI tooling.
|
|
15
15
|
|
|
16
|
+
## 快速上手
|
|
17
|
+
|
|
18
|
+
三步,大约五分钟:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
# 1. 安装
|
|
22
|
+
dsh plugin --profile <profile> add dsh-plugin-memory
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. **重启应用**,开个会话随便说句话。boot 块会自动加载——因为记忆库还没有灵魂,agent 会**主动开始「铸魂」对话**:它叫什么名字、怎么称呼你、你们是什么关系、该是什么性格。答多答少都行,它会逐项写回去。
|
|
26
|
+
|
|
27
|
+
3. **确认生效**。`dsh-memory doctor` 做一次环境体检(脚手架 / 孤儿页 / git 状态 / boot 预算),最后给出修复每一条的命令。或者打开**设置 → 记忆**看健康看板,选项都能热改。
|
|
28
|
+
|
|
29
|
+
之后就很简单了:你干活时 agent 顺手把记忆写回去;你随时能手动整理记忆库——纯 markdown + git,没有任何锁死的东西。
|
|
30
|
+
|
|
16
31
|
## 特性
|
|
17
32
|
|
|
18
33
|
- **开机强制注入(带路由表保护)**:插件通过 `ctx.systemPrompt.context()` 把记忆 boot 块(`SOUL.md` 人格 + `MEMORY.md` 协议 + `index.md` 目录 + 最近动态)注入会话上下文。宿主按投影去重:记忆不变就不重复注入,变化时新快照自动取代旧的——这是"新会话必先加载记忆"的**硬保障**,不需要模型碰运气调技能。总预算是 `bootMaxChars`,**按文件分配**:每个文件先拿一份均分(受实际大小封顶),剩余额度优先给 `index.md`、再给尚有内容未注入的文件——所以记忆库长大时,目录的尾部不会先被截掉(详见「boot 预算分配」)。默认还带**两道礼貌闸门**:`deferUntilUserSpeaks`(用户开口后才注入)与 `activeSessionOnly`(只注入当前激活会话),见「配置」。
|
|
@@ -179,6 +194,7 @@ dsh-memory query --type decision --tag dsh --hot --stale [关键词]
|
|
|
179
194
|
# 结构化检索:先按 frontmatter 过滤,再匹配正文
|
|
180
195
|
dsh-memory checkup [--boot=N] # 一份报告:体量/新鲜度/连接度/一致性 + 优先级行动清单
|
|
181
196
|
dsh-memory lint # 完整性体检
|
|
197
|
+
dsh-memory doctor # 环境体检:脚手架 / 孤儿页 / git / boot 预算,并给出修复命令
|
|
182
198
|
dsh-memory status # 健康概览(含陈旧页统计)
|
|
183
199
|
dsh-memory pack [out.tar.gz] # 打包导出(含 manifest)
|
|
184
200
|
dsh-memory unpack <archive> [--force] # 从归档恢复
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-memory",
|
|
3
3
|
"description": "Long-term memory plugin for DeepSeek Harness: persistent cross-session markdown memory with a soul/persona file, auto-injected at every session start, plus remember/recall/consolidate/forget workflows and portable migration tooling.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
package/scripts/memory.mjs
CHANGED
|
@@ -361,6 +361,151 @@ function cmdStatus(store) {
|
|
|
361
361
|
console.log(`oldest last_access: ${oldest}`)
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
/**
|
|
365
|
+
* `doctor` — the command to run when something feels off.
|
|
366
|
+
*
|
|
367
|
+
* It checks what actually breaks in practice — the scaffold, orphan pages,
|
|
368
|
+
* dead index links, git state, boot budget, staleness — and ends with the
|
|
369
|
+
* command that repairs each finding. Any hard failure exits 1; warnings
|
|
370
|
+
* alone keep the exit at 0, so `doctor` can gate a CI step.
|
|
371
|
+
*/
|
|
372
|
+
function cmdDoctor(store) {
|
|
373
|
+
const failures = []
|
|
374
|
+
const warnings = []
|
|
375
|
+
const fixes = []
|
|
376
|
+
const row = (mark, text) => console.log(` ${mark} ${text}`)
|
|
377
|
+
|
|
378
|
+
console.log('dsh-memory doctor')
|
|
379
|
+
console.log(`记忆库:${store}`)
|
|
380
|
+
console.log('')
|
|
381
|
+
|
|
382
|
+
if (!existsSync(store)) {
|
|
383
|
+
row('✗', '目录不存在')
|
|
384
|
+
console.log('\n建议:')
|
|
385
|
+
console.log(` dsh-memory init ${store}`)
|
|
386
|
+
process.exit(1)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// 1. writability — probe with a real write, because mode bits lie under ACLs
|
|
390
|
+
let writable = true
|
|
391
|
+
const probe = join(store, '.doctor-probe')
|
|
392
|
+
try {
|
|
393
|
+
writeFileSync(probe, '')
|
|
394
|
+
rmSync(probe)
|
|
395
|
+
} catch {
|
|
396
|
+
writable = false
|
|
397
|
+
}
|
|
398
|
+
row(writable ? '✓' : '✗', `目录可写${writable ? '' : '(写不进去,插件无法维护记忆库)'}`)
|
|
399
|
+
if (!writable) {
|
|
400
|
+
failures.push('目录不可写')
|
|
401
|
+
fixes.push(`chmod u+w "${store}"`)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// 2. scaffold
|
|
405
|
+
const REQUIRED = ['SOUL.md', 'MEMORY.md', 'index.md', 'log.md', 'BOOTSTRAP.md']
|
|
406
|
+
const missing = REQUIRED.filter((f) => !existsSync(join(store, f)))
|
|
407
|
+
if (missing.length === 0) {
|
|
408
|
+
row('✓', '脚手架完整(SOUL / MEMORY / index / log / BOOTSTRAP)')
|
|
409
|
+
} else {
|
|
410
|
+
row('✗', `脚手架缺文件:${missing.join(' / ')}`)
|
|
411
|
+
failures.push('脚手架不完整')
|
|
412
|
+
fixes.push('dsh-memory init — 只补缺失的模板,不覆盖已有内容')
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// 3. pages, orphans and dead links
|
|
416
|
+
const all = pages(store)
|
|
417
|
+
const indexPath = join(store, 'index.md')
|
|
418
|
+
const indexText = existsSync(indexPath) ? readFileSync(indexPath, 'utf8') : ''
|
|
419
|
+
const linked = [...indexText.matchAll(/\]\(([^)]+\.md)\)/g)]
|
|
420
|
+
.map((m) => m[1])
|
|
421
|
+
.filter((p) => !p.startsWith('http'))
|
|
422
|
+
.map((p) => p.replace(/^\.\//, ''))
|
|
423
|
+
const inIndex = new Set(linked)
|
|
424
|
+
const orphans = all.filter((p) => !inIndex.has(p))
|
|
425
|
+
row('✓', `页面 ${all.length} 个,index 覆盖 ${linked.length} 条`)
|
|
426
|
+
if (orphans.length > 0) {
|
|
427
|
+
row('⚠', `孤儿页 ${orphans.length} 个(存在于记忆库但不在 index.md 里)`)
|
|
428
|
+
warnings.push(`${orphans.length} 个孤儿页`)
|
|
429
|
+
fixes.push('dsh-memory index --write — 把声明了 summary: 的页面写回索引行')
|
|
430
|
+
}
|
|
431
|
+
const dead = linked.filter((p) => !existsSync(join(store, p)))
|
|
432
|
+
if (dead.length > 0) {
|
|
433
|
+
row('✗', `index 里 ${dead.length} 条死链:${dead.slice(0, 3).join(', ')}${dead.length > 3 ? ' …' : ''}`)
|
|
434
|
+
failures.push('index 有死链')
|
|
435
|
+
fixes.push('dsh-memory lint — 列出全部死链后手工修')
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// 4. git — the store is worth versioning, and autoCommit silently no-ops without a repo
|
|
439
|
+
if (!existsSync(join(store, '.git'))) {
|
|
440
|
+
row('⚠', '不是 git 仓库(没有版本历史,插件的 autoCommit 会跳过)')
|
|
441
|
+
warnings.push('无 git 仓库')
|
|
442
|
+
fixes.push(`git -C "${store}" init && git -C "${store}" add -A && git -C "${store}" commit -m "init"`)
|
|
443
|
+
} else {
|
|
444
|
+
const git = (...a) => execFileSync('git', a, {
|
|
445
|
+
cwd: store, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
|
|
446
|
+
}).trim()
|
|
447
|
+
let branch = ''
|
|
448
|
+
let dirty = 0
|
|
449
|
+
let ahead = 0
|
|
450
|
+
let hasRemote = false
|
|
451
|
+
try {
|
|
452
|
+
branch = git('rev-parse', '--abbrev-ref', 'HEAD')
|
|
453
|
+
dirty = git('status', '--porcelain').split('\n').filter(Boolean).length
|
|
454
|
+
hasRemote = git('remote').length > 0
|
|
455
|
+
if (hasRemote) {
|
|
456
|
+
const counts = git('rev-list', '--count', '--left-right', '@{upstream}...HEAD').split(/\s+/)
|
|
457
|
+
ahead = Number(counts[1] ?? 0)
|
|
458
|
+
}
|
|
459
|
+
} catch {
|
|
460
|
+
// an empty repo or a missing upstream lands here; the rows below cover both
|
|
461
|
+
}
|
|
462
|
+
row('✓', `git 仓库(分支 ${branch || '(尚无提交)'}${hasRemote ? '' : ',未配远端'})`)
|
|
463
|
+
if (dirty > 0) {
|
|
464
|
+
row('⚠', `${dirty} 个文件未提交(autoCommit 静默后会自行提交)`)
|
|
465
|
+
warnings.push(`${dirty} 个未提交文件`)
|
|
466
|
+
}
|
|
467
|
+
if (hasRemote && ahead > 0) {
|
|
468
|
+
row('⚠', `领先远端 ${ahead} 个提交(本地有历史没推上去)`)
|
|
469
|
+
warnings.push(`${ahead} 个提交未推送`)
|
|
470
|
+
fixes.push(`git -C "${store}" push — 记忆插件只 auto-commit,从不 auto-push`)
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// 5. boot budget — best effort: the CLI cannot see the plugin's composition config
|
|
475
|
+
const BOOT_FILES = ['SOUL.md', 'MEMORY.md', 'index.md']
|
|
476
|
+
const DEFAULT_BUDGET = 12000
|
|
477
|
+
const bootChars = BOOT_FILES.reduce((n, f) => {
|
|
478
|
+
const p = join(store, f)
|
|
479
|
+
return n + (existsSync(p) ? readFileSync(p, 'utf8').length : 0)
|
|
480
|
+
}, 0)
|
|
481
|
+
const pct = Math.round((bootChars / DEFAULT_BUDGET) * 100)
|
|
482
|
+
row(pct > 100 ? '⚠' : '✓', `boot 预算 ${bootChars} / ${DEFAULT_BUDGET} 字符(${pct}%;按默认值算,实际以插件配置为准)`)
|
|
483
|
+
if (pct > 100) {
|
|
484
|
+
warnings.push('boot 预算超出默认值')
|
|
485
|
+
fixes.push('dsh-memory checkup --boot=12000 — 看该裁哪个文件')
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// 6. staleness, reusing the same source as `status`
|
|
489
|
+
const access = accessSummary(store)
|
|
490
|
+
if (access.total > 0 && access.stale.length > 0) {
|
|
491
|
+
row('⚠', `陈旧页 ${access.stale.length}/${access.total}(>90 天或从未戳记)`)
|
|
492
|
+
warnings.push(`${access.stale.length} 个陈旧页`)
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
console.log('')
|
|
496
|
+
if (failures.length === 0 && warnings.length === 0) {
|
|
497
|
+
console.log('一切正常 ✅')
|
|
498
|
+
process.exit(0)
|
|
499
|
+
}
|
|
500
|
+
if (fixes.length > 0) {
|
|
501
|
+
console.log('建议:')
|
|
502
|
+
for (const f of fixes) console.log(` - ${f}`)
|
|
503
|
+
console.log('')
|
|
504
|
+
}
|
|
505
|
+
console.log(`结论:${failures.length} 项失败,${warnings.length} 项提醒`)
|
|
506
|
+
process.exit(failures.length > 0 ? 1 : 0)
|
|
507
|
+
}
|
|
508
|
+
|
|
364
509
|
function manifestFor(storePath) {
|
|
365
510
|
const files = walk(storePath).sort().map((f) => ({
|
|
366
511
|
path: relative(storePath, f),
|
|
@@ -467,6 +612,7 @@ if (args[0] === '--self-test') {
|
|
|
467
612
|
index [--check|--write|--sync-frontmatter]
|
|
468
613
|
index routing table: report drift / rewrite / import summaries
|
|
469
614
|
lint integrity check
|
|
615
|
+
doctor environment check-up: scaffold, orphans, git, boot budget + fixes
|
|
470
616
|
status health summary
|
|
471
617
|
pack [out.tar.gz] export portable archive + manifest
|
|
472
618
|
unpack <archive> [--force] restore archive
|
|
@@ -480,6 +626,7 @@ Store: $MEMORY_DIR or ./.memory or ~/.memory (current: ${store})`
|
|
|
480
626
|
case 'query': cmdQuery(store, args.slice(1)); break
|
|
481
627
|
case 'index': cmdIndex(store, args.slice(1)); break
|
|
482
628
|
case 'lint': cmdLint(store); break
|
|
629
|
+
case 'doctor': cmdDoctor(store); break
|
|
483
630
|
case 'status': cmdStatus(store); break
|
|
484
631
|
case 'pack': cmdPack(store, args[1]); break
|
|
485
632
|
case 'unpack': cmdUnpack(store, args[1], args.includes('--force')); break
|