cortico-world-memory-core 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/config.ts +1 -1
- package/src/world.ts +40 -5
- package/webui/app.js +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.24.0
|
|
4
|
+
|
|
5
|
+
**qq-official 的私聊能记了,但不会把「她自己说的话」记成对方说的。**
|
|
6
|
+
|
|
7
|
+
那个插件收发共用同一个 `senderKey`(`qq-official.c2c.…`),只看前缀会把三种东西一起抓进来:
|
|
8
|
+
她发出去的回复、`准备发送 → 私聊` 的占位、以及群聊。
|
|
9
|
+
|
|
10
|
+
- 白名单默认值加上 `qq-official\.c2c[.:]`;两版旧默认都算「没动过」,升级时自动换,不用手改配置。
|
|
11
|
+
- 抓取时按**方向**过滤:
|
|
12
|
+
- `tags` 带 `speak`(且来自 qq-official)→ 自己说的,跳过
|
|
13
|
+
- `type` 以 `.sent` / `.attempt` 结尾 → 发出去的回执 / 预备,跳过
|
|
14
|
+
- 正文以 `准备发送 →` 开头 → 老版本没 type/tags 时的兜底
|
|
15
|
+
- 群聊 key 不在白名单里,照旧不进。
|
|
16
|
+
- **来源不再抹成同一个词**:页面按 `c2c/group/channel` 显示「QQ 官方私聊 · 尾号」;
|
|
17
|
+
召回原文行带上 `·QQ官方私聊·xxxx`,模型能看出这句话从哪个会话来。
|
|
18
|
+
- `sender` 截断从 40 放宽到 64:`qq-official.c2c:` 本身占 16 字符,40 只给 openid 留 24,多个对象容易分不开。
|
|
19
|
+
- 新增 `tools/test-capture.ts` 第 10 项:同一 key 的五种事件,只留下两条真正的对方消息,
|
|
20
|
+
并检查来源标签与 sender 长度。
|
|
21
|
+
|
|
3
22
|
## 0.23.0
|
|
4
23
|
|
|
5
24
|
> 墓碑对齐需要自我意识 **0.10.0** 及以上;旧版不写墓碑,只是不会自动撤卡。
|
package/README.md
CHANGED
|
@@ -97,7 +97,9 @@ pnpm add cortico-world-memory-core
|
|
|
97
97
|
1. `envPromptVars()` 只回常量 —— 前缀永远不变,缓存不会因为「今天主动了几次」被冲掉。
|
|
98
98
|
2. 默认不每轮推送状态;要就开 `contextEveryMin`。
|
|
99
99
|
3. 主动开口先看对方最近 8 小时说过话没有,没有就只把 `dueAt` 往后推,不调模型。
|
|
100
|
-
4.
|
|
100
|
+
4. qq-official 的私聊:白名单认 `qq-official.c2c`,并按 `type`/`tags` 去掉她自己发出去的回执和「准备发送」占位——
|
|
101
|
+
那个插件收发共用同一个 senderKey,只看前缀会把两边混在一起。
|
|
102
|
+
5. 如果自我意识插件写了「想说话」(`../self-awareness/urges.jsonl`,30 分钟内、没用过),这一次可以不等原定间隔,
|
|
101
103
|
静默门也放宽到 6 分钟;由头用她的原话。她说「先搁着」时不会写。
|
|
102
104
|
4. 工作区文件检索有 60 秒缓存,只在 `recall` 带 query 时才发生,不增加每轮成本。
|
|
103
105
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-memory-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.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
|
@@ -94,7 +94,7 @@ export const MEMORY_CORE_DEFAULTS: MemoryCoreConfig = {
|
|
|
94
94
|
captureTurns: true,
|
|
95
95
|
// 真实 senderKey 长这样:private:1940008084(QQ 私聊)、desktop-pet.chat(桌宠对话)。
|
|
96
96
|
// 老默认值一个都匹配不上,导致原文库一直是 0 行 —— 改这个 regex 前先看一遍 data/runs/*/events.jsonl。
|
|
97
|
-
captureSenders: '^(desktop-pet\\.(chat|message|answer|voice)|private:|qq\\.private\\.|starpost\\.private\\.)',
|
|
97
|
+
captureSenders: '^(desktop-pet\\.(chat|message|answer|voice)|private:|qq\\.private\\.|qq-official\\.c2c[.:]|starpost\\.private\\.)',
|
|
98
98
|
captureAll: false,
|
|
99
99
|
captureMinLength: 4,
|
|
100
100
|
rawRetentionDays: 14,
|
package/src/world.ts
CHANGED
|
@@ -120,6 +120,18 @@ function extractUserText(raw: string): string {
|
|
|
120
120
|
.trim();
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/** 给召回行用的来源缩写:模型要知道这句话是从哪个渠道来的。 */
|
|
124
|
+
export function senderLabel(sender?: string): string {
|
|
125
|
+
const s = String(sender ?? '');
|
|
126
|
+
if (s.startsWith('qq-official.c2c')) return 'QQ官方私聊';
|
|
127
|
+
if (s.startsWith('qq-official.group')) return 'QQ群';
|
|
128
|
+
if (s.startsWith('qq-official.channel')) return 'QQ频道';
|
|
129
|
+
if (s.startsWith('private:')) return 'QQ私聊';
|
|
130
|
+
if (s.startsWith('desktop-pet')) return '桌宠';
|
|
131
|
+
if (s.startsWith('starpost')) return '星邮';
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
|
|
123
135
|
export class MemoryCoreWorld implements World {
|
|
124
136
|
readonly id = 'memory-core';
|
|
125
137
|
private readonly ctx: WorldContext<MemoryCoreConfig>;
|
|
@@ -922,7 +934,11 @@ export class MemoryCoreWorld implements World {
|
|
|
922
934
|
if (mode === 'search' && query) {
|
|
923
935
|
const hits = rankRaw(this.raw.all(), query, Math.max(1, Math.min(3, limit)));
|
|
924
936
|
for (const hit of hits) {
|
|
925
|
-
|
|
937
|
+
const from = senderLabel(hit.sender);
|
|
938
|
+
// 多个 qq-official 私聊对象共用一个标签,再带一段 openid 尾巴才分得开
|
|
939
|
+
const peer = from === 'QQ官方私聊' ? (/[A-Za-z0-9]{4}$/.exec(String(hit.sender ?? ''))?.[0] ?? '') : '';
|
|
940
|
+
const tag = from ? `·${from}${peer ? `·${peer}` : ''}` : '';
|
|
941
|
+
push(`· [对话 ${formatLocal(hit.ts, tz).slice(5)}${tag}] ${clip(hit.text, 90)}`);
|
|
926
942
|
}
|
|
927
943
|
if (this.cfg().workspaceScanEnabled && lines.join('\n').length < maxChars) {
|
|
928
944
|
const docHits = searchDocs(this.docs(), query, 2);
|
|
@@ -1190,8 +1206,12 @@ export class MemoryCoreWorld implements World {
|
|
|
1190
1206
|
*/
|
|
1191
1207
|
private senderRe(cfg: MemoryCoreConfig): RegExp {
|
|
1192
1208
|
const raw = String(cfg.captureSenders ?? '').trim();
|
|
1193
|
-
|
|
1194
|
-
const
|
|
1209
|
+
// 两版旧默认都算「没动过」:升级时自动补上 qq-official 的私聊前缀
|
|
1210
|
+
const legacy = [
|
|
1211
|
+
'^(starpost\\.private\\.|qq\\.|desktop-pet\\.message)',
|
|
1212
|
+
'^(desktop-pet\\.(chat|message|answer|voice)|private:|qq\\.private\\.|starpost\\.private\\.)',
|
|
1213
|
+
];
|
|
1214
|
+
const pattern = !raw || legacy.includes(raw) ? MEMORY_CORE_DEFAULTS.captureSenders : raw;
|
|
1195
1215
|
try {
|
|
1196
1216
|
return new RegExp(pattern);
|
|
1197
1217
|
} catch {
|
|
@@ -1240,7 +1260,14 @@ export class MemoryCoreWorld implements World {
|
|
|
1240
1260
|
while (!drained && rounds < budget) {
|
|
1241
1261
|
rounds += 1;
|
|
1242
1262
|
const to = Math.min(from + CAPTURE_BATCH, head);
|
|
1243
|
-
let events: readonly {
|
|
1263
|
+
let events: readonly {
|
|
1264
|
+
cursor: number;
|
|
1265
|
+
ts: string;
|
|
1266
|
+
senderKey?: string;
|
|
1267
|
+
text: string;
|
|
1268
|
+
type?: string;
|
|
1269
|
+
tags?: readonly string[];
|
|
1270
|
+
}[] = [];
|
|
1244
1271
|
try {
|
|
1245
1272
|
events = host.store.range({ fromCursor: from + 1, toCursor: to, origin: 'external' });
|
|
1246
1273
|
} catch {
|
|
@@ -1249,6 +1276,14 @@ export class MemoryCoreWorld implements World {
|
|
|
1249
1276
|
scanned += events.length;
|
|
1250
1277
|
for (const e of events) {
|
|
1251
1278
|
const key = e.senderKey ?? '';
|
|
1279
|
+
const kind = String(e.type ?? '');
|
|
1280
|
+
const tags = Array.isArray(e.tags) ? e.tags : [];
|
|
1281
|
+
// 方向过滤:qq-official 收发共用同一个 senderKey,只能看 type / tags。
|
|
1282
|
+
// 自己说出去的回执带 speak 标签或 *.sent / *.attempt,都不能记成「对方说的」。
|
|
1283
|
+
if ((kind.startsWith('qq-official.') || key.startsWith('qq-official.')) && tags.includes('speak')) continue;
|
|
1284
|
+
if (/\.(sent|attempt)$/.test(kind)) continue;
|
|
1285
|
+
// 插件占位兜底:老版本没有 type/tags 时,靠正文认「准备发送 → 私聊 msg_seq=…」
|
|
1286
|
+
if (/^准备发送\s*(?:→|->)/.test(String(e.text ?? '').trim())) continue;
|
|
1252
1287
|
// captureAll 打开时不再看白名单:群里的其他人、自己发的都记
|
|
1253
1288
|
if (!cfg.captureAll && !re.test(key)) {
|
|
1254
1289
|
// 记几个被挡掉的 key,出问题时一眼能看出是白名单还是正文的问题
|
|
@@ -1262,7 +1297,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1262
1297
|
if (/^\[(表情包|CQ:|图片)/.test(text)) continue;
|
|
1263
1298
|
if (/^[\p{P}\p{S}\s]+$/u.test(text)) continue;
|
|
1264
1299
|
if (/^\[[^\]]{0,12}\]$/.test(text.trim())) continue;
|
|
1265
|
-
items.push({ cursor: e.cursor, ts: e.ts, sender: maskSender(key).slice(0,
|
|
1300
|
+
items.push({ cursor: e.cursor, ts: e.ts, sender: maskSender(key).slice(0, 64), text });
|
|
1266
1301
|
}
|
|
1267
1302
|
// 按窗口边界推进,不按「最后一个匹配到的 cursor」:窗口里可能一条 external 都没有
|
|
1268
1303
|
from = to;
|
package/webui/app.js
CHANGED
|
@@ -2232,6 +2232,14 @@ function renderTurns() {
|
|
|
2232
2232
|
|
|
2233
2233
|
function shortSender(key) {
|
|
2234
2234
|
const raw = String(key ?? '');
|
|
2235
|
+
// qq-official 的私聊/群/频道前缀一样,只看第一段会全变成「qq-official.」
|
|
2236
|
+
if (raw.startsWith('qq-official.')) {
|
|
2237
|
+
const kind = raw.startsWith('qq-official.c2c') ? 'QQ 官方私聊'
|
|
2238
|
+
: raw.startsWith('qq-official.group') ? 'QQ 群'
|
|
2239
|
+
: raw.startsWith('qq-official.channel') ? 'QQ 频道' : 'QQ 官方';
|
|
2240
|
+
const tail = raw.slice(raw.indexOf(':') + 1).slice(-4);
|
|
2241
|
+
return raw.includes(':') && tail ? `${kind} · ${tail}` : kind;
|
|
2242
|
+
}
|
|
2235
2243
|
const base = raw.split(/[.:]/)[0];
|
|
2236
2244
|
const map = { starpost: '星邮', qq: 'QQ', private: 'QQ 私聊', 'desktop-pet': '桌宠' };
|
|
2237
2245
|
return map[base] ?? (raw || '—').slice(0, 12);
|