dsh-cross-memory 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +253 -2
- package/cordis.patch.yml +27 -0
- package/docs/DETAIL.md +13 -0
- package/docs/DETAIL.zh.md +17 -0
- package/icon.svg +1 -0
- package/lib/backfill.js +273 -0
- package/lib/citations.js +305 -0
- package/lib/client.js +1660 -0
- package/lib/config.js +736 -0
- package/lib/consolidate.js +1119 -0
- package/lib/extract.js +570 -0
- package/lib/gate.js +137 -0
- package/lib/git-origin.js +224 -0
- package/lib/index.js +4482 -0
- package/lib/log.js +260 -0
- package/lib/loops.js +186 -0
- package/lib/notices.js +195 -0
- package/lib/notify.js +33 -0
- package/lib/persona.js +163 -0
- package/lib/query.js +93 -0
- package/lib/raw-recall.js +286 -0
- package/lib/reflection.js +291 -0
- package/lib/remote.js +490 -0
- package/lib/render.js +678 -0
- package/lib/retention.js +64 -0
- package/lib/schedule.js +245 -0
- package/lib/search.js +1068 -0
- package/lib/skills.js +220 -0
- package/lib/state.js +701 -0
- package/lib/storage.js +1424 -0
- package/lib/sync-runtime.js +268 -0
- package/lib/sync.js +620 -0
- package/lib/test/activity.test.js +74 -0
- package/lib/test/archive.test.js +182 -0
- package/lib/test/backfill.test.js +144 -0
- package/lib/test/citations.test.js +91 -0
- package/lib/test/client-wiring.test.js +134 -0
- package/lib/test/consolidate-job.test.js +95 -0
- package/lib/test/consolidate.test.js +430 -0
- package/lib/test/consolidation-selection.test.js +152 -0
- package/lib/test/dedupe-keys.test.js +230 -0
- package/lib/test/delta.test.js +93 -0
- package/lib/test/derived.test.js +110 -0
- package/lib/test/disputes-panel.test.js +341 -0
- package/lib/test/eval.test.js +171 -0
- package/lib/test/expand.test.js +164 -0
- package/lib/test/extract.test.js +1020 -0
- package/lib/test/git-origin.test.js +189 -0
- package/lib/test/injection.test.js +440 -0
- package/lib/test/kind-filter.test.js +49 -0
- package/lib/test/legacy-state.test.js +69 -0
- package/lib/test/log.test.js +156 -0
- package/lib/test/loops.test.js +86 -0
- package/lib/test/memory.test.js +855 -0
- package/lib/test/notices.test.js +142 -0
- package/lib/test/persona.test.js +86 -0
- package/lib/test/prefilter.test.js +73 -0
- package/lib/test/preset.test.js +77 -0
- package/lib/test/raw-recall.test.js +186 -0
- package/lib/test/recall.test.js +433 -0
- package/lib/test/reflection.test.js +64 -0
- package/lib/test/remote.test.js +238 -0
- package/lib/test/retention.test.js +117 -0
- package/lib/test/retrieval.test.js +142 -0
- package/lib/test/rotation.test.js +228 -0
- package/lib/test/schedule.test.js +112 -0
- package/lib/test/settings-card.test.js +58 -0
- package/lib/test/skills.test.js +129 -0
- package/lib/test/state.test.js +212 -0
- package/lib/test/subagent-contract.test.js +139 -0
- package/lib/test/sweep.test.js +159 -0
- package/lib/test/sync.test.js +314 -0
- package/lib/test/time.test.js +171 -0
- package/lib/time.js +303 -0
- package/lib/tool.js +330 -0
- package/lib/types/backfill.d.ts +96 -0
- package/lib/types/citations.d.ts +105 -0
- package/lib/types/config.d.ts +811 -0
- package/lib/types/consolidate.d.ts +742 -0
- package/lib/types/extract.d.ts +352 -0
- package/lib/types/gate.d.ts +83 -0
- package/lib/types/git-origin.d.ts +23 -0
- package/lib/types/index.d.ts +1316 -0
- package/lib/types/log.d.ts +144 -0
- package/lib/types/loops.d.ts +82 -0
- package/lib/types/notices.d.ts +117 -0
- package/lib/types/notify.d.ts +12 -0
- package/lib/types/persona.d.ts +76 -0
- package/lib/types/query.d.ts +45 -0
- package/lib/types/raw-recall.d.ts +84 -0
- package/lib/types/reflection.d.ts +122 -0
- package/lib/types/remote.d.ts +246 -0
- package/lib/types/render.d.ts +286 -0
- package/lib/types/retention.d.ts +66 -0
- package/lib/types/schedule.d.ts +116 -0
- package/lib/types/search.d.ts +583 -0
- package/lib/types/skills.d.ts +71 -0
- package/lib/types/state.d.ts +294 -0
- package/lib/types/storage.d.ts +458 -0
- package/lib/types/sync-runtime.d.ts +103 -0
- package/lib/types/sync.d.ts +222 -0
- package/lib/types/test/activity.test.d.ts +1 -0
- package/lib/types/test/archive.test.d.ts +1 -0
- package/lib/types/test/backfill.test.d.ts +1 -0
- package/lib/types/test/citations.test.d.ts +1 -0
- package/lib/types/test/client-wiring.test.d.ts +1 -0
- package/lib/types/test/consolidate-job.test.d.ts +1 -0
- package/lib/types/test/consolidate.test.d.ts +1 -0
- package/lib/types/test/consolidation-selection.test.d.ts +1 -0
- package/lib/types/test/dedupe-keys.test.d.ts +1 -0
- package/lib/types/test/delta.test.d.ts +1 -0
- package/lib/types/test/derived.test.d.ts +1 -0
- package/lib/types/test/disputes-panel.test.d.ts +1 -0
- package/lib/types/test/eval.test.d.ts +1 -0
- package/lib/types/test/expand.test.d.ts +1 -0
- package/lib/types/test/extract.test.d.ts +1 -0
- package/lib/types/test/git-origin.test.d.ts +1 -0
- package/lib/types/test/injection.test.d.ts +1 -0
- package/lib/types/test/kind-filter.test.d.ts +1 -0
- package/lib/types/test/legacy-state.test.d.ts +1 -0
- package/lib/types/test/log.test.d.ts +1 -0
- package/lib/types/test/loops.test.d.ts +1 -0
- package/lib/types/test/memory.test.d.ts +1 -0
- package/lib/types/test/notices.test.d.ts +1 -0
- package/lib/types/test/persona.test.d.ts +1 -0
- package/lib/types/test/prefilter.test.d.ts +1 -0
- package/lib/types/test/preset.test.d.ts +1 -0
- package/lib/types/test/raw-recall.test.d.ts +1 -0
- package/lib/types/test/recall.test.d.ts +1 -0
- package/lib/types/test/reflection.test.d.ts +1 -0
- package/lib/types/test/remote.test.d.ts +1 -0
- package/lib/types/test/retention.test.d.ts +1 -0
- package/lib/types/test/retrieval.test.d.ts +1 -0
- package/lib/types/test/rotation.test.d.ts +1 -0
- package/lib/types/test/schedule.test.d.ts +1 -0
- package/lib/types/test/settings-card.test.d.ts +1 -0
- package/lib/types/test/skills.test.d.ts +1 -0
- package/lib/types/test/state.test.d.ts +1 -0
- package/lib/types/test/subagent-contract.test.d.ts +1 -0
- package/lib/types/test/sweep.test.d.ts +1 -0
- package/lib/types/test/sync.test.d.ts +1 -0
- package/lib/types/test/time.test.d.ts +1 -0
- package/lib/types/time.d.ts +67 -0
- package/lib/types/tool.d.ts +9 -0
- package/lib/types/types.d.ts +374 -0
- package/lib/types/workspace.d.ts +20 -0
- package/lib/types.js +47 -0
- package/lib/workspace.js +65 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +126 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cooper Zhuang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,254 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-cross-memory
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)的**跨会话记忆**插件:
|
|
4
|
+
把会话里值得长期保留的内容抽取成条目,按作用域存进本机记忆库,在后续会话里按需注入。
|
|
5
|
+
|
|
6
|
+
- **两种作用域**:`global`(所有项目共享)与 `project`(按工作区隔离)。
|
|
7
|
+
- **三条协同路径**:模型可调用的 `memory` 工具、空闲时的后台抽取、有界的摘要注入与按需召回。
|
|
8
|
+
- **只写本机**:记忆库默认在 `$DSH_HOME/memories`,不上传任何服务;多机同步需要你自己配置一个 Git 仓库。
|
|
9
|
+
- **可审计**:每条记忆带来源、时间与(自动抽取时的)会话证据;归档可恢复,不静默删除。
|
|
10
|
+
|
|
11
|
+
## 功能
|
|
12
|
+
|
|
13
|
+
| 能力 | 说明 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| 显式写入 | 模型调用 `memory` 工具写入/更新/检索/读取/遗忘;标题即身份,同名再写是更新。 |
|
|
16
|
+
| 后台抽取 | 会话空闲或按周期被扫描,用一次辅助模型调用抽取可复用的事实;落盘前做密钥擦除。 |
|
|
17
|
+
| 合并重整 | 受限子代理对一批记忆去重、改写、退役;有风险的决定进入「待裁决」由你决定。 |
|
|
18
|
+
| 分层注入 | 每个会话注入一次有界摘要;另有按需补注(当前这轮明显相关时)、标题轮转与增量块。 |
|
|
19
|
+
| 按需召回 | 关键词 + 时间衰减 + 一跳扩展;命中原因可在日志里核对。 |
|
|
20
|
+
| 原始片段(可选) | 补注块可附带来源会话的原文片段,默认关闭,因为它会把别的会话的原文带进当前上下文。 |
|
|
21
|
+
| persona | 维护「这个人是谁」的画像(`persona/human.md`),注入在记忆摘要之前,默认预算 12000 字节;设置 → 记忆 → 画像 可查看/编辑,并可锁定不让后台改写。 |
|
|
22
|
+
| 开放承诺 | 把会话里答应过、但还没到期/没做的事记成台账,到期未闭环会提醒。 |
|
|
23
|
+
| 反思与技能草稿 | 每周从记忆里提炼跨项目观察(必须引用来源记忆);可把重复流程提成技能草稿,需你手动晋升。 |
|
|
24
|
+
| GUI | 设置 → 记忆:浏览/搜索/新增/删除、**画像查看/编辑与锁定**、配置项、待裁决;插件页该包下也有同一张配置卡。 |
|
|
25
|
+
|
|
26
|
+
### Persona 画像
|
|
27
|
+
|
|
28
|
+
- **在哪看**:画像是记忆库里的 `persona/human.md`(旧的单文件 `persona.md` 仍兼容读取)。每次会话开始时它被包进 `<persona>…snapshot 日期…</persona>`,注入在记忆摘要之前;超过 `personaMaxBytes`(默认 **12000**,0 关闭)的部分按行截断。
|
|
29
|
+
- **怎么编辑**:**设置 → 记忆 → 画像**,改完点「保存画像」即写回,不经过后台合并,不用重启宿主。
|
|
30
|
+
- **锁定**:同一页勾选「锁定画像」会在画像旁边写 `persona/human.lock`;锁定后后台 consolidation 即使提出画像改写也会跳过(日志会记 `persona is locked; the automatic profile update was skipped`),只有你手动保存才会改变它。取消勾选即解除。
|
|
31
|
+
|
|
32
|
+
更细的设计说明见 [`docs/DETAIL.zh.md`](docs/DETAIL.zh.md)(英文版 [`docs/DETAIL.md`](docs/DETAIL.md))。
|
|
33
|
+
|
|
34
|
+
## 安装
|
|
35
|
+
|
|
36
|
+
包是标准 DSH profile bundle,用 `dsh plugin` 装进目标 profile:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# 从 npm 安装
|
|
40
|
+
dsh plugin --profile <profile> add dsh-cross-memory
|
|
41
|
+
|
|
42
|
+
# 从本地检出安装(路径按你的实际位置)
|
|
43
|
+
dsh plugin --profile <profile> add /path/to/packages/dsh-cross-memory
|
|
44
|
+
|
|
45
|
+
# 从 GitHub 安装
|
|
46
|
+
dsh plugin --profile <profile> add github:<you>/dsh-cross-memory
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
安装后**重启该 profile 的进程**(`dsh web` 这类长驻进程不会热加载新 bundle)。
|
|
50
|
+
`dsh --profile <profile> --dump-config` 里应能看到下面这一行:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
- id: memories # 插件在 profile 里的固定 id,设置页与配置项都按它寻址
|
|
54
|
+
name: dsh-cross-memory
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> 插件在组合里的 id 始终是 `memories`,与包名无关。从旧包名迁移时,删掉旧的插件行、按新包名重装即可;
|
|
58
|
+
> 记忆数据目录不变。
|
|
59
|
+
>
|
|
60
|
+
> `lib/` 是构建产物、不入库。从 git 安装时 `prepare` 钩子会就地构建一次
|
|
61
|
+
> (`npm run build`);pnpm 默认拦截安装脚本,按它打印的 key 加进 `allowBuilds` 后重跑即可。
|
|
62
|
+
> 从本地路径安装或从 npm 安装不需要这一步。
|
|
63
|
+
|
|
64
|
+
## 快速上手
|
|
65
|
+
|
|
66
|
+
1. 在一个会话里说一句值得记住的事,然后:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
/memories mine # 立刻从当前会话抽取一次
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
2. 打开 **设置 → 记忆** 查看条目;或让模型直接调用 `memory` 工具:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
memory write scope=global title="Prefer pnpm over npm" body="..." kind=preference
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
3. 下一个会话开始时,摘要会自动注入;之后可用 `memory search` 或 `/memories search <query>` 检索细节。
|
|
79
|
+
|
|
80
|
+
## 配置
|
|
81
|
+
|
|
82
|
+
配置分两层,都在插件那一行的 `config` 下。
|
|
83
|
+
|
|
84
|
+
**部署层**(改完需要重挂这一行):
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
- id: memories
|
|
88
|
+
config:
|
|
89
|
+
memoriesDir: /custom/path # 默认 $DSH_HOME/memories
|
|
90
|
+
logFile: '' # 默认 $DSH_HOME/logs/dsh-cross-memory.log;空串关闭文件日志
|
|
91
|
+
projectRootMarkers: ['.git'] # 向上找工作区根的标记
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**可调项**(`.volatile()` 字段):修改后立即生效,不需要重启,也不会重挂插件实例。
|
|
95
|
+
可以在设置 → 记忆 → 配置里改,也可以直接改当前 profile 的 patch。共 60 多项,常见项如下:
|
|
96
|
+
|
|
97
|
+
| 键 | 默认 | 说明 |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| `maxSummaryBytes` | `4096` | 每会话注入摘要的总字节预算;`0` 关闭注入,只留工具 |
|
|
100
|
+
| `maxSummaryEntries` | `12` | 每个作用域最多列出几条 |
|
|
101
|
+
| `globalSummaryEntries` | `4` | 全局段最多列几条(两作用域共用总预算,全局段先渲染) |
|
|
102
|
+
| `globalSummaryBytes` | `1200` | 全局段单独占的字节预算;`0` 不注入全局段 |
|
|
103
|
+
| `summaryFreshSlots` | `3` | 每作用域预留几个名额给从未出现过的记忆,避免老条目长期占位 |
|
|
104
|
+
| `recallMode` | `on-demand` | `once` 只注一次摘要 / `on-demand` 额外按需补注 / `off` 只用工具 |
|
|
105
|
+
| `recallMinScore` | `9` | 按需补注的相关度下限(严格度旋钮) |
|
|
106
|
+
| `recallMinTerms` | `2` | 补注所需的实词数,防止只共享一个常见词就触发 |
|
|
107
|
+
| `recallMaxPerConversation` | `4` | 一个会话最多按需补注多少条记忆;`0` 关闭 |
|
|
108
|
+
| `rawRecall` | `false` | 补注块是否附带来源会话的原文片段(默认关闭) |
|
|
109
|
+
| `maxEntriesPerScope` | `1000` | 每作用域保留上限,超出后归档最久未用的 |
|
|
110
|
+
| `maxUnusedDays` | `90` | 多久没用就归档;`0` 关闭 |
|
|
111
|
+
| `snapshotMaxAgeDays` | `60` | `durability: snapshot` 条目的过期天数;`0` 关闭 |
|
|
112
|
+
| `sweepIntervalHours` | `12` | 定期整理间隔;`0` 关闭 |
|
|
113
|
+
| `autoExtract` | `true` | 是否启用空闲后台抽取 |
|
|
114
|
+
| `autoExtractIdleMs` | `300000` | 空闲多久后触发一次抽取 |
|
|
115
|
+
| `extractIntervalMinutes` | `30` | 周期性抽取间隔;`0` 关闭周期检查 |
|
|
116
|
+
| `minIdleHours` | `6` | 会话至少空闲多久才可被抽取 |
|
|
117
|
+
| `maxAgeDays` | `10` | 超过这么多天没活动的会话不再抽取 |
|
|
118
|
+
| `consolidate` | `true` | 是否启用合并重整 |
|
|
119
|
+
| `consolidateCooldownHours` | `6` | 两次合并之间的最小间隔 |
|
|
120
|
+
| `autoDecide` | `true` | 允许 AI 裁决本会排队等你的合并决定 |
|
|
121
|
+
| `syncRemote` | 空 | 记忆库同步用的 Git remote;空 = 只在本机提交 |
|
|
122
|
+
| `syncClock` | `12:05,18:05` | 定时同步的本地时刻;空则回退到 `syncIntervalMinutes` |
|
|
123
|
+
| `syncIntervalMinutes` | `10` | 后台同步间隔;`0` 关闭定时器 |
|
|
124
|
+
| `extractProvider` / `extractModel` | 空 | 抽取调用的模型路由;空则沿用会话路由 |
|
|
125
|
+
| `logLevel` | `info` | 插件日志详细程度:`off`/`error`/`warn`/`info`/`debug` |
|
|
126
|
+
|
|
127
|
+
完整字段与逐项说明以设置页「配置」标签为准(也可 `dsh --profile <profile> --dump-config`)。
|
|
128
|
+
|
|
129
|
+
## `memory` 工具
|
|
130
|
+
|
|
131
|
+
| action | 参数 | 作用 |
|
|
132
|
+
| --- | --- | --- |
|
|
133
|
+
| `write` | `scope` + `title` + `body` + `tags?` + `kind?` + `appliesTo?` | 写入或更新一条记忆 |
|
|
134
|
+
| `search` | `query?` + `scope?` + `tags?` + `limit?` | 检索;`query` 为空时按最近更新列出 |
|
|
135
|
+
| `read` | `id` + `scope?` | 读全文(默认先项目、后全局) |
|
|
136
|
+
| `forget` | `id` + `scope?` | 删除一条 |
|
|
137
|
+
| `evidence` | `id` 或 `evidenceSession` | 读这条记忆背后的会话证据笔记与逐字引文 |
|
|
138
|
+
|
|
139
|
+
`kind` 取值:`fact` / `preference` / `knowledge` / `failure` / `procedure`。
|
|
140
|
+
|
|
141
|
+
## `/memories` 命令
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
/memories 列出两个作用域
|
|
145
|
+
/memories list global|project 只列某一作用域
|
|
146
|
+
/memories search <query> 检索(可加 --kind <kind>)
|
|
147
|
+
/memories show <id> 看全文
|
|
148
|
+
/memories add <global|project> <text> 手工写入
|
|
149
|
+
/memories forget <id> 删除
|
|
150
|
+
/memories archive [global|project] 列出已归档
|
|
151
|
+
/memories restore <id> 从归档取回
|
|
152
|
+
/memories mode [on|off] 本次会话临时关闭/开启记忆
|
|
153
|
+
/memories mine 立刻从当前会话抽取一次
|
|
154
|
+
/memories backfill [--apply] 回填本进程没见过的历史会话(默认只估算)
|
|
155
|
+
/memories consolidate 立刻跑一次合并
|
|
156
|
+
/memories plan / apply / reject 查看与裁决待处理合并
|
|
157
|
+
/memories sweep 立刻跑一次保留整理
|
|
158
|
+
/memories stale 列出引用了已不存在文件的记忆
|
|
159
|
+
/memories skills / promote <name> / discard <name> 技能草稿管理
|
|
160
|
+
/memories stats 存储位置与计数
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 数据存储
|
|
164
|
+
|
|
165
|
+
记忆库默认在 `$DSH_HOME/memories`(`$DSH_HOME` 未设置时为 `~/.dsh`)。条目是人类可读的
|
|
166
|
+
Markdown + 简单 frontmatter,**文件是唯一真相**;水位线、任务租约、用量计数等状态放在同目录的
|
|
167
|
+
SQLite(`state.db`,Node 内置 `node:sqlite`,无外部依赖):
|
|
168
|
+
|
|
169
|
+
```text
|
|
170
|
+
$DSH_HOME/memories/
|
|
171
|
+
├── index.json # 可重建的索引缓存
|
|
172
|
+
├── entries/<id>.md # 每条全局记忆一个文件
|
|
173
|
+
├── archive/<id>.md # 归档的全局记忆(可恢复)
|
|
174
|
+
├── projects/<slug>/
|
|
175
|
+
│ ├── project.json # slug 与根路径映射
|
|
176
|
+
│ ├── hosts/ # 用过这个项目的机器
|
|
177
|
+
│ ├── entries/<id>.md
|
|
178
|
+
│ └── archive/<id>.md
|
|
179
|
+
├── sessions/<session-id>.md # 证据笔记(被挖掘过的会话)
|
|
180
|
+
├── skills/<name>/SKILL.md # 技能草稿(未晋升前 DSH 看不到)
|
|
181
|
+
├── persona/ # persona 画像(human.md;human.lock 存在表示已锁定)
|
|
182
|
+
├── reflections/ # 每周反思
|
|
183
|
+
└── state.db # SQLite 状态
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
插件自己的日志默认写在 `$DSH_HOME/logs/dsh-cross-memory.log`,单文件 2 MB 轮转一代。
|
|
187
|
+
`npm run report` 可以把日志汇总成一份可读摘要。
|
|
188
|
+
|
|
189
|
+
## 隐私边界
|
|
190
|
+
|
|
191
|
+
- **默认不联网**。记忆只写在 `$DSH_HOME` 下,不往你的工作区仓库写文件;Git 同步默认关闭。
|
|
192
|
+
- **后台模型调用**会经过你配置的模型路由(默认沿用会话自己的路由)。抽取输入是会话尾部,
|
|
193
|
+
只取用户与助手正文,丢弃工具结果和插件注入的内容,避免记忆自噬;落盘前做密钥擦除
|
|
194
|
+
(`sk-…`、`ghp_…`、`AKIA…`、JWT、私钥块、`api_key=…`、`Bearer …` 等)。
|
|
195
|
+
- **注入的内容是背景数据,不是指令**:注入块会明确告诉模型,记忆记录的是写入时的事实,
|
|
196
|
+
不一定现在仍成立。
|
|
197
|
+
- **原始片段是 opt-in**:`rawRecall` 默认关闭;打开后补注块会附带来源会话的原文(只读本机会话日志)。
|
|
198
|
+
- **通知可选**:默认通过操作系统通知提醒(每日摘要、积压警告、到期承诺),
|
|
199
|
+
`noticeQuietHours` 可设置静默时段,`noticesEnabled: false` 完全关闭。
|
|
200
|
+
- **彻底关掉后台行为**:`autoExtract: false`、`consolidate: false`、`reflectionEnabled: false`;
|
|
201
|
+
再设 `maxSummaryBytes: 0` 或 `recallMode: off` 就只剩 `memory` 工具与 `/memories` 命令。
|
|
202
|
+
- 归档与合并只动 `$DSH_HOME` 下的文件;归档条目可 `restore`,合并失败的改动会回滚。
|
|
203
|
+
|
|
204
|
+
## 多机同步(Git)
|
|
205
|
+
|
|
206
|
+
记忆库本身就是一个 Git 工作副本。把 `syncRemote` 指向**你自己创建的私有仓库**,多台机器就会共用同一份记忆:
|
|
207
|
+
|
|
208
|
+
```yaml
|
|
209
|
+
- id: memories
|
|
210
|
+
config:
|
|
211
|
+
syncRemote: https://github.com/<you>/dsh-cross-memory-store.git
|
|
212
|
+
# 或 git@github.com:<you>/dsh-cross-memory-store.git
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
- 写入路径只做**本地提交**(`syncDebounceSeconds` 默认 2 秒合并一次);拉取与推送在后台定时进行。
|
|
216
|
+
- 默认同步时刻 `syncClock: 12:05,18:05`(DeepSeek 谷时开始后几分钟,冲突合并成本最低);
|
|
217
|
+
留空则按 `syncIntervalMinutes`(默认 10 分钟);`0` 关闭定时器,只保留手动同步。
|
|
218
|
+
- 冲突处理:能安全合并的自动合并;可能丢信息的进入 **设置 → 记忆 → 待裁决**(或 `/memories plan`)。
|
|
219
|
+
`autoDecide` 开启时由 AI 先判断「这次改动是否丢信息」。
|
|
220
|
+
- **不入库**的状态:`state.db*`、各级 `index.json`、`pending/`、`project.json`、`*.log`。
|
|
221
|
+
- 同步仓库需要你自己创建并保护;插件不会替你创建远端,也不会向未配置的地址发送数据。
|
|
222
|
+
|
|
223
|
+
## 兼容性
|
|
224
|
+
|
|
225
|
+
| 依赖 | 区间 |
|
|
226
|
+
| --- | --- |
|
|
227
|
+
| DSH | `^0.2.1-rc.2 \|\| ^0.2.2-alpha.2` |
|
|
228
|
+
| Node.js | `>=24`(与 DSH 宿主自带运行时一致) |
|
|
229
|
+
| Cordis | `^4.0.5 \|\| ^4.0.6-alpha.1` |
|
|
230
|
+
| Schemastery | `^3.18.5 \|\| ^3.18.6-alpha.1` |
|
|
231
|
+
|
|
232
|
+
`@deepseek-ai/*` 均为 `peerDependencies`,由宿主提供,插件不另装内核包。
|
|
233
|
+
不同内核版本的子代理约定差异(预设路线 / 无预设直调 / 老内核黑名单路线)已在插件内适配。
|
|
234
|
+
|
|
235
|
+
## 开发
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
npm i # 或 pnpm i;prepare 钩子会构建一次
|
|
239
|
+
npm run typecheck # tsc --noEmit
|
|
240
|
+
npm run build # tsc + 客户端 bundle,产物在 lib/
|
|
241
|
+
npm test # 编译后跑 node --test
|
|
242
|
+
npm run smoke # 用真实 Cordis 根加载插件,检查注册结果
|
|
243
|
+
npm run report # 汇总插件日志
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
- `src/` 是 TypeScript 源码,`client/` 是浏览器半边(构建时拼成 `lib/client.js`),
|
|
247
|
+
`lib/` 是构建产物、不入库。
|
|
248
|
+
- `scripts/` 下有回填、检索评测、召回日志评测等运维与评测脚本;`bench/` 是基准与真实会话评测,
|
|
249
|
+
其数据与语料不入库。
|
|
250
|
+
- 改动宿主半边(`lib/*.js`)后需要重启 DSH 宿主才生效;只改浏览器半边刷新页面即可。
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
[MIT](LICENSE) © 2026 Cooper Zhuang
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# The dsh-cross-memory bundle patch: one row inserting the cross-session memory
|
|
2
|
+
# plugin over the profile root. Later bundle patches and the profile's own
|
|
3
|
+
# cordis.patch.yml address it by id (`memories`), with the last write winning.
|
|
4
|
+
#
|
|
5
|
+
# One row, two kinds of key. The keys below are composition facts; every
|
|
6
|
+
# behavioural knob is a live field of this same row — declared `.volatile()` in
|
|
7
|
+
# the plugin's Config, edited from the Memories page, and persisted into the
|
|
8
|
+
# active profile's Cordis patch:
|
|
9
|
+
#
|
|
10
|
+
# - id: memories
|
|
11
|
+
# config:
|
|
12
|
+
# autoExtract: false
|
|
13
|
+
# maxSummaryBytes: 8192
|
|
14
|
+
#
|
|
15
|
+
# This row carries deployment facts only — where the store lives and how a
|
|
16
|
+
# workspace root is recognised — because the profile patch is the layer above it
|
|
17
|
+
# and is where a user's own values belong.
|
|
18
|
+
|
|
19
|
+
- insert:
|
|
20
|
+
- id: memories
|
|
21
|
+
name: dsh-cross-memory
|
|
22
|
+
config:
|
|
23
|
+
# Directory holding every memory store. Defaults to $DSH_HOME/memories.
|
|
24
|
+
# memoriesDir: /custom/path
|
|
25
|
+
# Child names that mark a workspace root during the upward walk.
|
|
26
|
+
projectRootMarkers:
|
|
27
|
+
- .git
|
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Cross-memory
|
|
2
|
+
|
|
3
|
+
Extracts whatever is worth keeping (preferences, decisions, pitfalls, promises) into scoped memory entries and recalls the relevant ones into later sessions.
|
|
4
|
+
|
|
5
|
+
## Capabilities
|
|
6
|
+
- Extraction and consolidation passes with type, source and time on every entry.
|
|
7
|
+
- Recall ranked by relevance with time decay; hit reasons are inspectable.
|
|
8
|
+
- A Remote namespace (8 methods) for browsing and editing from settings.
|
|
9
|
+
- A tool-free memories-consolidator child preset for dedupe and merge.
|
|
10
|
+
|
|
11
|
+
## Notes
|
|
12
|
+
- Consolidation runs when the session is idle; /memories consolidate forces it.
|
|
13
|
+
- Entries are scoped per project; moving a session does not move memories automatically.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 跨记忆
|
|
2
|
+
|
|
3
|
+
把会话里值得长期保留的内容(偏好、决定、踩坑、承诺)抽取成条目,按项目/会话作用域存进记忆库;后续会话按相关度召回并注入上下文。
|
|
4
|
+
|
|
5
|
+
## 主要能力
|
|
6
|
+
- 抽取:按阶段对会话做抽取与合并,条目带类型、来源与时间。
|
|
7
|
+
- 召回:按语义相关度与时间衰减挑选条目注入,可查看命中原因。
|
|
8
|
+
- 远端命名空间:向浏览器暴露 8 个方法,设置页可浏览、编辑、归档条目。
|
|
9
|
+
- 合并子代理:memories-consolidator 预设,用无工具子代理做去重与合并。
|
|
10
|
+
|
|
11
|
+
## 常用入口
|
|
12
|
+
- 设置 → 记忆:浏览、搜索、归档、导入导出。
|
|
13
|
+
- /memories 命令:查看与整理记忆库状态。
|
|
14
|
+
|
|
15
|
+
## 注意
|
|
16
|
+
- 合并任务只在会话空闲时触发;需要立刻跑用 /memories consolidate。
|
|
17
|
+
- 记忆库按项目作用域分目录;搬会话不会自动带记忆条目(需要显式搬)。
|
package/icon.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="7" y="6" width="22" height="24" rx="4" fill="#3B82F6"/><path d="M13 11h10M13 16h10M13 21h6" stroke="#fff" stroke-width="2.2" stroke-linecap="round"/></svg>
|
package/lib/backfill.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Historical-session backfill.
|
|
3
|
+
*
|
|
4
|
+
* Extraction only ever reads sessions that are live in this process, so every
|
|
5
|
+
* conversation that ended before the plugin was installed stays unmined forever.
|
|
6
|
+
* This module turns the persisted session logs under `<dshHome>/sessions` back
|
|
7
|
+
* into extraction windows, without a host service and without replaying the
|
|
8
|
+
* conversation: it decodes the log's zstd frames, keeps the user/assistant prose
|
|
9
|
+
* the extractor wants, and cuts it into bounded windows.
|
|
10
|
+
*
|
|
11
|
+
* The caller owns the model call and the store write; everything here is pure
|
|
12
|
+
* parsing so it can be tested against fixture logs.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-cross-memory/backfill
|
|
15
|
+
*/
|
|
16
|
+
import { createHash } from 'node:crypto';
|
|
17
|
+
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
18
|
+
import { basename, dirname, join } from 'node:path';
|
|
19
|
+
import * as zlib from 'node:zlib';
|
|
20
|
+
/** zstd frame magic bytes; a session log is a concatenation of frames. */
|
|
21
|
+
const ZSTD_MAGIC = Buffer.from([0x28, 0xb5, 0x2f, 0xfd]);
|
|
22
|
+
/** A session log, whatever version suffix DSH gave it (`session.jsonl.zstd`, `session.v4.jsonl.zstd`). */
|
|
23
|
+
const SESSION_LOG = /^session.*\.jsonl\.zstd$/u;
|
|
24
|
+
/** Deepest directory nesting `findSessionLogs` walks. */
|
|
25
|
+
const MAX_LOG_DEPTH = 4;
|
|
26
|
+
/** Whether this Node build can decompress zstd at all. */
|
|
27
|
+
export function zstdAvailable() {
|
|
28
|
+
return typeof zlib.zstdDecompressSync === 'function';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Decompress one concatenated-frame session log.
|
|
32
|
+
*
|
|
33
|
+
* A session log is an append-only series of independent zstd frames, so a
|
|
34
|
+
* single-shot decode stops at the first frame and hides the conversation. Every
|
|
35
|
+
* frame boundary is decoded and joined; a candidate offset that is not a frame
|
|
36
|
+
* start simply fails to decode and is skipped.
|
|
37
|
+
*
|
|
38
|
+
* @param buffer - raw file bytes.
|
|
39
|
+
* @returns the joined log text.
|
|
40
|
+
* @throws when the Node build has no zstd support.
|
|
41
|
+
*/
|
|
42
|
+
export function decodeSessionLog(buffer) {
|
|
43
|
+
const decompress = zlib.zstdDecompressSync;
|
|
44
|
+
if (decompress === undefined)
|
|
45
|
+
throw new Error('backfill needs zstd support from Node.js 22.15 or newer');
|
|
46
|
+
const offsets = [];
|
|
47
|
+
let index = buffer.indexOf(ZSTD_MAGIC);
|
|
48
|
+
while (index >= 0) {
|
|
49
|
+
offsets.push(index);
|
|
50
|
+
index = buffer.indexOf(ZSTD_MAGIC, index + ZSTD_MAGIC.length);
|
|
51
|
+
}
|
|
52
|
+
const parts = [];
|
|
53
|
+
for (let frame = 0; frame < offsets.length; frame += 1) {
|
|
54
|
+
const start = offsets[frame];
|
|
55
|
+
if (start === undefined)
|
|
56
|
+
continue;
|
|
57
|
+
const end = offsets[frame + 1] ?? buffer.length;
|
|
58
|
+
try {
|
|
59
|
+
parts.push(decompress(buffer.subarray(start, end)).toString('utf8'));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Not a standalone frame boundary: skip it.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return parts.join('');
|
|
66
|
+
}
|
|
67
|
+
/** Join the text blocks of one message, ignoring reasoning and tool calls. */
|
|
68
|
+
function blockText(blocks) {
|
|
69
|
+
if (!Array.isArray(blocks))
|
|
70
|
+
return '';
|
|
71
|
+
const parts = [];
|
|
72
|
+
for (const block of blocks) {
|
|
73
|
+
if (typeof block !== 'object' || block === null)
|
|
74
|
+
continue;
|
|
75
|
+
const record = block;
|
|
76
|
+
if (record.type !== 'text' || typeof record.text !== 'string')
|
|
77
|
+
continue;
|
|
78
|
+
const text = record.text.replace(/\s+/gu, ' ').trim();
|
|
79
|
+
if (text.length > 0)
|
|
80
|
+
parts.push(text);
|
|
81
|
+
}
|
|
82
|
+
return parts.join(' ').trim();
|
|
83
|
+
}
|
|
84
|
+
/** A stable session id for a log whose header is missing or unreadable. */
|
|
85
|
+
function fallbackSessionId(file) {
|
|
86
|
+
const directory = basename(dirname(file));
|
|
87
|
+
if (directory.startsWith('session-'))
|
|
88
|
+
return directory;
|
|
89
|
+
return `session-backfill-${createHash('sha1').update(file).digest('hex').slice(0, 12)}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse one decoded session log.
|
|
93
|
+
*
|
|
94
|
+
* Only `user/message` events authored by the user and `assistant/message`
|
|
95
|
+
* events are kept: tool results are bulky and rarely the durable lesson, and
|
|
96
|
+
* plugin-authored user messages (a memory block, a recall delta) are skipped so
|
|
97
|
+
* backfill never feeds memory its own summaries.
|
|
98
|
+
*
|
|
99
|
+
* @param text - decoded log text (one JSON event per line).
|
|
100
|
+
* @param file - the log's path, used for a fallback session id.
|
|
101
|
+
* @param modifiedAt - the file's mtime, carried through for reporting.
|
|
102
|
+
* @returns the recovered session, or `undefined` when the log has no prose.
|
|
103
|
+
*/
|
|
104
|
+
export function parseSessionLog(text, file, modifiedAt) {
|
|
105
|
+
const messages = [];
|
|
106
|
+
let sessionId;
|
|
107
|
+
let cwd;
|
|
108
|
+
let route;
|
|
109
|
+
let maxSeq = 0;
|
|
110
|
+
for (const line of text.split('\n')) {
|
|
111
|
+
const trimmed = line.trim();
|
|
112
|
+
if (trimmed.length === 0)
|
|
113
|
+
continue;
|
|
114
|
+
let event;
|
|
115
|
+
try {
|
|
116
|
+
event = JSON.parse(trimmed);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (typeof event !== 'object' || event === null)
|
|
122
|
+
continue;
|
|
123
|
+
const seq = Number(event['seq'] ?? 0);
|
|
124
|
+
if (Number.isFinite(seq) && seq > maxSeq)
|
|
125
|
+
maxSeq = seq;
|
|
126
|
+
const type = event['type'];
|
|
127
|
+
if (type === 'session') {
|
|
128
|
+
if (typeof event['id'] === 'string' && event['id'].length > 0)
|
|
129
|
+
sessionId = event['id'];
|
|
130
|
+
if (typeof event['cwd'] === 'string' && event['cwd'].length > 0)
|
|
131
|
+
cwd = event['cwd'];
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (type === 'request/header' && route === undefined) {
|
|
135
|
+
const header = event['data']?.header;
|
|
136
|
+
const config = header?.config;
|
|
137
|
+
if (typeof config?.provider === 'string' && typeof config.model === 'string'
|
|
138
|
+
&& config.provider.length > 0 && config.model.length > 0) {
|
|
139
|
+
route = {
|
|
140
|
+
provider: config.provider,
|
|
141
|
+
model: config.model,
|
|
142
|
+
...typeof config.reasoningEffort === 'string' ? { reasoningEffort: config.reasoningEffort } : {},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (type !== 'user/message' && type !== 'assistant/message')
|
|
148
|
+
continue;
|
|
149
|
+
const data = event['data'];
|
|
150
|
+
if (type === 'user/message') {
|
|
151
|
+
// A memory block or a recall delta is a user message too; only prose the
|
|
152
|
+
// human wrote may be mined.
|
|
153
|
+
if (data?.source?.kind !== 'user')
|
|
154
|
+
continue;
|
|
155
|
+
const body = blockText(data?.content);
|
|
156
|
+
if (body.length === 0)
|
|
157
|
+
continue;
|
|
158
|
+
messages.push({ seq: Number.isFinite(seq) ? seq : 0, role: 'user', text: body });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const body = blockText(data?.message?.content);
|
|
162
|
+
if (body.length === 0)
|
|
163
|
+
continue;
|
|
164
|
+
messages.push({ seq: Number.isFinite(seq) ? seq : 0, role: 'assistant', text: body });
|
|
165
|
+
}
|
|
166
|
+
if (messages.length === 0)
|
|
167
|
+
return undefined;
|
|
168
|
+
return {
|
|
169
|
+
sessionId: sessionId ?? fallbackSessionId(file),
|
|
170
|
+
file,
|
|
171
|
+
modifiedAt,
|
|
172
|
+
...cwd === undefined ? {} : { cwd },
|
|
173
|
+
...route === undefined ? {} : { route },
|
|
174
|
+
messages,
|
|
175
|
+
maxSeq,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Cut a recovered transcript into bounded extraction windows.
|
|
180
|
+
*
|
|
181
|
+
* The message count and the character budget are separate limits on purpose:
|
|
182
|
+
* a few very long turns and many short ones are both real, and either alone
|
|
183
|
+
* produces a window the extractor cannot afford.
|
|
184
|
+
*
|
|
185
|
+
* @param messages - the recovered transcript, oldest first.
|
|
186
|
+
* @param maxMessages - model-facing message cap for one window.
|
|
187
|
+
* @param maxChars - character budget for one window.
|
|
188
|
+
* @returns the windows, in order.
|
|
189
|
+
*/
|
|
190
|
+
export function planWindows(messages, maxMessages, maxChars) {
|
|
191
|
+
const windows = [];
|
|
192
|
+
const messageCap = Math.max(1, Math.trunc(maxMessages));
|
|
193
|
+
const charCap = Math.max(200, Math.trunc(maxChars));
|
|
194
|
+
let current = [];
|
|
195
|
+
let cost = 0;
|
|
196
|
+
let firstSeq = 0;
|
|
197
|
+
let lastSeq = 0;
|
|
198
|
+
const flush = () => {
|
|
199
|
+
if (current.length === 0)
|
|
200
|
+
return;
|
|
201
|
+
windows.push({
|
|
202
|
+
text: current.map((entry) => entry.line).join('\n\n'),
|
|
203
|
+
firstSeq,
|
|
204
|
+
lastSeq,
|
|
205
|
+
messages: current.length,
|
|
206
|
+
sources: current.map((entry) => ({ seq: entry.seq, text: entry.text })),
|
|
207
|
+
});
|
|
208
|
+
current = [];
|
|
209
|
+
cost = 0;
|
|
210
|
+
};
|
|
211
|
+
for (const message of messages) {
|
|
212
|
+
const line = `${message.role === 'user' ? 'USER' : 'ASSISTANT'}: ${message.text}`;
|
|
213
|
+
const lineCost = line.length + (current.length === 0 ? 0 : 2);
|
|
214
|
+
if (current.length > 0 && (current.length >= messageCap || cost + lineCost > charCap))
|
|
215
|
+
flush();
|
|
216
|
+
if (current.length === 0)
|
|
217
|
+
firstSeq = message.seq;
|
|
218
|
+
current.push({ seq: message.seq, text: message.text, line });
|
|
219
|
+
lastSeq = message.seq;
|
|
220
|
+
cost += lineCost;
|
|
221
|
+
}
|
|
222
|
+
flush();
|
|
223
|
+
return windows;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Every persisted session log under one harness home's `sessions` directory.
|
|
227
|
+
*
|
|
228
|
+
* @param sessionsDir - absolute `<dshHome>/sessions` path.
|
|
229
|
+
* @returns log paths with their mtimes, newest first; unreadable directories are skipped.
|
|
230
|
+
*/
|
|
231
|
+
export async function findSessionLogs(sessionsDir) {
|
|
232
|
+
const found = [];
|
|
233
|
+
const walk = async (dir, depth) => {
|
|
234
|
+
if (depth > MAX_LOG_DEPTH)
|
|
235
|
+
return;
|
|
236
|
+
let entries;
|
|
237
|
+
try {
|
|
238
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
for (const entry of entries) {
|
|
244
|
+
const path = join(dir, entry.name);
|
|
245
|
+
if (entry.isDirectory()) {
|
|
246
|
+
await walk(path, depth + 1);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (!entry.isFile() || !SESSION_LOG.test(entry.name))
|
|
250
|
+
continue;
|
|
251
|
+
try {
|
|
252
|
+
const info = await stat(path);
|
|
253
|
+
found.push({ file: path, modifiedAt: info.mtimeMs });
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// A log that vanished between listing and stat is simply not there.
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
await walk(sessionsDir, 0);
|
|
261
|
+
return found.sort((left, right) => right.modifiedAt - left.modifiedAt);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Read and parse one log file in one step.
|
|
265
|
+
*
|
|
266
|
+
* @param file - absolute log path.
|
|
267
|
+
* @param modifiedAt - mtime the caller already observed.
|
|
268
|
+
* @returns the parsed session, or `undefined` when the log has no prose.
|
|
269
|
+
*/
|
|
270
|
+
export async function readSessionLog(file, modifiedAt) {
|
|
271
|
+
const buffer = await readFile(file);
|
|
272
|
+
return parseSessionLog(decodeSessionLog(buffer), file, modifiedAt);
|
|
273
|
+
}
|