cortico-world-memory-core 0.22.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 +32 -0
- package/README.md +3 -1
- package/package.json +2 -2
- package/src/config.ts +1 -1
- package/src/store.ts +2 -0
- package/src/world.ts +80 -5
- package/webui/app.js +17 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
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
|
+
|
|
22
|
+
## 0.23.0
|
|
23
|
+
|
|
24
|
+
> 墓碑对齐需要自我意识 **0.10.0** 及以上;旧版不写墓碑,只是不会自动撤卡。
|
|
25
|
+
|
|
26
|
+
**能直接删了,退休不再是唯一出口。**
|
|
27
|
+
|
|
28
|
+
- 详情栏「退休」旁边加了「彻底删除」:二次确认 + 10 秒撤销,和回收站里是同一套。
|
|
29
|
+
在用的卡不用先退休、再去回收站找。
|
|
30
|
+
- 从自我意识收下想法时记 `srcThoughtId`。她删掉那条想法后,墓碑写在
|
|
31
|
+
`../self-awareness/deleted-thoughts.jsonl`,这边下一次周期清理会撤回对应卡片。
|
|
32
|
+
只认带来源 id 的新卡片;更早的没有 id,手动删。
|
|
33
|
+
- 测试新增 `tools/test-delete.ts` 2 项:按墓碑撤回、无关卡片不动。
|
|
34
|
+
|
|
3
35
|
## 0.22.0
|
|
4
36
|
|
|
5
37
|
> 需要自我意识 **0.9.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": [
|
|
@@ -73,6 +73,6 @@
|
|
|
73
73
|
"access": "public"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
|
-
"test": "node --experimental-transform-types --no-warnings tools/test-store.ts && node --experimental-transform-types --no-warnings tools/test-world.ts && node --experimental-transform-types --no-warnings tools/test-capture.ts && node --experimental-transform-types --no-warnings tools/test-upgrade.ts && node --experimental-transform-types --no-warnings tools/test-urge.ts && node --experimental-transform-types --no-warnings tools/test-site-auth.ts && node --experimental-transform-types --no-warnings tools/audit-webui.ts"
|
|
76
|
+
"test": "node --experimental-transform-types --no-warnings tools/test-store.ts && node --experimental-transform-types --no-warnings tools/test-world.ts && node --experimental-transform-types --no-warnings tools/test-capture.ts && node --experimental-transform-types --no-warnings tools/test-upgrade.ts && node --experimental-transform-types --no-warnings tools/test-urge.ts && node --experimental-transform-types --no-warnings tools/test-delete.ts && node --experimental-transform-types --no-warnings tools/test-site-auth.ts && node --experimental-transform-types --no-warnings tools/audit-webui.ts"
|
|
77
77
|
}
|
|
78
78
|
}
|
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/store.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface Card {
|
|
|
31
31
|
/** 缺省视为 active:老数据没有这个字段,读的时候补上。 */
|
|
32
32
|
status?: CardStatus;
|
|
33
33
|
retiredAt?: string;
|
|
34
|
+
/** 从自我意识收下来时,记下那条想法的 id:她删了想法,这张卡要跟着撤。 */
|
|
35
|
+
srcThoughtId?: string;
|
|
34
36
|
/** 谁让它退休的:'merge' | 'purge' | 'stale' | 接替它的卡片 id。 */
|
|
35
37
|
retiredBy?: string;
|
|
36
38
|
/** 它接替了哪些卡(编辑留版本、closes 关旧记录时写)。 */
|
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);
|
|
@@ -1163,6 +1179,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1163
1179
|
Boolean(this.cfg().captureBackfill)
|
|
1164
1180
|
&& (Number(this.state.watermarkVersion ?? 0) < CAPTURE_WATERMARK_VERSION || !this.state.backfillDoneAt),
|
|
1165
1181
|
);
|
|
1182
|
+
this.pruneDeletedThoughts();
|
|
1166
1183
|
this.absorbThoughts(now);
|
|
1167
1184
|
await this.maybeContext(now);
|
|
1168
1185
|
await this.maybePreactivate(now);
|
|
@@ -1189,8 +1206,12 @@ export class MemoryCoreWorld implements World {
|
|
|
1189
1206
|
*/
|
|
1190
1207
|
private senderRe(cfg: MemoryCoreConfig): RegExp {
|
|
1191
1208
|
const raw = String(cfg.captureSenders ?? '').trim();
|
|
1192
|
-
|
|
1193
|
-
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;
|
|
1194
1215
|
try {
|
|
1195
1216
|
return new RegExp(pattern);
|
|
1196
1217
|
} catch {
|
|
@@ -1239,7 +1260,14 @@ export class MemoryCoreWorld implements World {
|
|
|
1239
1260
|
while (!drained && rounds < budget) {
|
|
1240
1261
|
rounds += 1;
|
|
1241
1262
|
const to = Math.min(from + CAPTURE_BATCH, head);
|
|
1242
|
-
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
|
+
}[] = [];
|
|
1243
1271
|
try {
|
|
1244
1272
|
events = host.store.range({ fromCursor: from + 1, toCursor: to, origin: 'external' });
|
|
1245
1273
|
} catch {
|
|
@@ -1248,6 +1276,14 @@ export class MemoryCoreWorld implements World {
|
|
|
1248
1276
|
scanned += events.length;
|
|
1249
1277
|
for (const e of events) {
|
|
1250
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;
|
|
1251
1287
|
// captureAll 打开时不再看白名单:群里的其他人、自己发的都记
|
|
1252
1288
|
if (!cfg.captureAll && !re.test(key)) {
|
|
1253
1289
|
// 记几个被挡掉的 key,出问题时一眼能看出是白名单还是正文的问题
|
|
@@ -1261,7 +1297,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1261
1297
|
if (/^\[(表情包|CQ:|图片)/.test(text)) continue;
|
|
1262
1298
|
if (/^[\p{P}\p{S}\s]+$/u.test(text)) continue;
|
|
1263
1299
|
if (/^\[[^\]]{0,12}\]$/.test(text.trim())) continue;
|
|
1264
|
-
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 });
|
|
1265
1301
|
}
|
|
1266
1302
|
// 按窗口边界推进,不按「最后一个匹配到的 cursor」:窗口里可能一条 external 都没有
|
|
1267
1303
|
from = to;
|
|
@@ -1497,6 +1533,44 @@ export class MemoryCoreWorld implements World {
|
|
|
1497
1533
|
* 文本前面加「独处时写下」——不然它会以卡片的身份进上下文,被当成此刻的想法,
|
|
1498
1534
|
* 那又变成替她认领了。
|
|
1499
1535
|
*/
|
|
1536
|
+
/**
|
|
1537
|
+
* 她删掉的想法,墓碑写在 `deleted-thoughts.jsonl`。
|
|
1538
|
+
* 由那条想法收成的卡片要一起清掉——不然时间线里没了,星图上还挂着。
|
|
1539
|
+
* 只认带 srcThoughtId 的新卡片;老卡片没有来源 id,只能手动删。
|
|
1540
|
+
*/
|
|
1541
|
+
private pruneDeletedThoughts(): void {
|
|
1542
|
+
const file = join(this.dataDir, '..', 'self-awareness', 'deleted-thoughts.jsonl');
|
|
1543
|
+
if (!existsSync(file)) return;
|
|
1544
|
+
const ids = new Set<string>();
|
|
1545
|
+
try {
|
|
1546
|
+
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
1547
|
+
const s = line.trim();
|
|
1548
|
+
if (!s) continue;
|
|
1549
|
+
try {
|
|
1550
|
+
const o = JSON.parse(s) as { id?: unknown };
|
|
1551
|
+
if (typeof o.id === 'string' && o.id) ids.add(o.id);
|
|
1552
|
+
} catch {
|
|
1553
|
+
// 坏行跳过
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
} catch {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
if (!ids.size) return;
|
|
1560
|
+
const victims = this.store
|
|
1561
|
+
.all()
|
|
1562
|
+
.filter((c) => c.srcThoughtId && ids.has(c.srcThoughtId))
|
|
1563
|
+
.map((c) => c.id);
|
|
1564
|
+
if (victims.length) {
|
|
1565
|
+
this.store.purge(victims);
|
|
1566
|
+
try {
|
|
1567
|
+
this.host?.log?.info?.('[memory-core] 她删了想法,跟着撤回卡片', { count: victims.length });
|
|
1568
|
+
} catch {
|
|
1569
|
+
// ignore
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1500
1574
|
private absorbThoughts(now: Date): void {
|
|
1501
1575
|
if (this.cfg().absorbSelfThought === false) return;
|
|
1502
1576
|
const done = new Set(this.state.absorbedThoughtIds ?? []);
|
|
@@ -1517,6 +1591,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1517
1591
|
tags: ['独处'],
|
|
1518
1592
|
source: 'self-awareness',
|
|
1519
1593
|
origin: 'tool',
|
|
1594
|
+
srcThoughtId: t.id,
|
|
1520
1595
|
});
|
|
1521
1596
|
added += 1;
|
|
1522
1597
|
}
|
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);
|
|
@@ -2355,6 +2363,7 @@ function renderInspector() {
|
|
|
2355
2363
|
? `<button class="btn tiny" id="btn-restore">恢复这条</button>`
|
|
2356
2364
|
: `<button class="btn tiny" id="btn-retire">退休</button>`
|
|
2357
2365
|
}
|
|
2366
|
+
<button class="btn tiny danger" id="btn-purge">彻底删除</button>
|
|
2358
2367
|
</div>
|
|
2359
2368
|
${lineageHtml(card)}
|
|
2360
2369
|
${
|
|
@@ -2391,7 +2400,14 @@ function renderInspector() {
|
|
|
2391
2400
|
toast('复制失败,浏览器不给剪贴板权限', true);
|
|
2392
2401
|
}
|
|
2393
2402
|
});
|
|
2394
|
-
//
|
|
2403
|
+
// 详情栏也能直接删:二次确认 + 10 秒撤销,和回收站里是同一套
|
|
2404
|
+
const purgeBtn = $('#btn-purge');
|
|
2405
|
+
if (purgeBtn) {
|
|
2406
|
+
purgeBtn.addEventListener('click', async () => {
|
|
2407
|
+
const n = await purgeWithUndo([card.id]);
|
|
2408
|
+
if (n) await load();
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2395
2411
|
const retireBtn = $('#btn-retire');
|
|
2396
2412
|
if (retireBtn) {
|
|
2397
2413
|
retireBtn.addEventListener('click', async () => {
|