cortico-world-memory-core 0.12.1 → 0.14.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 +250 -207
- package/README.md +7 -5
- package/describe.json +5 -1
- package/package.json +1 -1
- package/src/config.ts +77 -12
- package/src/recall.ts +51 -3
- package/src/store.ts +12 -3
- package/src/tools.ts +3 -1
- package/src/world.ts +92 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,207 +1,250 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 0.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
## 0.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
|
|
74
|
-
## 0.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
-
|
|
135
|
-
-
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
-
|
|
146
|
-
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
-
|
|
157
|
-
-
|
|
158
|
-
-
|
|
159
|
-
-
|
|
160
|
-
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
-
|
|
178
|
-
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
-
|
|
188
|
-
-
|
|
189
|
-
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
-
|
|
196
|
-
- `
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
装完就能用,不用先去调 35 个开关。
|
|
6
|
+
|
|
7
|
+
- **顶部指标加「24 小时新写入」**:这是最高频的疑问(「她怎么不写记忆了」),现在打开设置页第一眼就能看到。0 会标红。
|
|
8
|
+
- **默认值按大众场景调了 4 个**:
|
|
9
|
+
|
|
10
|
+
| 项 | 旧默认 | 新默认 | 为什么 |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| `nightlyConsolidate` | 关 | **开** | 它已经不发额外请求(夜里备料、下次开口交付),关着等于放弃唯一一次「提醒它整理」的机会 |
|
|
13
|
+
| `requireRecentUserHours` | 8 小时 | **5 小时** | 8 小时太保守,早上第一条几乎不会触发主动 |
|
|
14
|
+
| `rawRetentionDays` | 7 天 | **14 天** | 7 天后原文进归档,日常问「上周说的那个」就搜不到了 |
|
|
15
|
+
| `rawArchiveDays` | 90 天 | **365 天** | 原话是证据,一年才几 MB,不该省 |
|
|
16
|
+
|
|
17
|
+
- 说明里去掉了一处 `**` 标记(设置页不渲染 markdown,会原样显示)。
|
|
18
|
+
- **注意**:这些只影响「没存过这个键」的新配置。已经在 `config.json` 里存了旧值的,需要手动改。
|
|
19
|
+
|
|
20
|
+
## 0.13.1
|
|
21
|
+
## 0.13.1
|
|
22
|
+
|
|
23
|
+
设置页文案有几处是**错的**,不是过时——按它们做决定会被误导。
|
|
24
|
+
|
|
25
|
+
- **夜间整理**:原来写「会多一次完整请求(约 8-10 万 token)」。0.6.0 之后它压根不发额外请求(夜里只备料,等下次开口才交付),而且 8-10 万这个量级也不对。改成如实描述。
|
|
26
|
+
- **每天主动上限**:原来写「3 次约等于 30 万 token」,实际一次主动 1-2 万。
|
|
27
|
+
- **存对话原文**:原来写「不存你自己说的话」,但默认白名单里就有 `desktop-pet.answer`,打开 `captureAll` 更是全存。
|
|
28
|
+
- **重扫历史补录**:原来写「做完自动关掉自己」——开关不会自己关,只是状态标记让它不再跑。改成「补完就不会再跑,开关留着不用管」。
|
|
29
|
+
- **组描述**还停在「四套记忆合成的一套」,改回它现在的样子。
|
|
30
|
+
- 补上「睡觉结束」「免打扰结束」两处空说明,并讲清**免打扰和睡觉不是一回事**。
|
|
31
|
+
- **设置项重排**:记忆总开关、站点、每轮想起几条提到最前;主动开口和作息收到后面。用显式顺序表实现,缺项会自动追加到末尾,不会漏。
|
|
32
|
+
- 顺手修掉 `captureAll` 标题显示成原始 key 的问题(写了 `label`,宿主读的是 `title`)。
|
|
33
|
+
|
|
34
|
+
## 0.13.0
|
|
35
|
+
## 0.13.0
|
|
36
|
+
|
|
37
|
+
补地基的三件(对照海马体:保真、自动捕获、召回质量)。
|
|
38
|
+
|
|
39
|
+
- **原话快照**:写卡时把对方最近那句原话(截断 80 字、`\d{7,}` 和邮箱先抹掉)一起存进 `src.text`。卡片仍是转述,但现在追得回证据。
|
|
40
|
+
- **出处视图**:`mcore_recall` 加 `id` 参数,返回这条记忆 + 当时的原话 + 前后各 2 句原文(标出「就是这句」),并给出「当天第几段对话」(间隔 >30 分钟算新的一段)。原文归档了会明说,不假装查到了。
|
|
41
|
+
- **BM25 取代二元组重叠**:正文打分换成真正的 BM25(k1=1.2 / b=0.75),建一次倒排;词频和长度都归一,长卡不再虚高,罕见词权重更大。系数调到 0.25 让权重/新鲜度还能在近似分之间起作用。
|
|
42
|
+
- **分档改用实词命中**:BM25 会给「今天」这种高频词打分,所以 `strong` 判定改成看 `bigrams`(停用词已剔除)+ 分数下限,不再用裸分。
|
|
43
|
+
- **captureAll 开关**:默认仍只记白名单,打开后群聊和自己发的也落盘。
|
|
44
|
+
- 测试新增 21(原话快照 + 出处 + 脱敏)和 22(捕获开关),共 117 条断言。
|
|
45
|
+
|
|
46
|
+
## 0.12.1
|
|
47
|
+
|
|
48
|
+
没有代码改动,重写简介。
|
|
49
|
+
|
|
50
|
+
- 旧简介还在讲「一张卡片表 + 4 个工具 + 473 字提示词 + 本地记忆地图」,那是 0.2.x 的形态。这一版按现在的样子重写:四个工具的分工、每轮自动推 2 条旧记忆、召回分两档、冷层三个月回暖、3D 星图、常驻约 1,000 token。
|
|
51
|
+
- 顺带说明:npm 上此前停在 0.4.4,0.5.0–0.12.0 这一段(3D 星图、两档召回、标签与冷层配额)这次一并发出去。
|
|
52
|
+
|
|
53
|
+
## 0.12.0
|
|
54
|
+
|
|
55
|
+
一轮「治写入口径」的改动。真实库体检出来的病:66 条里 50 条是 episode、50 条没有任何标签、小黑盒这一个话题堆了 8 条。功能不缺,是写进来的东西不对。
|
|
56
|
+
|
|
57
|
+
- **写入时提醒同主题堆积**:写 episode 时如果某个实词在库里已经出现 ≥4 次,返回里会带一句「『小黑盒』这个话题已经有 8 条了」,并给出两条出口(用 `closes` 并进旧的 / 其实它是规矩就写成 fact)。用实词复现而不是文本相似度——实测「每天发一条小黑盒」换个说法 Jaccard 只有 0.2,向量化的事我们做不了,但词频能抓到。
|
|
58
|
+
- **提示词要求带标签**:`tags` 两个词,主题 + 对方可能换的说法。这是唯一零成本提升召回的杠杆(现在 76% 的卡没标签,`tagHit` 整条通道空转)。
|
|
59
|
+
- **标签也做 IDF**:出现在三成以上卡里的标签(「日常」「工作」)不再算命中,否则泛标签会把所有卡一起抬高。
|
|
60
|
+
- **预激活按类型软加权**:fact ×1.25 / promise ×1.3 / episode ×0.8。**没有硬过滤**——库里 76% 是 episode,砍掉就没东西可推了。
|
|
61
|
+
- **冷层改成配额制**:`chillAfterDays` 默认 180 → **30**;只沉 episode/note,事实和自我不动;每天最多 4 条,**总数不超过在用卡的 25%**(防止十周后整片星空变黑)。
|
|
62
|
+
- **`npm test`**:五套测试 + 前端自检一条命令跑完,100 多条断言。README 加了「自检」一节,并说明 `tools/` 不进包。
|
|
63
|
+
|
|
64
|
+
## 0.11.0
|
|
65
|
+
|
|
66
|
+
召回分两档口气。海马体那边靠「想起来了 / 有点像」把不确定性摊开,我们之前是榜单一股脑给,模型容易把沾边的当成事实——这是它编故事最省力的入口。
|
|
67
|
+
|
|
68
|
+
- **`rankCardsScored`**:和 `rankCards` 同一套打分,但把 `lexical` / `tagHit` / `bigrams` / `tier` 一起返回,分档不在外面重算。
|
|
69
|
+
- **分档规则**:命中 ≥2 个实词二元组,或 1 个实词且词面重合 ≥0.45,或标签命中 ≥0.6 → `strong`;其余(只靠权重和新鲜度浮上来的)→ `weak`。
|
|
70
|
+
- **输出**:`【对得上】` / `【可能沾边,别当准】`;**一条都没真对上时**直接写「没有对得上的,下面只是沾边」,而且最多给 2 条,不拿 5 条沾边的充数。
|
|
71
|
+
- 出处那行顺手压缩成「↩ 是写它时最近的那句原话;卡片本身是改写的」。
|
|
72
|
+
- 真实库验证:`抖音绑的号` → 4 条对得上 + 1 条沾边;`今天好累` → 一条都对不上,只给 2 条线索。
|
|
73
|
+
|
|
74
|
+
## 0.10.0
|
|
75
|
+
|
|
76
|
+
按 GLM 的评审改星图的画法。它的三条批评都成立:光斑不是恒星、旋臂是画出来的虚线、多颗星的光晕叠在一起过曝。
|
|
77
|
+
|
|
78
|
+
- **恒星化**:光晕从「核的 9 倍」压到 3 倍,透明度 0.42 → 0.24;星核改成 1–2px 的锐利白点,够亮的再加十字星芒。放大不再糊。
|
|
79
|
+
- **旋臂由密度堆出来**:5200 颗尘埃点按 `r = r₀ + s·R`、`θ = base + 2.15π·s` 撒布,垂直方向按半径加大散射,再乘一条 `sin(19s)` 的明暗起伏做出「结」和「空洞」;底下垫一层柔光贴图的薄雾补连续性——不是画一条虚线再把星挂上去。
|
|
80
|
+
- **压过曝**:区域星云 0.13 → 0.07,核心三层降到 0.1 / 0.22 / 0.5,星等按族群大小加权(卡多的团整体更亮)。
|
|
81
|
+
- **超空间航道**:跨星系但共享标签的记忆之间连虚线(`rgba(158,206,255,0.22)`),这是「星群感」的来源,也让连线带上语义。
|
|
82
|
+
- **滚轮锚定光标缩放**:缩放时光标指着的那颗星不跑;双击连平移一起复位。
|
|
83
|
+
- **标签分级**:缩放 < 0.9 时只留 2 张卡以上的族,避免小族标签糊满屏。
|
|
84
|
+
|
|
85
|
+
## 0.9.1
|
|
86
|
+
|
|
87
|
+
主题按钮点了没反应。两个原因叠在一起:
|
|
88
|
+
|
|
89
|
+
- **在宿主里永远没反应**:站点被嵌进 Coopanion 时,URL 里带着宿主的主题快照(`#cortico-theme=…`),`applyTheme()` 一看到快照就直接用它、不再读本地选择,所以手动切换被覆盖。现在**用户手动选过就听用户的**,快照只在「跟随系统」时生效。
|
|
90
|
+
- **就算没有宿主,第一次点也可能看不出变化**:原来是 `auto → light → dark` 三态轮转,系统本来就是浅色时,`auto` 和 `light` 长得一模一样,点一下等于没点。现在改成**按屏幕上当前的样子翻面**(浅→深→浅),每次点都一定看得见。
|
|
91
|
+
- 按钮提示从「跟随系统 / 深色 / 浅色」改成「切换深色 / 浅色」,跟实际行为一致。
|
|
92
|
+
- 新增 `?theme=light|dark|auto` 调试参数,截图和排查时可以直接定死主题。
|
|
93
|
+
|
|
94
|
+
## 0.9.0
|
|
95
|
+
|
|
96
|
+
星图从「平面星系」升级成 **3D**,并且变成**默认视图**。
|
|
97
|
+
|
|
98
|
+
- **真的三维**:所有东西(6600 个尘埃点、420 颗远景星、66 个记忆星、星座连线、星云光团)都在世界坐标里,绕 Y 轴和 X 轴旋转后做透视投影,按深度排序画。不是把 2D 图斜切一下。
|
|
99
|
+
- **交互**:拖动旋转(带惯性)、滚轮缩放 0.45×–3.2×、双击复位、静置 2.6 秒后自己慢慢转。右下角实时显示 ROT / PITCH / ZOOM,字体用等宽,像仪表盘。
|
|
100
|
+
- **科幻感**:内嵌细边框、扫描线、底部缓慢下扫的辉光、标签用半透明黑底承托、遥测读数。都是 CSS 两层,不额外占 canvas。
|
|
101
|
+
- **默认视图**:星图排到第一个标签(`1` 键),打开站点就是这个画面。存储键换成 `mcore-view2`,老用户升级后也会看到新默认。
|
|
102
|
+
- **性能**:一帧约 4,700 个点 + 66 个精灵,用 `lighter` 混合叠加;离开星图页会 `cancelAnimationFrame`,不在后台空转。
|
|
103
|
+
- **标签**:贴着自己那团的外缘,撞上了就往下错开;团在正中心时固定朝右上,不会糊在自己人身上。
|
|
104
|
+
- 新增 `?gx=yaw,pitch,zoom` 调试参数,方便截图和复现视角。
|
|
105
|
+
|
|
106
|
+
## 0.8.0
|
|
107
|
+
|
|
108
|
+
把星图做成了**一个独立视图**,不是图谱的皮肤。
|
|
109
|
+
|
|
110
|
+
- **星图页**:螺旋星系当底(核心 + 两条尘埃旋臂 + 远景星),每个主题一团星座,凸包外扩成发光带。**亮度 = 最近被想起**(久不用的会暗下去,冷层更暗)、大小 = 权重、颜色 = 类型。
|
|
111
|
+
- **分区规则**:≥3 张卡共用的标签独立成团(月 / 小黑盒 / 无限流…),其余按类型兜底。不手写「脑区」——那等于编。
|
|
112
|
+
- **交互**:点星点看详情、悬停显示那句话、标签自动避让、跟着窗口尺寸重排。布局用固定种子,同一批卡每次画出来一样(截图稳定)。
|
|
113
|
+
- **性能**:星系底色(星点 + 星云 + 6600 个尘埃点)画一次缓存成离屏 canvas,悬停只重画上层;节点光晕按类型缓存成 sprite,不每帧建渐变。零依赖,仍是 canvas 2D。
|
|
114
|
+
- **视图注册**:`VIEWS` 统一管视图清单,加视图只改一处(之前散在 renderStage / 键盘 / boot 三处);`7` 键切星图。
|
|
115
|
+
- 顺手修了 `.galaxy-empty` 的 `[hidden]` 被 `display:grid` 顶掉、空态文字压在星图上的问题。
|
|
116
|
+
|
|
117
|
+
## 0.7.0
|
|
118
|
+
|
|
119
|
+
第一批清单里的 5 和 6:**把常驻成本砍下来**,和**一层不骗人的皮肤**。
|
|
120
|
+
|
|
121
|
+
- **常驻 1,358 → 约 1,003 tok(−26%)**。三处改动:
|
|
122
|
+
1. 提示词里删掉和工具 schema 重复的 kind 定义和查法说明——同一件事只说一遍,schema 说「是什么」,提示词说「什么时候用」。
|
|
123
|
+
2. schema 不再写数值边界(`minimum` / `maximum`),handler 本来就会 clamp,写两遍是每轮多付一次钱。
|
|
124
|
+
3. 日程参数从 `items: [{time,title,place}]` 拍平成顶层 `time/title/place`——原来的实现只取第一项,数组纯属浪费。
|
|
125
|
+
- **守门测试**:`test-upgrade` 最后两项钉住「schema ≤ 2600 字符、提示词 ≤ 480 字」,以后改胖了会红。
|
|
126
|
+
- **星图皮肤**:图谱右上角一个开关,同一份数据换个画法——光晕代替实心圆、连线压到 0.05 透明度,远看是一片星云。不动布局、不动交互、不加依赖(还是那个 canvas 和那套力导向),约 30 行。偏好记在本地,`?stars=1` 可以直接打开。
|
|
127
|
+
- 日程的老调用方式(`items` 数组)仍然兼容,导入和旧页面不会坏。
|
|
128
|
+
|
|
129
|
+
## 0.6.0
|
|
130
|
+
|
|
131
|
+
第一批清单里的 3 和 4:**自动巩固**和**分层**。两件都刻意做成「可逆、可看见」。
|
|
132
|
+
|
|
133
|
+
- **夜间整理改成「夜里备料、开口才交付」**:原来是在凌晨三点推一句「去整理一下」,那个点没人说话,推送就躺在历史里没人接;而且一次开就是一整轮完整请求。现在夜里只把最近 24 小时的原文收成一份 ≤1100 字的材料存进 `state.nightlyPending`,等**下一次说话**(`onTurnEnded`)才作为 piggyback 事件交付。指令也收紧:最多 3 条、能写 fact 就别写 episode、承诺带 `dueAt`、已有的别重复。另外两条免打扰:一天不到 4 句不备料;当天已经自己写过 3 条就不催。放超过 2 天的材料直接丢弃。
|
|
134
|
+
- **冷层(L2)**:`chillAfterDays` 默认 180。超过这个天数没被想起 + 权重 ≤ 0.5 + 不是没做完的承诺 → 沉到冷层。**不删除**:不参与每轮预激活、不进「最近」,显式搜索仍然找得到并标 `❄`;被真正召回一次会自动回暖。每天只判一次(`state.lastChillDay`)。
|
|
135
|
+
- **体检页加冷层**:显示沉了多少、还能再沉多少,可以手动「沉下去」或「全部回暖」——`POST /api/chill` / `/api/warm`,不带 ids 就是全部符合条件的。
|
|
136
|
+
- **缺键回落**:`chillAfterDays` 同样有「老 config 里没这个键」的问题,加了 `chillDays()` 回落到 180。
|
|
137
|
+
- **冷层口径**:`recall` 的 `mode=recent` 用 `recallable()`(排除冷层),`mode=search` 用 `active()`(包含冷层并标 ❄)。未完成的承诺永远不沉。
|
|
138
|
+
|
|
139
|
+
## 0.5.0
|
|
140
|
+
|
|
141
|
+
两件事:**让记忆自己浮上来**,和**承认它可以被追溯**。
|
|
142
|
+
|
|
143
|
+
起因是读了 dsh-hippocampus 的实现——它证明了一件事:记忆插件真正的病不是「记得少」,是「想不起」。我们的数据也印证了:147 次写、27 次读,62 张卡里 48 张从没被召回。模型不问,记忆就不存在。
|
|
144
|
+
|
|
145
|
+
- **每轮预激活**:`preactivateLines`(默认 2,可设 0 关)。拿对方刚说的那句当线索,`rankCards` 排序后推 ≤3 条到上下文,格式是「以前记下的,不是对方刚说的」。每张卡 2 小时冷却,同一句不重复推,同一张卡不连推。触发点有两个:心跳(60s)和 `onTurnEnded`——短对话等不到心跳。
|
|
146
|
+
- **线索必须真的命中**:`rankCards` 新增 `requireHit` 和 `minBigrams`。不加这两个的话,「今天好累」这种句子会让一张高权重无关卡靠 `weight` 混进「想起来了」。现在只认**实词**:单字不算,含虚词的二元组(不是 / 不能 / 来了 / 的号)也不算,另外还有一张时令词表(今天 / 晚上 / 回来)。在真实库上验过:`今天好累`、`我回来了`、`晚上吃点啥` 都推不出东西,`小黑盒…`、`抖音绑定的号`、`明天几点叫我` 各推出 2 条正确卡片。
|
|
147
|
+
- **出处 `↩`**:写卡时把当时最近的一句原话游标记进 `src`(半小时内才算),召回时显示 `↩11-02`,并在列表头上写明「这是改写过的记忆,不是原话」。改内容时不继承 `src`——文本换了,旧出处就是假的。
|
|
148
|
+
- **预激活单独记账**:新增 `primedCount` / `lastPrimedAt`,不和 `uses` 混。`uses` 仍然只表示「模型主动查了」,否则「召回转化率」这个数会被系统推送污染。体检页的「从没被想起」改成 `uses + primedCount` 都为 0。
|
|
149
|
+
- **缺键回落**:老部署的 `config.json` 没有 `preactivateLines`,直接 `Number(undefined)` 会得到 0,功能等于默认关闭。加 `preactivateCount()` 回落到默认值——`promiseRepeatDays` 上次踩过同一个坑。
|
|
150
|
+
- 提示词和工具 schema 没动,常驻仍是 1,358 tok;预激活每轮多约 35–60 tok,只在真的有命中时才推。
|
|
151
|
+
|
|
152
|
+
## 0.4.4
|
|
153
|
+
|
|
154
|
+
站点安全修复。来源是仓库 issue #1(Phantivia,扩展市场审查):写接口没有鉴权,任意网页可跨站写卡。**方向完全正确**,我按他给的两条建议都做了,并且先复现了四个事实:`text/plain` 跨站 POST 能写进去、伪造 `Host` 能拿到 200、`OPTIONS` 是 404、响应里没有 CORS 头。
|
|
155
|
+
|
|
156
|
+
- **写接口加一次性令牌**:`MemorySite` 启动时生成 `randomBytes(18)`,首页 HTML 注入 `<meta name="mcore-token">`,`app.js` 把它放进所有写请求的 `x-mcore-token` 头。校验用 `timingSafeEqual`。其他网页能打 localhost,但拿不到这个头。
|
|
157
|
+
- **Host 白名单**:只认 `127.0.0.1:<port>` 和 `localhost:<port>`,其他 Host 一律 403——包括首页。这条专门挡 DNS 重绑定:光有令牌挡不住重绑定(攻击者能读到带令牌的首页),光有 Host 白名单也挡不住用户浏览器里的普通 CSRF。
|
|
158
|
+
- **首页 `no-store`**:令牌每次启动都换,页面缓存住旧令牌会让所有写操作 403。
|
|
159
|
+
- **只读接口保持无令牌**:`/api/snapshot`、`/api/export` 等跨站读不到响应体(没有 CORS 头),导出链接也要能直接下载。
|
|
160
|
+
- **新增 `tools/test-site-auth.ts`**:10 项,覆盖令牌注入、伪造 Host、无令牌/错令牌/正确令牌、`localhost` 放行、导出仍可下载。
|
|
161
|
+
|
|
162
|
+
顺带一提:`Content-Type` 那条建议(只接受 `application/json`)我没单独做。因为写了「必须带令牌」之后它已经没有增量——没有令牌时,无论什么 Content-Type 都进不来。
|
|
163
|
+
|
|
164
|
+
## 0.4.3
|
|
165
|
+
|
|
166
|
+
隐私和手滑这两件事,都是之前列出来一直没做的。
|
|
167
|
+
|
|
168
|
+
- **原文来源脱敏**:`turns.jsonl` 里的 `sender` 原来存的是 `private:1940008084` 这种明文账号,目录一同步到网盘或备份就跟着泄露。现在只留后 4 位(`private:…8084`)。三道都做了:写入时脱敏、读取时再脱一次(老文件即使没改也不会露)、启动时把 `archive/` 下的旧文件抹一遍(`state.senderScrubbedAt` 记时间,只做一次)。
|
|
169
|
+
- **原文单条删除**:`DELETE /api/turns/:cursor`,热数据和归档都支持;删的是本地这一行,不影响对方那边,删完不会因为水位回退被重新录回来。页面上鼠标移到某一行,右上角出现「×」。
|
|
170
|
+
- **修掉 `load()` 里 `if (!quiet) render(); else render();`** 的冗余分支。
|
|
171
|
+
- **新增 `tools/audit-webui.ts`**:静态检查三件事——`$('#id')` 引用的元素在 HTML 里是否存在、`S.xxx` 读取的属性是否在 `S` 上定义、前端调的 `/api/*` 在后端是否有对应路由。0.4.2 里那个「搜索框从 0.1.0 起就抛异常」的 bug,正属于这套检查能提前抓到的类型。
|
|
172
|
+
|
|
173
|
+
## 0.4.2
|
|
174
|
+
|
|
175
|
+
按「第一批」做的三件事,其中第一件顺带挖出一个从 0.1.0 就带着的 bug。
|
|
176
|
+
|
|
177
|
+
- **原文页加「含归档」开关**:原来页面只搜最近 7 天的热数据,10-27 之前的句子在 `archive/` 里,一搜就是「没有匹配的对话」,看着像根本没记过。现在勾上开关会调 `/api/archive` 把归档也搜一遍,命中按天分组列在下面;开关状态记在本地,下次打开还记得。
|
|
178
|
+
- **深链接支持 `?q=` 和 `?archive=1`**:链接可以直接打开某个搜索结果,例如 `/?view=turns&q=泡馍&archive=1`。
|
|
179
|
+
- **修好搜索框**:`el.search` 的输入回调里写成了 `S.searchClear`,而 `S` 上根本没有这个属性——从 0.1.0 起,每敲一个字都在抛 `TypeError`,只是异常被吞掉,看起来像「搜索要等一会儿才生效」(实际是等 20 秒轮询重绘)。现在改成 `el.searchClear`。
|
|
180
|
+
- **提示词调 episode / fact 配比**:`episode` 从「发生过的一件事」收紧成「只写会改变你怎么看她的一件事,流水账不记,一天最多 2 条」,并把「能写成 fact 就别写成 episode」提到段首。实测 65 条里 48 条是 episode、只有 8 条 fact,这个比例说明它在记流水账。提示词 750 → 785 字(顺手把状态/日程那句压短,净增 28 tok)。
|
|
181
|
+
- 顺带把 4 条误标成 `promise` 的记录改回正确类型(两条已完成的改成 `episode`,一条常驻要求改成 `fact`),"没有截止时间"从 4 条降到 1 条。
|
|
182
|
+
|
|
183
|
+
## 0.4.1
|
|
184
|
+
|
|
185
|
+
0.4.0 没发到 npm,这里补上它漏掉的两件事——都是「承诺闭环」那一处。
|
|
186
|
+
|
|
187
|
+
- **补齐「无截止」出口**:0.4.0 只做了「不带 `dueAt` 就拒绝」,结果是一个真没时间的承诺(「下次见面给她带那本书」)根本存不进去,模型要么编一个日期,要么降级写成 `note`。现在 `dueAt: "none"` 会被接受,存成「无截止」的承诺:不参与提醒,但在体检测出来,可以补时间。
|
|
188
|
+
- **周期提醒改成默认开**:`promiseRepeatDays` 默认从 `0` 改成 `1`。0.4.0 的默认值等于「提醒一次就永久沉默」,那个 bug 实际还在。现在过期没做的承诺每天最多提一次,直到做完(传 `closes`)或退休;想退回旧行为就设 `0`。
|
|
189
|
+
- 修一处恢复失真:走导入接口撤销删除时,原本会把 `source` 一律改成 `import:backup`,现在能带就带。
|
|
190
|
+
|
|
191
|
+
## 0.4.0
|
|
192
|
+
|
|
193
|
+
这一版先把「会丢的东西别丢、答应的别忘」,再加一个能看见自己状态的体检页。默认行为基本不变,两处有意的变化单独标出。
|
|
194
|
+
|
|
195
|
+
- **写盘改成原子操作**:`cards.jsonl` / `turns.jsonl` / `state.json` 都先写 `.tmp` 再改名。原来每次全量 `writeFileSync` 覆盖,写到一半断电或被杀,文件会截断成空,`load()` 静默返回 0 条——整个库就这么没了,页面上一点异常都看不出来。rename 被杀软锁住时退回直接写。
|
|
196
|
+
- **每天自动备份**:当天第一次写入前把 `cards.jsonl` 复制到 `backups/cards-YYYY-MM-DD.jsonl`,只留 7 份。备份先于覆盖,所以备份里总是「改动前」的完整文件。
|
|
197
|
+
- **导入**:`POST /api/import` 接受自己导出的 JSON(整包:卡片 + 原文 + 日程 + 状态)。只加不覆盖——同 id 或「同类型 + 同文本」跳过,所以重复导同一个文件是幂等的。`state` 只接 `rawWatermark` 而且只往前推,防止旧备份把水位倒回去重录原文。原来只有导出没有导入,备份是单向的。
|
|
198
|
+
- **承诺必须带 `dueAt`**:`mcore_write` 写 `promise` 不给 `dueAt` 会直接被拒,并提示先问对方。之前 6 条承诺里 4 条没有截止时间,提醒管线对它们完全无效。
|
|
199
|
+
- **可选的周期提醒**:新增 `promiseRepeatDays`(默认 `0`)。`0` 时和旧版完全一致(提醒一次就永久沉默);大于 `0` 时按上次提醒时间算,够天数就再提一次,给「每天发一条」这类周期承诺用。
|
|
200
|
+
- **排序参考「上次被想起的时间」**:`lastUsedAt` 进打分(权重上限 0.15,压不倒一个关键词命中)。新增 `recallUseAging`(默认开),关掉退回旧公式。
|
|
201
|
+
- **体检页**:在用 / 从没被召回 / 召回次数 / 原文规模、近 14 天新增柱状、承诺与备份状态。从没被召回的卡可一键退休(不删除)。
|
|
202
|
+
- **维护面板加「承诺」页**:列出没写截止时间的(带时间输入框直接补)和已过时间还没做的(可标记做完)。
|
|
203
|
+
- **彻底删除加预览与撤销**:删前列出将删的条目,删后 10 秒内可整包还原(走新的导入接口)。
|
|
204
|
+
- 提示词 720 → 732 字:补一句「承诺必须写 dueAt,不知道就先问」。
|
|
205
|
+
|
|
206
|
+
## 0.3.2
|
|
207
|
+
|
|
208
|
+
- 简介统一格式:群号单独成段「QQ 交流群:745879632」,不再跟着正文尾巴;英文版同步。
|
|
209
|
+
- npm 卡片简介(`description`)也补上同一句,和 Token 账房保持一致。
|
|
210
|
+
|
|
211
|
+
## 0.3.1
|
|
212
|
+
|
|
213
|
+
- 简介末尾加 QQ 交流群 745879632(中英两版)。
|
|
214
|
+
|
|
215
|
+
## 0.3.0
|
|
216
|
+
|
|
217
|
+
- **图谱补上版本链**:被 `supersedes` 接替的旧卡会补进图(压暗、带标签),按「旧 → 新」画虚线箭头,图例注明「虚线箭头=被新版本接替」。之前这张图只有标签共现和「同一天」两种弱边,看不出记忆是怎么演进的——而版本链恰恰是这个插件最该被看见的关系。
|
|
218
|
+
- **搜索加防抖**:输入 150ms 后才重绘,不再每敲一个字就把原文 1000+ 条、表格几十行整体重建。
|
|
219
|
+
- **原文页分页**:先渲染最近 200 条,底部「还有 N 条 · 继续加载」;日期分组在只加载了一部分时显示「52 / 126 条」,不会让人以为那天只有这么几句。
|
|
220
|
+
- **「彻底删除」移出详情栏**:它原来紧挨「退休」,误触一次就不可逆。现在只能在维护面板 → 回收站里删,详情栏只留「退休 / 恢复」。
|
|
221
|
+
- 演示数据补了两组版本链,市场截图能体现新的图谱边。
|
|
222
|
+
|
|
223
|
+
## 0.2.1
|
|
224
|
+
|
|
225
|
+
- **修掉「对话原文一直是 0 行」**:默认 `captureSenders` 白名单一个真实 senderKey 都匹配不上(实际是 `private:1940008084`、`desktop-pet.chat`,旧正则写的是 `qq.` / `desktop-pet.message`)。新默认认 QQ 私聊、桌宠对话/语音、星邮私聊,群聊仍然不收;读到旧默认值会自动换成新的,不用手改设置。
|
|
226
|
+
- **原文过期不再直接删**:超过 `rawRetentionDays` 的行按天挪进 `data/memory-core/archive/YYYY-MM-DD.jsonl`,新增 `rawArchiveDays`(默认 90 天,0 = 永久)。模型用 `mcore_recall` 的 `mode=archive` 能翻回更早的对话。
|
|
227
|
+
- **归档不重复**:过期的新行直接进归档、不再留在 `turns.jsonl`;启动时按已归档的游标去重,重启不会把同一行写第二遍。
|
|
228
|
+
- **历史补录**:新增 `captureBackfill`,打开后重启一次会把水位倒回开头重扫宿主还留着的消息,补完自动停用;中途被打断会从断点接着跑。
|
|
229
|
+
- **补录分页修正**:宿主 `range` 的 `limit` 是「从区间末尾取」,之前拿它当分页,`from=0` 时直接返回全部历史的最后 400 条、水位一次跳到末尾,前面的补录全被跳过。改成分窗扫(`toCursor` 逐段推进),旧水位按版本号自动作废重来——真实数据从 55 行补到 1327 行。
|
|
230
|
+
- **诊断可见**:`state.json` 记录最近一次捕获的体检结果(扫了多少条、留下几条、被白名单挡掉的 key 样例),原文页没有数据时直接把样例显示出来。
|
|
231
|
+
- **召回打分**:标签单独加权(同一关键词命中标签比正文里顺带提到更靠前);`uses` 惩罚封顶 8 次,常用的重要记忆不会越用越沉。
|
|
232
|
+
- **疑似作废**加了老化候选:90 天没被召回、权重低于 0.45、未完成的承诺除外——仍然只是候选,要人点一下才退休。
|
|
233
|
+
- 提示词跟着加了一句 `mode=archive` 的用法(697 → 720 字符)。
|
|
234
|
+
|
|
235
|
+
## 0.2.0
|
|
236
|
+
|
|
237
|
+
- 补上扩展市场要的自描述与元数据:`describe.json`(工具、事件、环境提示词原文)、图标、四张演示截图,`cortico.locales` 中英简介。
|
|
238
|
+
- 标签改成词表里的:`memory`、`companion`、`internal-state`、`experimental`(原来的 `proactive` / `life` 不在词表里,市场会判为无效标签)。
|
|
239
|
+
- `CHANGELOG.md` 进包,市场详情页才能按版本显示更新日志。代码与 0.1.1 一致。
|
|
240
|
+
|
|
241
|
+
## 0.1.1
|
|
242
|
+
|
|
243
|
+
- 修正 `repository` / `homepage` / `bugs` 指向的 GitHub 地址(0.1.0 里写错了账号)。代码与 0.1.0 一致。
|
|
244
|
+
|
|
245
|
+
## 0.1.0
|
|
246
|
+
|
|
247
|
+
- 首个版本:一张卡片表(fact / self / episode / promise / note)、四个工具、一段静态环境提示词。
|
|
248
|
+
- 退休与版本链:编辑不覆盖,旧版标 `retired` 并由新卡记 `supersedes`;`closes` 取代旧记录后不再参与检索。
|
|
249
|
+
- 记忆域 `scope`、重复合并、疑似作废/垃圾识别,都在记忆地图的「维护」面板里先预览再执行。
|
|
250
|
+
- 记忆地图:图谱 / 时间线 / 列表 / 原文 / 文件五视图,右栏可折叠。
|
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ pnpm add cortico-world-memory-core
|
|
|
30
30
|
| 工具 | 作用 |
|
|
31
31
|
|---|---|
|
|
32
32
|
| `mcore_write` | 写一条记忆。`kind` 五选一,可带 `weight` / `tags` / `dueAt`;**`promise` 必须带 `dueAt`**,不知道时间会被拒绝并提示先问,确实没有截止时间就写 `dueAt: "none"`;传 `closes` 表示「这条替代了某条旧的」 |
|
|
33
|
-
| `mcore_recall` | 查记忆。不传 `query` 就是最近几条;传了就按内容搜,同时搜最近 7 天的对话原文和工作区笔记;结果分两档:「对得上」和「可能沾边,别当准」;带 `↩` 的是改写过的记忆 +
|
|
33
|
+
| `mcore_recall` | 查记忆。不传 `query` 就是最近几条;传了就按内容搜,同时搜最近 7 天的对话原文和工作区笔记;结果分两档:「对得上」和「可能沾边,别当准」;带 `↩` 的是改写过的记忆 + 当时那句原话的日期;给 `id` 可以看这条记忆的出处(当时那句原话 + 前后文);`mode=open` 看没做完的承诺和今天的安排;`mode=archive` 翻更早的归档原文 |
|
|
34
34
|
| `mcore_state` | 角色自己的精力 / 心情 / 正在做什么 / 在哪 / 睡没睡 |
|
|
35
35
|
| `mcore_plan` | 今天的日程(增、勾、清空) |
|
|
36
36
|
|
|
@@ -103,17 +103,19 @@ pnpm add cortico-world-memory-core
|
|
|
103
103
|
| `captureTurns` | `true` | 存对方最近的对话原文,供「搜最近聊过什么」 |
|
|
104
104
|
| `captureSenders` | `^(desktop-pet\.(chat\|message\|answer\|voice)\|private:\|qq\.private\.\|starpost\.private\.)` | 哪些来源算对话(正则匹配 senderKey)。真实 key 长这样:`private:1940008084`、`desktop-pet.chat`;群聊不算 |
|
|
105
105
|
| `captureMinLength` | `4` | 短于这个字数的消息不进原文库 |
|
|
106
|
-
| `rawRetentionDays` | `
|
|
107
|
-
| `rawArchiveDays` | `
|
|
108
|
-
| `captureBackfill` | `false` |
|
|
106
|
+
| `rawRetentionDays` | `14` | 热数据天数,超过就按天挪进 `archive/`(不再直接删) |
|
|
107
|
+
| `rawArchiveDays` | `365` | 归档保留天数,`0` = 永久 |
|
|
108
|
+
| `captureBackfill` | `false` | 打开后重启一次:把宿主还留着的历史消息补扫进原文库,只补没扫过的,补完就不会再跑 |
|
|
109
109
|
| `recallLimit` | `5` | 一次召回给几条 |
|
|
110
110
|
| `recallMaxChars` | `600` | 召回结果总字数上限 |
|
|
111
111
|
| `recallUseAging` | `true` | 排序参考「上次被想起的时间」:久不用的旧卡让位;关掉退回只看关键词、标签、权重 |
|
|
112
112
|
| `preactivateLines` | `2` | 每轮按对方刚说的话自动带出几条旧记忆(预激活),不用模型自己去查;`0` = 关,最多 3 条 |
|
|
113
113
|
| `promiseRepeatDays` | `1` | 到期还没做的承诺隔几天再提一次,直到做完或退休;`0` = 只提醒一次 |
|
|
114
114
|
| `proactiveEnabled` | `true` | 主动开口 |
|
|
115
|
+
| `requireRecentUserHours` | `5` | 对方超过这么久没说话就不主动,免得对着空房间说话白花钱 |
|
|
115
116
|
| `proactiveMinGapMin` / `proactiveDailyCap` | `100` / `3` | 主动间隔与每日上限 |
|
|
116
|
-
| `nightlyConsolidate` | `
|
|
117
|
+
| `nightlyConsolidate` | `true` | 夜间整理。夜里把当天原文备成一份材料,**下次开口时**才交付(不占额外请求,是一次普通的工具调用) |
|
|
118
|
+
| `captureAll` | `false` | 关着只记白名单里那个人的话;打开后群里其他人、以及自己发的消息也落盘。只影响原文库,不增加每轮成本 |
|
|
117
119
|
| `chillAfterDays` | `30` | 多久没被想起就沉到冷层(只沉低权重的「经历 / 临时」,事实、自我、未完成的承诺不动)。每天最多沉 4 条,最多占 25%。冷层不参与预激活和「最近」,搜索仍能找到,可一键回暖;`0` = 关闭 |
|
|
118
120
|
| `siteEnabled` / `sitePort` | `true` / `7801` | 记忆地图 |
|
|
119
121
|
|
package/describe.json
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
"name": "mcore_recall",
|
|
57
|
-
"description": "查记忆。给 query 按内容搜(同时搜最近 7 天原文和工作区笔记),不给就看最近几条;mode=open 看没做完的承诺和今天的安排,mode=archive 翻归档(要 query
|
|
57
|
+
"description": "查记忆。给 query 按内容搜(同时搜最近 7 天原文和工作区笔记),不给就看最近几条;mode=open 看没做完的承诺和今天的安排,mode=archive 翻归档(要 query);给 id 看这条记忆的出处(当时的原话 + 前后文)。对方提到人或旧事、问「你还记得吗」时先查再答。",
|
|
58
58
|
"parameters": {
|
|
59
59
|
"type": "object",
|
|
60
60
|
"additionalProperties": false,
|
|
@@ -63,6 +63,10 @@
|
|
|
63
63
|
"type": "string",
|
|
64
64
|
"description": "关键词就够"
|
|
65
65
|
},
|
|
66
|
+
"id": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"description": "看某条记忆的出处(传行首 8 位),会给出当时的原话和前后文"
|
|
69
|
+
},
|
|
66
70
|
"kind": {
|
|
67
71
|
"type": "string",
|
|
68
72
|
"enum": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-memory-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "四个工具写卡、查卡、改状态、排日程,改口不覆盖。每轮自动把 2 条相关旧记忆推到眼前,不用模型自己查;搜索分「对得上 / 可能沾边」两档。冷层收走三个月没想起的流水账,不删、可回暖。3D 星图一眼看完整个库。常驻约 1,000 token,本地不联网,MIT。\n\nQQ 交流群:745879632",
|
|
6
6
|
"keywords": [
|
package/src/config.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface MemoryCoreConfig {
|
|
|
33
33
|
captureTurns: boolean;
|
|
34
34
|
/** 哪些来源算「对方在跟我说话」,正则匹配 senderKey。 */
|
|
35
35
|
captureSenders: string;
|
|
36
|
+
/** 放开白名单:所有外部消息都记(含群聊、以及自己发的)。默认关。 */
|
|
37
|
+
captureAll: boolean;
|
|
36
38
|
/** 短于这么多字的对话原文不存(过滤表情、单字、口令回执)。 */
|
|
37
39
|
captureMinLength: number;
|
|
38
40
|
/** 对话原文保留天数(热数据,超过就按天归档)。 */
|
|
@@ -82,7 +84,7 @@ export const MEMORY_CORE_DEFAULTS: MemoryCoreConfig = {
|
|
|
82
84
|
proactiveJitterMin: 25,
|
|
83
85
|
proactiveDailyCap: 3,
|
|
84
86
|
idleGateMin: 20,
|
|
85
|
-
requireRecentUserHours:
|
|
87
|
+
requireRecentUserHours: 5,
|
|
86
88
|
promiseRepeatDays: 1,
|
|
87
89
|
quietStart: '23:30',
|
|
88
90
|
quietEnd: '08:00',
|
|
@@ -93,9 +95,10 @@ export const MEMORY_CORE_DEFAULTS: MemoryCoreConfig = {
|
|
|
93
95
|
// 真实 senderKey 长这样:private:1940008084(QQ 私聊)、desktop-pet.chat(桌宠对话)。
|
|
94
96
|
// 老默认值一个都匹配不上,导致原文库一直是 0 行 —— 改这个 regex 前先看一遍 data/runs/*/events.jsonl。
|
|
95
97
|
captureSenders: '^(desktop-pet\\.(chat|message|answer|voice)|private:|qq\\.private\\.|starpost\\.private\\.)',
|
|
98
|
+
captureAll: false,
|
|
96
99
|
captureMinLength: 4,
|
|
97
|
-
rawRetentionDays:
|
|
98
|
-
rawArchiveDays:
|
|
100
|
+
rawRetentionDays: 14,
|
|
101
|
+
rawArchiveDays: 365,
|
|
99
102
|
captureBackfill: false,
|
|
100
103
|
recallLimit: 5,
|
|
101
104
|
recallMaxChars: 600,
|
|
@@ -103,7 +106,7 @@ export const MEMORY_CORE_DEFAULTS: MemoryCoreConfig = {
|
|
|
103
106
|
preactivateLines: 2,
|
|
104
107
|
chillAfterDays: 30,
|
|
105
108
|
contextEveryMin: 0,
|
|
106
|
-
nightlyConsolidate:
|
|
109
|
+
nightlyConsolidate: true,
|
|
107
110
|
nightlyHour: 3,
|
|
108
111
|
energyDecayPerHour: 2.2,
|
|
109
112
|
workspaceScanEnabled: true,
|
|
@@ -132,13 +135,13 @@ const num = (
|
|
|
132
135
|
});
|
|
133
136
|
|
|
134
137
|
/** 设置页表单:键是 cfg 里的点分路径。全部热更新,改完不用重启。 */
|
|
135
|
-
|
|
138
|
+
const RAW_GROUP: ConfigGroup = {
|
|
136
139
|
id: 'world:memory-core',
|
|
137
140
|
owner: 'world:memory-core',
|
|
138
141
|
schema: {
|
|
139
142
|
type: 'object',
|
|
140
143
|
title: '记忆核心',
|
|
141
|
-
description: '
|
|
144
|
+
description: '卡片 + 4 个工具 + 一段提示词。装好后角色会自己往里写,也在你开口时自动带出几条旧的。第一次启动会把旧插件的记忆只读导入一次,原文件不动。',
|
|
142
145
|
properties: {
|
|
143
146
|
'worlds.memory-core.proactiveEnabled': {
|
|
144
147
|
type: 'boolean',
|
|
@@ -148,7 +151,7 @@ export const MEMORY_CORE_CONFIG_GROUP: ConfigGroup = {
|
|
|
148
151
|
},
|
|
149
152
|
'worlds.memory-core.proactiveMinGapMin': num('两次主动的最小间隔', '默认 100 分钟。太短会显得粘人,也费 token。', 15, 720, '分钟'),
|
|
150
153
|
'worlds.memory-core.proactiveJitterMin': num('随机抖动', '在最小间隔上加 0 到这么多分钟的随机量,避免每天准点开口。', 0, 120, '分钟'),
|
|
151
|
-
'worlds.memory-core.proactiveDailyCap': num('每天主动上限', '
|
|
154
|
+
'worlds.memory-core.proactiveDailyCap': num('每天主动上限', '一次主动约 1-2 万 token(看上下文长度),3 次大概 5 万。0 = 不限。', 0, 12, '次'),
|
|
152
155
|
'worlds.memory-core.idleGateMin': num('对方刚说话后的静默', '窗口内不主动,免得打断。', 0, 240, '分钟'),
|
|
153
156
|
'worlds.memory-core.requireRecentUserHours': num('对方多久没说话就不主动', '超过这个时长就当没人在,主动会对着空房间说话、白花钱。0 = 不限制。', 0, 72, '小时'),
|
|
154
157
|
'worlds.memory-core.promiseRepeatDays': num('承诺隔几天再提一次', '到期还没做的承诺,隔这么多天再提一次,直到做完或退休。默认 1(每天最多一次);0 = 只提醒一次。', 0, 30, '天'),
|
|
@@ -161,13 +164,13 @@ export const MEMORY_CORE_CONFIG_GROUP: ConfigGroup = {
|
|
|
161
164
|
'worlds.memory-core.quietEnd': {
|
|
162
165
|
type: 'string',
|
|
163
166
|
title: '免打扰结束',
|
|
164
|
-
description: '24 小时制 HH:MM
|
|
167
|
+
description: '24 小时制 HH:MM。起止相同等于不启用。',
|
|
165
168
|
'x-hot': true,
|
|
166
169
|
},
|
|
167
170
|
'worlds.memory-core.sleepStart': {
|
|
168
171
|
type: 'string',
|
|
169
172
|
title: '睡觉开始',
|
|
170
|
-
description: '
|
|
173
|
+
description: '这个时段里状态显示「在睡觉」,精力按「睡觉」逻辑回升;和免打扰不是一回事——免打扰只是不主动开口。',
|
|
171
174
|
'x-hot': true,
|
|
172
175
|
},
|
|
173
176
|
'worlds.memory-core.sleepEnd': {
|
|
@@ -184,9 +187,15 @@ export const MEMORY_CORE_CONFIG_GROUP: ConfigGroup = {
|
|
|
184
187
|
'worlds.memory-core.captureTurns': {
|
|
185
188
|
type: 'boolean',
|
|
186
189
|
title: '存对话原文',
|
|
187
|
-
description: '
|
|
190
|
+
description: '把最近的对话存成一行行本地文本,供「搜最近聊过什么」。默认只存白名单里的人;打开下面那项后,群里其他人和你自己说的也会存。',
|
|
188
191
|
'x-hot': true,
|
|
189
192
|
},
|
|
193
|
+
'worlds.memory-core.captureAll': {
|
|
194
|
+
type: 'boolean',
|
|
195
|
+
title: '所有人说的话都记',
|
|
196
|
+
description: '关着只记白名单里的人(默认),打开后群里其他人、以及你自己发的也会落盘。落盘只影响原文库,不增加每轮成本。',
|
|
197
|
+
default: false,
|
|
198
|
+
},
|
|
190
199
|
'worlds.memory-core.captureSenders': {
|
|
191
200
|
type: 'string',
|
|
192
201
|
title: '算作对话的来源',
|
|
@@ -199,7 +208,7 @@ export const MEMORY_CORE_CONFIG_GROUP: ConfigGroup = {
|
|
|
199
208
|
'worlds.memory-core.captureBackfill': {
|
|
200
209
|
type: 'boolean',
|
|
201
210
|
title: '重扫历史补录',
|
|
202
|
-
description: '
|
|
211
|
+
description: '打开后重启一次:把宿主还留着的历史消息补扫进原文库。只补没扫过的;补完就不会再跑,开关留着不用管。',
|
|
203
212
|
'x-hot': false,
|
|
204
213
|
},
|
|
205
214
|
'worlds.memory-core.recallLimit': num('一次召回给几条', '默认 5 条。给多了挤占上下文。', 1, 12, '条'),
|
|
@@ -215,7 +224,7 @@ export const MEMORY_CORE_CONFIG_GROUP: ConfigGroup = {
|
|
|
215
224
|
'worlds.memory-core.nightlyConsolidate': {
|
|
216
225
|
type: 'boolean',
|
|
217
226
|
title: '夜间整理',
|
|
218
|
-
description: '
|
|
227
|
+
description: '夜里把当天的原文收成一份材料,等你下次开口时交给它整理(最多 3 条,能写成 fact 就不写 episode)。不额外发请求。默认开。',
|
|
219
228
|
'x-hot': true,
|
|
220
229
|
},
|
|
221
230
|
'worlds.memory-core.nightlyHour': num('夜间整理时间', '24 小时制的小时数。', 0, 23, '点'),
|
|
@@ -264,3 +273,59 @@ export const MEMORY_CORE_CONFIG_GROUP: ConfigGroup = {
|
|
|
264
273
|
},
|
|
265
274
|
},
|
|
266
275
|
};
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 设置页的显示顺序:把「总开关 / 看记忆 / 每轮想起几条」放最前,
|
|
280
|
+
* 主动开口和作息往后——那些是角色行为,不是记忆本身。
|
|
281
|
+
* 用显式顺序表而不是直接调换定义位置,改起来不容易漏项。
|
|
282
|
+
*/
|
|
283
|
+
const SETTINGS_ORDER = [
|
|
284
|
+
'worlds.memory-core.memoryEnabled',
|
|
285
|
+
'worlds.memory-core.siteEnabled',
|
|
286
|
+
'worlds.memory-core.sitePort',
|
|
287
|
+
'worlds.memory-core.preactivateLines',
|
|
288
|
+
'worlds.memory-core.captureTurns',
|
|
289
|
+
'worlds.memory-core.captureAll',
|
|
290
|
+
'worlds.memory-core.captureSenders',
|
|
291
|
+
'worlds.memory-core.captureMinLength',
|
|
292
|
+
'worlds.memory-core.recallLimit',
|
|
293
|
+
'worlds.memory-core.recallMaxChars',
|
|
294
|
+
'worlds.memory-core.recallUseAging',
|
|
295
|
+
'worlds.memory-core.chillAfterDays',
|
|
296
|
+
'worlds.memory-core.rawRetentionDays',
|
|
297
|
+
'worlds.memory-core.rawArchiveDays',
|
|
298
|
+
'worlds.memory-core.captureBackfill',
|
|
299
|
+
'worlds.memory-core.nightlyConsolidate',
|
|
300
|
+
'worlds.memory-core.nightlyHour',
|
|
301
|
+
'worlds.memory-core.workspaceScanEnabled',
|
|
302
|
+
'worlds.memory-core.workspaceDirs',
|
|
303
|
+
'worlds.memory-core.workspaceExts',
|
|
304
|
+
'worlds.memory-core.workspaceMaxFiles',
|
|
305
|
+
'worlds.memory-core.workspaceMaxFileKB',
|
|
306
|
+
'worlds.memory-core.proactiveEnabled',
|
|
307
|
+
'worlds.memory-core.proactiveMinGapMin',
|
|
308
|
+
'worlds.memory-core.proactiveJitterMin',
|
|
309
|
+
'worlds.memory-core.proactiveDailyCap',
|
|
310
|
+
'worlds.memory-core.idleGateMin',
|
|
311
|
+
'worlds.memory-core.requireRecentUserHours',
|
|
312
|
+
'worlds.memory-core.promiseRepeatDays',
|
|
313
|
+
'worlds.memory-core.quietStart',
|
|
314
|
+
'worlds.memory-core.quietEnd',
|
|
315
|
+
'worlds.memory-core.sleepStart',
|
|
316
|
+
'worlds.memory-core.sleepEnd',
|
|
317
|
+
'worlds.memory-core.energyDecayPerHour',
|
|
318
|
+
'worlds.memory-core.contextEveryMin',
|
|
319
|
+
];
|
|
320
|
+
|
|
321
|
+
export const MEMORY_CORE_CONFIG_GROUP: ConfigGroup = (() => {
|
|
322
|
+
const props = (RAW_GROUP.schema.properties ?? {}) as Record<string, unknown>;
|
|
323
|
+
const known = SETTINGS_ORDER.filter((k) => k in props);
|
|
324
|
+
// 顺序表里没写到的项也不能丢:追加到末尾,宁可顺序难看也别少一个开关
|
|
325
|
+
const rest = Object.keys(props).filter((k) => !known.includes(k));
|
|
326
|
+
const ordered = [...known, ...rest].map((k) => [k, props[k]] as const);
|
|
327
|
+
return {
|
|
328
|
+
...RAW_GROUP,
|
|
329
|
+
schema: { ...RAW_GROUP.schema, properties: Object.fromEntries(ordered) },
|
|
330
|
+
};
|
|
331
|
+
})();
|
package/src/recall.ts
CHANGED
|
@@ -54,6 +54,47 @@ export function scoreText(queryTokens: readonly string[], text: string): number
|
|
|
54
54
|
return overlap(queryTokens, text);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/** BM25 参数:k1 控制词频饱和,b 控制长度归一。都是常用值。 */
|
|
58
|
+
const BM25_K1 = 1.2;
|
|
59
|
+
const BM25_B = 0.75;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 给整个候选池建一次倒排:每张卡的词频、长度、以及每个词出现在几张卡里。
|
|
63
|
+
* 卡片数量级是几十到几百,一次构建比「每个词去 includes 一遍」更省。
|
|
64
|
+
*/
|
|
65
|
+
function buildIndex(pool: readonly Card[]) {
|
|
66
|
+
const df = new Map<string, number>();
|
|
67
|
+
const tf = new Map<string, Map<string, number>>();
|
|
68
|
+
const len = new Map<string, number>();
|
|
69
|
+
let total = 0;
|
|
70
|
+
for (const card of pool) {
|
|
71
|
+
const tokens = tokenize(card.text);
|
|
72
|
+
const local = new Map<string, number>();
|
|
73
|
+
for (const t of tokens) local.set(t, (local.get(t) ?? 0) + 1);
|
|
74
|
+
tf.set(card.id, local);
|
|
75
|
+
len.set(card.id, tokens.length);
|
|
76
|
+
total += tokens.length;
|
|
77
|
+
for (const t of local.keys()) df.set(t, (df.get(t) ?? 0) + 1);
|
|
78
|
+
}
|
|
79
|
+
return { df, tf, len, avg: pool.length ? total / pool.length || 1 : 1, n: pool.length };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 一张卡的 BM25 分。字面越贴、词越罕见、卡越短,分越高。 */
|
|
83
|
+
function bm25(index: ReturnType<typeof buildIndex>, card: Card, tokens: readonly string[]): number {
|
|
84
|
+
const local = index.tf.get(card.id);
|
|
85
|
+
if (!local) return 0;
|
|
86
|
+
const dl = index.len.get(card.id) ?? 0;
|
|
87
|
+
let sum = 0;
|
|
88
|
+
for (const token of new Set(tokens)) {
|
|
89
|
+
const f = local.get(token);
|
|
90
|
+
if (!f) continue;
|
|
91
|
+
const df = index.df.get(token) ?? 0;
|
|
92
|
+
const idf = Math.log(1 + (index.n - df + 0.5) / (df + 0.5));
|
|
93
|
+
sum += (idf * (f * (BM25_K1 + 1))) / (f + BM25_K1 * (1 - BM25_B + (BM25_B * dl) / index.avg));
|
|
94
|
+
}
|
|
95
|
+
return sum;
|
|
96
|
+
}
|
|
97
|
+
|
|
57
98
|
function overlap(queryTokens: readonly string[], text: string): number {
|
|
58
99
|
if (!queryTokens.length) return 0;
|
|
59
100
|
const hay = String(text ?? '').toLowerCase();
|
|
@@ -161,8 +202,11 @@ export function rankCardsScored(cards: readonly Card[], opts: RankOptions): Scor
|
|
|
161
202
|
for (const [tag, n] of df) if (n > cap) commonTag.add(tag);
|
|
162
203
|
}
|
|
163
204
|
|
|
205
|
+
const index = buildIndex(pool);
|
|
164
206
|
const scored = pool.map((card) => {
|
|
165
|
-
|
|
207
|
+
// BM25 取代原来的「二元组命中数 / 长度」:词频和长度都归一过了,
|
|
208
|
+
// 一句话里反复出现同一个词不会把分堆爆,长卡也不会因为词多而虚高。
|
|
209
|
+
const lexical = bm25(index, card, queryTokens);
|
|
166
210
|
// 标签单独算一次:对方说「生日」时,打了 #生日 的卡要比正文里顺嘴提到的排得靠前。
|
|
167
211
|
// 但泛标签会把所有卡都拉高,所以先剔掉「到处都是」的那些。
|
|
168
212
|
const weakTags = card.tags.filter((t) => !commonTag.has(t));
|
|
@@ -176,7 +220,9 @@ export function rankCardsScored(cards: readonly Card[], opts: RankOptions): Scor
|
|
|
176
220
|
opts.useAging && Number.isFinite(lastUsed)
|
|
177
221
|
? 0.15 * Math.exp(-(now - lastUsed) / (30 * 86_400_000))
|
|
178
222
|
: 0;
|
|
179
|
-
|
|
223
|
+
// BM25 的量级是 0~25,乘 0.25 压回和旧版相近的比例:正文相关仍占主导,
|
|
224
|
+
// 但权重 / 新鲜度 / 用进废退还能在近似分数之间起作用。
|
|
225
|
+
const score = lexical * 0.25 + tagHit * 1.2 + card.weight * 0.5 + freshness(card.createdAt, now) + glow - used;
|
|
180
226
|
// 双字以上的命中数:预激活用它挡单字噪音
|
|
181
227
|
const hay = `${card.text} ${card.tags.join(' ')}`.toLowerCase();
|
|
182
228
|
let bigrams = 0;
|
|
@@ -193,7 +239,9 @@ export function rankCardsScored(cards: readonly Card[], opts: RankOptions): Scor
|
|
|
193
239
|
...x,
|
|
194
240
|
// 两个实词对上、或一个实词且词面确实重合,才算「对得上」;
|
|
195
241
|
// 只靠权重和新鲜度浮上来的,一律算「可能沾边」。
|
|
196
|
-
|
|
242
|
+
// 分档靠「实词命中数」而不是裸分:BM25 在「今天」这种高频词上也会给分,
|
|
243
|
+
// 但停用词表已经把这类词从 bigrams 里剔掉了,用它分档才不会被带偏。
|
|
244
|
+
tier: (x.bigrams >= 2 || (x.bigrams >= 1 && x.lexical >= 2.2) || x.tagHit >= 0.6
|
|
197
245
|
? 'strong'
|
|
198
246
|
: 'weak') as 'strong' | 'weak',
|
|
199
247
|
}));
|
package/src/store.ts
CHANGED
|
@@ -41,7 +41,8 @@ export interface Card {
|
|
|
41
41
|
* 写这条时最近的一句原文(游标 + 时间)。卡片是模型改写过的结论,
|
|
42
42
|
* 不是原话;留一个指针,召回时才敢说「这条能追到当时的哪一句」。
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
/** 写这条时,对方最近说的那句原话(截断 80 字,已脱敏)。有它才追得回证据。 */
|
|
45
|
+
src?: { cursor: number; ts: string; text?: string };
|
|
45
46
|
/** 被「主动想起」过几次(每轮预激活),和 uses(工具召回)分开记。 */
|
|
46
47
|
primedCount?: number;
|
|
47
48
|
lastPrimedAt?: string;
|
|
@@ -334,7 +335,8 @@ export class CardStore {
|
|
|
334
335
|
origin?: string;
|
|
335
336
|
createdAt?: string;
|
|
336
337
|
scope?: string;
|
|
337
|
-
|
|
338
|
+
/** 写这条时,对方最近说的那句原话(截断 80 字,已脱敏)。有它才追得回证据。 */
|
|
339
|
+
src?: { cursor: number; ts: string; text?: string };
|
|
338
340
|
}): { card: Card; merged: boolean } {
|
|
339
341
|
const text = String(input.text ?? '').replace(/\s+/g, ' ').trim().slice(0, 500);
|
|
340
342
|
const key = normalizeText(text);
|
|
@@ -719,7 +721,14 @@ export class CardStore {
|
|
|
719
721
|
src:
|
|
720
722
|
c.src && typeof c.src === 'object' && Number.isFinite(Number((c.src as { cursor?: unknown }).cursor))
|
|
721
723
|
&& typeof (c.src as { ts?: unknown }).ts === 'string'
|
|
722
|
-
? {
|
|
724
|
+
? {
|
|
725
|
+
cursor: Number((c.src as { cursor: number }).cursor),
|
|
726
|
+
ts: String((c.src as { ts: string }).ts),
|
|
727
|
+
text:
|
|
728
|
+
typeof (c.src as { text?: unknown }).text === 'string'
|
|
729
|
+
? String((c.src as { text: string }).text).slice(0, 80)
|
|
730
|
+
: undefined,
|
|
731
|
+
}
|
|
723
732
|
: undefined,
|
|
724
733
|
primedCount: Number.isFinite(Number(c.primedCount)) ? Number(c.primedCount) : undefined,
|
|
725
734
|
lastPrimedAt: typeof c.lastPrimedAt === 'string' ? c.lastPrimedAt : undefined,
|
package/src/tools.ts
CHANGED
|
@@ -40,11 +40,13 @@ export const TOOL_SPECS: ToolSpec[] = [
|
|
|
40
40
|
name: 'mcore_recall',
|
|
41
41
|
description:
|
|
42
42
|
'查记忆。给 query 按内容搜(同时搜最近 7 天原文和工作区笔记),不给就看最近几条;'
|
|
43
|
-
+ 'mode=open 看没做完的承诺和今天的安排,mode=archive 翻归档(要 query
|
|
43
|
+
+ 'mode=open 看没做完的承诺和今天的安排,mode=archive 翻归档(要 query);'
|
|
44
|
+
+ '给 id 看这条记忆的出处(当时的原话 + 前后文)。'
|
|
44
45
|
+ '对方提到人或旧事、问「你还记得吗」时先查再答。',
|
|
45
46
|
parameters: obj(
|
|
46
47
|
{
|
|
47
48
|
query: { type: 'string', description: '关键词就够' },
|
|
49
|
+
id: { type: 'string', description: '看某条记忆的出处(传行首 8 位),会给出当时的原话和前后文' },
|
|
48
50
|
kind: { type: 'string', enum: ['fact', 'self', 'episode', 'promise', 'note'], description: '只看某一类' },
|
|
49
51
|
mode: { type: 'string', enum: ['search', 'recent', 'open', 'archive'], description: '默认 search' },
|
|
50
52
|
days: { type: 'integer', description: '只看最近这么多天' },
|
package/src/world.ts
CHANGED
|
@@ -58,6 +58,16 @@ function clip(text: string, limit: number): string {
|
|
|
58
58
|
return s.length > limit ? `${s.slice(0, limit)}…` : s;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/** 原话要落进卡片,先把明显的号码抹掉:卡片会被导出、被展示,原话不该泄。 */
|
|
62
|
+
function scrubQuote(text: string): string {
|
|
63
|
+
return String(text ?? '')
|
|
64
|
+
.replace(/\s+/g, ' ')
|
|
65
|
+
.trim()
|
|
66
|
+
.replace(/\d{7,}/g, '[号码]')
|
|
67
|
+
.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g, '[邮箱]')
|
|
68
|
+
.slice(0, 80);
|
|
69
|
+
}
|
|
70
|
+
|
|
61
71
|
function num(value: unknown, fallback: number, lo: number, hi: number): number {
|
|
62
72
|
const n = Number(value);
|
|
63
73
|
if (!Number.isFinite(n)) return fallback;
|
|
@@ -219,6 +229,13 @@ export class MemoryCoreWorld implements World {
|
|
|
219
229
|
const cfg = this.cfg();
|
|
220
230
|
const stats = this.store.stats();
|
|
221
231
|
const count = this.countToday();
|
|
232
|
+
const dayAgo = Date.now() - 86_400_000;
|
|
233
|
+
const fresh = this.store
|
|
234
|
+
.active()
|
|
235
|
+
.filter((c) => {
|
|
236
|
+
const at = Date.parse(c.createdAt);
|
|
237
|
+
return Number.isFinite(at) && at >= dayAgo;
|
|
238
|
+
}).length;
|
|
222
239
|
return {
|
|
223
240
|
label: '记忆核心',
|
|
224
241
|
lamps: [
|
|
@@ -245,9 +262,15 @@ export class MemoryCoreWorld implements World {
|
|
|
245
262
|
},
|
|
246
263
|
],
|
|
247
264
|
badges: [
|
|
265
|
+
{ label: '记忆', value: stats.total },
|
|
266
|
+
// 「为什么没有新记忆」是最高频的疑问,所以把 24 小时写入量放到第一屏
|
|
267
|
+
{
|
|
268
|
+
label: '24 小时新写入',
|
|
269
|
+
value: fresh,
|
|
270
|
+
tone: fresh > 0 ? 'on' : 'off',
|
|
271
|
+
},
|
|
248
272
|
{ label: '今日主动', value: `${count}/${cfg.proactiveDailyCap || '∞'}` },
|
|
249
273
|
{ label: '精力', value: Math.round(this.state.energy), tone: this.state.energy < 35 ? 'off' : 'on' },
|
|
250
|
-
{ label: '记忆', value: stats.total },
|
|
251
274
|
],
|
|
252
275
|
promptDocs: [
|
|
253
276
|
{
|
|
@@ -748,7 +771,12 @@ export class MemoryCoreWorld implements World {
|
|
|
748
771
|
this.probeLastUser(Date.now());
|
|
749
772
|
const src =
|
|
750
773
|
this.lastTurn && Date.now() - this.lastTurn.at < 30 * 60_000
|
|
751
|
-
? {
|
|
774
|
+
? {
|
|
775
|
+
cursor: this.lastTurn.cursor,
|
|
776
|
+
ts: new Date(this.lastTurn.at).toISOString(),
|
|
777
|
+
// 原话一起存下来:卡片是转述,将来要证明「她当时真这么说过」,靠的是这个
|
|
778
|
+
text: scrubQuote(this.lastTurn.text) || undefined,
|
|
779
|
+
}
|
|
752
780
|
: undefined;
|
|
753
781
|
const res = this.store.add({
|
|
754
782
|
kind,
|
|
@@ -827,6 +855,8 @@ export class MemoryCoreWorld implements World {
|
|
|
827
855
|
|
|
828
856
|
private handleRecall(args: Record<string, unknown>): string {
|
|
829
857
|
if (!this.cfg().memoryEnabled) return '记忆已关闭(设置页里可以打开)。';
|
|
858
|
+
const idArg = str(args.id, 60);
|
|
859
|
+
if (idArg) return this.handleSource(idArg);
|
|
830
860
|
const query = str(args.query, 200);
|
|
831
861
|
const mode = String(args.mode ?? (query ? 'search' : 'recent'));
|
|
832
862
|
const limit = num(args.limit, Number(this.cfg().recallLimit) || 5, 1, 12);
|
|
@@ -958,6 +988,64 @@ export class MemoryCoreWorld implements World {
|
|
|
958
988
|
].join('\n');
|
|
959
989
|
}
|
|
960
990
|
|
|
991
|
+
/**
|
|
992
|
+
* 看一条记忆的出处:卡片原文 + 写它时那句原话 + 前后文。
|
|
993
|
+
* 卡片是改写的,只有这里能回到证据。
|
|
994
|
+
*/
|
|
995
|
+
private handleSource(prefix: string): string {
|
|
996
|
+
const tz = this.tz();
|
|
997
|
+
const card = this.findCard(prefix);
|
|
998
|
+
if (!card) return '没找到这条记忆(id 是召回结果里行首的 8 位)。';
|
|
999
|
+
const out: string[] = [];
|
|
1000
|
+
out.push(`【这条记忆】· ${card.id.slice(0, 8)} ${formatLocal(card.createdAt, tz).slice(5)} ${clip(card.text, 160)}(${card.kind}${card.status === 'retired' ? ',已退休' : ''})`);
|
|
1001
|
+
|
|
1002
|
+
if (!card.src) {
|
|
1003
|
+
out.push('这条没记出处(多半是导入的旧数据,或者写的时候对方半小时内没说话)。');
|
|
1004
|
+
} else {
|
|
1005
|
+
const when = formatLocal(card.src.ts, tz);
|
|
1006
|
+
const sess = this.sessionIndexOf(card.src.ts, card.src.cursor);
|
|
1007
|
+
const head = `写它的时候:${when}${sess ? ` · 当天第 ${sess} 段对话` : ''}`;
|
|
1008
|
+
out.push(card.src.text ? `${head}\n原话:「${card.src.text}」` : `${head}\n(那句话没留下来,只记了时间)`);
|
|
1009
|
+
const around = this.rawAround(card.src.cursor, 2);
|
|
1010
|
+
if (around.length) {
|
|
1011
|
+
out.push('前后:');
|
|
1012
|
+
for (const e of around) {
|
|
1013
|
+
const mark = e.cursor === card.src.cursor ? ' ← 就是这句' : '';
|
|
1014
|
+
out.push(`· [${formatLocal(e.ts, tz).slice(5)}] ${clip(e.text, 80)}${mark}`);
|
|
1015
|
+
}
|
|
1016
|
+
} else {
|
|
1017
|
+
out.push('(这段原文不在最近几天里,用 mode=archive 搜那天的话)');
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
if (card.supersedes?.length) out.push(`这条接替了:${card.supersedes.map((id) => id.slice(0, 8)).join(' ')}`);
|
|
1021
|
+
return out.join('\n');
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
/** 某条原文前后各 n 句(只在本机最近的热数据里找)。 */
|
|
1025
|
+
private rawAround(cursor: number, n: number) {
|
|
1026
|
+
if (!Number.isFinite(cursor) || cursor < 0) return [];
|
|
1027
|
+
const all = this.raw.all().slice().sort((a, b) => a.cursor - b.cursor);
|
|
1028
|
+
const at = all.findIndex((e) => e.cursor === cursor);
|
|
1029
|
+
if (at < 0) return [];
|
|
1030
|
+
return all.slice(Math.max(0, at - n), at + n + 1);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/** 当天第几段对话:间隔超过 30 分钟就算新的一段。 */
|
|
1034
|
+
private sessionIndexOf(ts: string, cursor: number): number {
|
|
1035
|
+
const tz = this.tz();
|
|
1036
|
+
const day = formatLocal(ts, tz).slice(0, 10);
|
|
1037
|
+
let idx = 0;
|
|
1038
|
+
let prev = 0;
|
|
1039
|
+
for (const e of this.raw.all().slice().sort((a, b) => a.cursor - b.cursor)) {
|
|
1040
|
+
if (formatLocal(e.ts, tz).slice(0, 10) !== day) continue;
|
|
1041
|
+
const t = Date.parse(e.ts);
|
|
1042
|
+
if (!prev || t - prev > 30 * 60_000) idx += 1;
|
|
1043
|
+
prev = t;
|
|
1044
|
+
if (e.cursor >= cursor) break;
|
|
1045
|
+
}
|
|
1046
|
+
return idx;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
961
1049
|
private handlePlan(args: Record<string, unknown>): string {
|
|
962
1050
|
const action = String(args.action ?? 'list');
|
|
963
1051
|
if (action === 'add') {
|
|
@@ -1116,7 +1204,8 @@ export class MemoryCoreWorld implements World {
|
|
|
1116
1204
|
scanned += events.length;
|
|
1117
1205
|
for (const e of events) {
|
|
1118
1206
|
const key = e.senderKey ?? '';
|
|
1119
|
-
|
|
1207
|
+
// captureAll 打开时不再看白名单:群里的其他人、自己发的都记
|
|
1208
|
+
if (!cfg.captureAll && !re.test(key)) {
|
|
1120
1209
|
// 记几个被挡掉的 key,出问题时一眼能看出是白名单还是正文的问题
|
|
1121
1210
|
if (key && keys.size < 6) keys.add(key);
|
|
1122
1211
|
continue;
|