cortico-world-memory-core 0.15.0 → 0.18.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 +41 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/config.ts +18 -0
- package/src/store.ts +4 -0
- package/src/world.ts +151 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
把她独处时想的东西,接进记忆和主动开口。
|
|
6
|
+
|
|
7
|
+
- **重要的进记忆**:她自己标成 8 分以上的想法,会收成一张 `self` 卡片、打上「独处」标签、上星图。
|
|
8
|
+
文本前面加「独处时写下:」——**不然它会以卡片身份进上下文,被当成此刻的想法,那又变成替她认领了**。
|
|
9
|
+
只收 24 小时内的;同一个 id 不重复收。
|
|
10
|
+
- **主动开口有了由头**:以前由头是「几点几分、你在干嘛、精力多少」,现在多一句
|
|
11
|
+
「你刚才一个人在想的:…」(1.5 小时内、还没被用过的那条)。想得越具体,开口越像真有话说。
|
|
12
|
+
- 新开关 `absorbSelfThought`(默认开)。
|
|
13
|
+
- 测试 28(7 项):收 8 分以上不收 4 分、带「独处时写下」、带标签、只写一张、不重复收、只记收下的 id。
|
|
14
|
+
|
|
15
|
+
## 0.17.0
|
|
16
|
+
## 0.17.0
|
|
17
|
+
|
|
18
|
+
按她自己的意见改的。三条都成立,第三条是根本问题。
|
|
19
|
+
|
|
20
|
+
- **不再冒充回忆**:原来写「你一个人待着的时候想过:…」。但那句话是另一次调用产出的,她并没有经历那个思考过程——说成回忆,就是拿一段别人写的文字逼她认领。现在改成
|
|
21
|
+
`(22:31 你一个人时在本子上写过:…——不一定是你现在的想法,看着用。)`
|
|
22
|
+
从「我的回忆」降级为「我写过的东西」,并且明确免责。
|
|
23
|
+
- **窗口 6 小时 → 2 小时**:攒太久就过时了,那时候连「当时什么感觉」都不成立。
|
|
24
|
+
- **夜间整理不再逼产出**:去掉「最多写 3 条」,改成「记过的不用再记,漏了的补一条就行,不用凑数」。
|
|
25
|
+
原来那句是数量压力,模型收到「要求产出 + 空白素材」最容易编。
|
|
26
|
+
- 新增开关「带上她独处时写下的话」(默认开)。关掉就只是本地记录,永远不进对话。
|
|
27
|
+
- 测试:15 改断言(不再要求「最多 3 条」)、26 加两条(免责声明、时间戳)、新增 27(2 小时窗口 + 开关)。
|
|
28
|
+
|
|
29
|
+
## 0.16.0
|
|
30
|
+
## 0.16.0
|
|
31
|
+
|
|
32
|
+
和「自我意识」插件对接:**她一个人待着时想过的事,会在你开口时被带进来。**
|
|
33
|
+
|
|
34
|
+
- 预激活多一段:`(你一个人待着的时候想过:…)`。素材读同级目录的 `self-awareness/thoughts.jsonl`。
|
|
35
|
+
- 挑哪一条:先看和对方这句话有没有词面重叠(重叠算两分),再看新鲜度(一分);**6 小时以外的不带**。
|
|
36
|
+
- **一句都不沾边就不带**(除非是半小时内刚想的)。实测过:问「帖子怎么样」却答「我想起你说的错字」,比不想还怪。
|
|
37
|
+
- 同一条想法只推一次,记在 `state.lastSelfThoughtId`。没装那个插件就跳过,不报错。
|
|
38
|
+
- 顺手修了个拦路的:以前 `if (!picked.length) return`,卡片一条都没命中就整段不推——现在只要有想法照样推。
|
|
39
|
+
- 测试 26(4 项):想法进预激活、带的是正文、记住已推哪条、换轮对话不重复推。
|
|
40
|
+
|
|
41
|
+
常驻 token 不变;只在真有想法时多约 25 token。
|
|
42
|
+
|
|
43
|
+
## 0.15.0
|
|
3
44
|
## 0.15.0
|
|
4
45
|
|
|
5
46
|
一个用户反馈:「它记的是事实和承诺,那些零碎的口气,还得我自己往本子上写。」
|
package/README.md
CHANGED
|
@@ -30,7 +30,9 @@ 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 天的对话原文和工作区笔记;装了「自我意识」插件的话,对方一开口还会顺带带上她独处时写下的一句:**标明时间、说明「不一定是你现在的想法」、2 小时内、同一条只推一次**。这一项可以在设置里关掉(`shareSelfThought`),关掉就只是本地记录。
|
|
34
|
+
|
|
35
|
+
结果分两档:「对得上」和「可能沾边,别当准」;带 `↩` 的是改写过的记忆 + 当时那句原话的日期;给 `id` 可以看这条记忆的出处(当时那句原话 + 前后文);`mode=voice` 返回几句对方的原话,用来听语气(卡片记不住口气,样本才行);`mode=open` 看没做完的承诺和今天的安排;`mode=archive` 翻更早的归档原文 |
|
|
34
36
|
| `mcore_state` | 角色自己的精力 / 心情 / 正在做什么 / 在哪 / 睡没睡 |
|
|
35
37
|
| `mcore_plan` | 今天的日程(增、勾、清空) |
|
|
36
38
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-memory-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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
|
@@ -104,6 +104,10 @@ export const MEMORY_CORE_DEFAULTS: MemoryCoreConfig = {
|
|
|
104
104
|
recallMaxChars: 600,
|
|
105
105
|
recallUseAging: true,
|
|
106
106
|
preactivateLines: 2,
|
|
107
|
+
/** 对方开口时,把「自我意识」插件独处时写下的那一句带进上下文。 */
|
|
108
|
+
shareSelfThought: true,
|
|
109
|
+
/** 把她独处时特别在意的那些(重要度 8 以上)写成 self 卡片,进星图。 */
|
|
110
|
+
absorbSelfThought: true,
|
|
107
111
|
chillAfterDays: 30,
|
|
108
112
|
contextEveryMin: 0,
|
|
109
113
|
nightlyConsolidate: true,
|
|
@@ -184,6 +188,18 @@ const RAW_GROUP: ConfigGroup = {
|
|
|
184
188
|
description: '关掉后不再读写卡片,已有记录仍留在数据目录。',
|
|
185
189
|
'x-hot': true,
|
|
186
190
|
},
|
|
191
|
+
'worlds.memory-core.shareSelfThought': {
|
|
192
|
+
type: 'boolean',
|
|
193
|
+
title: '带上她独处时写下的话',
|
|
194
|
+
description: '对方开口时,把她一个人待着时写在本子上的一句带进上下文——会标明时间,也会说明「不一定是你现在的想法」。关掉就只是本地记录,永远不进对话。',
|
|
195
|
+
default: true,
|
|
196
|
+
},
|
|
197
|
+
'worlds.memory-core.absorbSelfThought': {
|
|
198
|
+
type: 'boolean',
|
|
199
|
+
title: '独处时的想法进记忆',
|
|
200
|
+
description: '她独处时写下的、她自己标成「很重要」的那些(8 分以上),会收成一条「关于她自己」的记忆,出现在星图上。卡片里会写清「独处时写下」,不会被当成此刻的想法。',
|
|
201
|
+
default: true,
|
|
202
|
+
},
|
|
187
203
|
'worlds.memory-core.captureTurns': {
|
|
188
204
|
type: 'boolean',
|
|
189
205
|
title: '存对话原文',
|
|
@@ -285,6 +301,8 @@ const SETTINGS_ORDER = [
|
|
|
285
301
|
'worlds.memory-core.siteEnabled',
|
|
286
302
|
'worlds.memory-core.sitePort',
|
|
287
303
|
'worlds.memory-core.preactivateLines',
|
|
304
|
+
'worlds.memory-core.shareSelfThought',
|
|
305
|
+
'worlds.memory-core.absorbSelfThought',
|
|
288
306
|
'worlds.memory-core.captureTurns',
|
|
289
307
|
'worlds.memory-core.captureAll',
|
|
290
308
|
'worlds.memory-core.captureSenders',
|
package/src/store.ts
CHANGED
|
@@ -85,6 +85,10 @@ export interface CoreState {
|
|
|
85
85
|
nightlyPending?: { day: string; text: string };
|
|
86
86
|
/** 冷层每天只判一次,记下今天判过了。 */
|
|
87
87
|
lastChillDay?: string;
|
|
88
|
+
/** 自我意识插件写过的那条想法,已经推给主模型了——别每轮都推同一条。 */
|
|
89
|
+
lastSelfThoughtId?: string;
|
|
90
|
+
/** 已经收成卡片的想法 id(只留最近 100 个,够防重复了)。 */
|
|
91
|
+
absorbedThoughtIds?: string[];
|
|
88
92
|
rawWatermark?: number;
|
|
89
93
|
/** 水位是按哪一版捕获逻辑推进的。旧版用了错的 range 语义,水位不可信,见 CAPTURE_WATERMARK_VERSION。 */
|
|
90
94
|
watermarkVersion?: number;
|
package/src/world.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 2) 不每轮推送状态,只有 contextEveryMin>0 才推,默认 0;
|
|
8
8
|
* 3) 主动开口有「对方最近说过话」这道闸,避免对着空房间调用模型。
|
|
9
9
|
*/
|
|
10
|
-
import { existsSync } from 'node:fs';
|
|
10
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
12
|
import { join } from 'node:path';
|
|
13
13
|
import { randomUUID } from 'node:crypto';
|
|
@@ -1160,6 +1160,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1160
1160
|
Boolean(this.cfg().captureBackfill)
|
|
1161
1161
|
&& (Number(this.state.watermarkVersion ?? 0) < CAPTURE_WATERMARK_VERSION || !this.state.backfillDoneAt),
|
|
1162
1162
|
);
|
|
1163
|
+
this.absorbThoughts(now);
|
|
1163
1164
|
await this.maybeContext(now);
|
|
1164
1165
|
await this.maybePreactivate(now);
|
|
1165
1166
|
await this.maybeRemind(now);
|
|
@@ -1404,18 +1405,144 @@ export class MemoryCoreWorld implements World {
|
|
|
1404
1405
|
})
|
|
1405
1406
|
.slice(0, lines)
|
|
1406
1407
|
.map((x) => x.card);
|
|
1407
|
-
|
|
1408
|
+
// 她一个人待着时写下的那句:优先挑和这句话沾边的那条。
|
|
1409
|
+
// 措辞是「写过」不是「想过」——那句话是另一次调用产出的,她并没有真的经历那个思考过程,
|
|
1410
|
+
// 说成回忆就是在逼她认领一段不存在的经历。
|
|
1411
|
+
const think = this.cfg().shareSelfThought === false ? null : this.pickSelfThought(now, turn.text);
|
|
1412
|
+
if (!picked.length && !think) return;
|
|
1408
1413
|
|
|
1409
1414
|
const tz = this.tz();
|
|
1410
|
-
const
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
)
|
|
1415
|
+
const parts: string[] = [];
|
|
1416
|
+
if (think) {
|
|
1417
|
+
const when = think.ts ? formatLocal(think.ts, tz).slice(11, 16) : '';
|
|
1418
|
+
parts.push(`(${when ? `${when} ` : ''}你一个人时在本子上写过:${clip(think.text, 70)}——不一定是你现在的想法,看着用。)`);
|
|
1419
|
+
}
|
|
1420
|
+
if (picked.length) {
|
|
1421
|
+
const body = picked.map((c) => `· ${clip(c.text, 60)}(${formatLocal(c.createdAt, tz).slice(5, 10)})`).join('\n');
|
|
1422
|
+
parts.push(`(你想起几件事(不是对方刚说的),合适就用,别当清单念:\n${body})`);
|
|
1423
|
+
}
|
|
1424
|
+
const ok = await this.push('mcore.prime', parts.join('\n'), 'piggyback');
|
|
1416
1425
|
if (!ok) return;
|
|
1417
1426
|
this.primedFor = key;
|
|
1418
|
-
this.store.prime(picked.map((c) => c.id));
|
|
1427
|
+
if (picked.length) this.store.prime(picked.map((c) => c.id));
|
|
1428
|
+
if (think) {
|
|
1429
|
+
// 记下来,同一条想法只推一次;错过了就等她自己再想一条
|
|
1430
|
+
this.state.lastSelfThoughtId = think.id;
|
|
1431
|
+
this.save();
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
/** 读最近的想法原文,按时间倒序。没装那个插件就返回空数组。 */
|
|
1436
|
+
private readThoughts(limit = 40): { id: string; ts: string; text: string; importance: number }[] {
|
|
1437
|
+
const file = join(this.dataDir, '..', 'self-awareness', 'thoughts.jsonl');
|
|
1438
|
+
if (!existsSync(file)) return [];
|
|
1439
|
+
let lines: string[] = [];
|
|
1440
|
+
try {
|
|
1441
|
+
lines = readFileSync(file, 'utf8').split('\n').filter(Boolean).slice(-limit);
|
|
1442
|
+
} catch {
|
|
1443
|
+
return [];
|
|
1444
|
+
}
|
|
1445
|
+
const out: { id: string; ts: string; text: string; importance: number }[] = [];
|
|
1446
|
+
for (const line of lines) {
|
|
1447
|
+
try {
|
|
1448
|
+
const t = JSON.parse(line) as { id?: string; ts?: string; text?: string; importance?: number };
|
|
1449
|
+
if (!t.text) continue;
|
|
1450
|
+
out.push({
|
|
1451
|
+
id: String(t.id ?? ''),
|
|
1452
|
+
ts: String(t.ts ?? ''),
|
|
1453
|
+
text: String(t.text),
|
|
1454
|
+
importance: Number(t.importance) || 0,
|
|
1455
|
+
});
|
|
1456
|
+
} catch {
|
|
1457
|
+
// 坏行跳过
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
return out.reverse();
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
/**
|
|
1464
|
+
* 把「她自己标成很重要」的想法收成一张 self 卡片。
|
|
1465
|
+
* 文本前面加「独处时写下」——不然它会以卡片的身份进上下文,被当成此刻的想法,
|
|
1466
|
+
* 那又变成替她认领了。
|
|
1467
|
+
*/
|
|
1468
|
+
private absorbThoughts(now: Date): void {
|
|
1469
|
+
if (this.cfg().absorbSelfThought === false) return;
|
|
1470
|
+
const done = new Set(this.state.absorbedThoughtIds ?? []);
|
|
1471
|
+
const fresh = this.readThoughts(40).filter((t) => t.importance >= 8 && t.id && !done.has(t.id));
|
|
1472
|
+
if (!fresh.length) return;
|
|
1473
|
+
let added = 0;
|
|
1474
|
+
for (const t of fresh.slice(0, 3)) {
|
|
1475
|
+
const age = now.getTime() - (Date.parse(t.ts) || 0);
|
|
1476
|
+
// 太旧的想法别补写进来,那是在翻旧账
|
|
1477
|
+
const freshEnough = !Number.isFinite(age) || age < 24 * 3_600_000;
|
|
1478
|
+
if (freshEnough) {
|
|
1479
|
+
const text = clip(`独处时写下:${t.text}`, 200);
|
|
1480
|
+
this.store.add({
|
|
1481
|
+
kind: 'self',
|
|
1482
|
+
text,
|
|
1483
|
+
weight: 0.6,
|
|
1484
|
+
// 打个标签:星图的航道(跨区同标签连线)和图例才认得出来这是「独处」来的
|
|
1485
|
+
tags: ['独处'],
|
|
1486
|
+
source: 'self-awareness',
|
|
1487
|
+
origin: 'tool',
|
|
1488
|
+
});
|
|
1489
|
+
added += 1;
|
|
1490
|
+
}
|
|
1491
|
+
done.add(t.id);
|
|
1492
|
+
}
|
|
1493
|
+
this.state.absorbedThoughtIds = [...done].slice(-100);
|
|
1494
|
+
if (added) {
|
|
1495
|
+
try {
|
|
1496
|
+
this.host?.log?.info?.('[memory-core] 收下了她独处时的想法', { count: added });
|
|
1497
|
+
} catch {
|
|
1498
|
+
// ignore
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
/**
|
|
1504
|
+
* 从自我意识插件的 thoughts.jsonl 里挑一条。
|
|
1505
|
+
* 选法:和对方刚说的话有词面重叠的优先,其次挑新鲜的;6 小时以外的不要。
|
|
1506
|
+
* 没装那个插件就返回 null,不报错。
|
|
1507
|
+
*/
|
|
1508
|
+
private pickSelfThought(now: Date, query: string): { id: string; text: string; ts: string } | null {
|
|
1509
|
+
const file = join(this.dataDir, '..', 'self-awareness', 'thoughts.jsonl');
|
|
1510
|
+
if (!existsSync(file)) return null;
|
|
1511
|
+
let lines: string[] = [];
|
|
1512
|
+
try {
|
|
1513
|
+
lines = readFileSync(file, 'utf8').split('\n').filter(Boolean).slice(-20);
|
|
1514
|
+
} catch {
|
|
1515
|
+
return null;
|
|
1516
|
+
}
|
|
1517
|
+
if (!lines.length) return null;
|
|
1518
|
+
|
|
1519
|
+
const qTokens = new Set(tokenize(query).filter(isContentToken));
|
|
1520
|
+
let best: { id: string; text: string; ts: string; score: number } | null = null;
|
|
1521
|
+
for (const line of lines) {
|
|
1522
|
+
let t: { id?: string; ts?: string; text?: string };
|
|
1523
|
+
try {
|
|
1524
|
+
t = JSON.parse(line) as typeof t;
|
|
1525
|
+
} catch {
|
|
1526
|
+
continue;
|
|
1527
|
+
}
|
|
1528
|
+
if (!t.text) continue;
|
|
1529
|
+
const at = Date.parse(String(t.ts ?? ''));
|
|
1530
|
+
if (!Number.isFinite(at)) continue;
|
|
1531
|
+
// 2 小时:攒太久就过时了——那时候连「当时什么感觉」都不成立了
|
|
1532
|
+
const ageH = (now.getTime() - at) / 3_600_000;
|
|
1533
|
+
if (ageH > 2) continue;
|
|
1534
|
+
if (t.id && t.id === this.state.lastSelfThoughtId) continue;
|
|
1535
|
+
let hit = 0;
|
|
1536
|
+
for (const tok of tokenize(String(t.text)).filter(isContentToken)) if (qTokens.has(tok)) hit += 1;
|
|
1537
|
+
// 一句都不沾边就别硬塞:问「帖子怎么样」却答「我想起你说的错字」,比不想还怪。
|
|
1538
|
+
// 唯一的例外是刚想的(半小时内)——那确实还在脑子里,冒出来是自然的。
|
|
1539
|
+
if (hit === 0 && ageH > 0.5) continue;
|
|
1540
|
+
const score = hit * 2 + Math.max(0, 1 - ageH / 2);
|
|
1541
|
+
if (!best || score > best.score) {
|
|
1542
|
+
best = { id: String(t.id ?? ''), text: String(t.text), ts: String(t.ts ?? ''), score };
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
return best ? { id: best.id, text: best.text, ts: best.ts } : null;
|
|
1419
1546
|
}
|
|
1420
1547
|
|
|
1421
1548
|
private async maybeRemind(now: Date): Promise<void> {
|
|
@@ -1473,10 +1600,23 @@ export class MemoryCoreWorld implements World {
|
|
|
1473
1600
|
|
|
1474
1601
|
const since = lastUser ? humanSpan(now.getTime() - lastUser) : null;
|
|
1475
1602
|
const reason = this.reasonFor(now);
|
|
1603
|
+
// 刚一个人想过什么,是比「几点几分」更好的由头
|
|
1604
|
+
const think = this.cfg().shareSelfThought === false
|
|
1605
|
+
? null
|
|
1606
|
+
: this.readThoughts(10).find((t) => {
|
|
1607
|
+
if (t.id && t.id === this.state.lastSelfThoughtId) return false;
|
|
1608
|
+
const age = now.getTime() - (Date.parse(t.ts) || 0);
|
|
1609
|
+
return Number.isFinite(age) && age < 1.5 * 3_600_000;
|
|
1610
|
+
}) ?? null;
|
|
1611
|
+
const thinkLine = think ? `\n(你刚才一个人在想的:${clip(think.text, 60)})` : '';
|
|
1476
1612
|
const text = `(由头:${formatLocal(now, this.tz()).slice(11)},你${this.state.activity}`
|
|
1477
1613
|
+ `${this.state.location ? `,在${this.state.location}` : ''},精力 ${Math.round(this.state.energy)}`
|
|
1478
|
-
+ `${since ? `;上次说话是 ${since} 前` : ''}。${reason})想主动跟对方说一句,别问「在吗」,直接说你此刻的事。`;
|
|
1614
|
+
+ `${since ? `;上次说话是 ${since} 前` : ''}。${reason}${thinkLine})想主动跟对方说一句,别问「在吗」,直接说你此刻的事。`;
|
|
1479
1615
|
const ok = await this.push('mcore.wake', text, 'flush');
|
|
1616
|
+
if (ok && think) {
|
|
1617
|
+
this.state.lastSelfThoughtId = think.id;
|
|
1618
|
+
this.save();
|
|
1619
|
+
}
|
|
1480
1620
|
if (!ok) {
|
|
1481
1621
|
defer(15);
|
|
1482
1622
|
return;
|
|
@@ -1548,7 +1688,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1548
1688
|
}
|
|
1549
1689
|
const ok = await this.push(
|
|
1550
1690
|
'mcore.nightly',
|
|
1551
|
-
|
|
1691
|
+
`(昨天留下的这些,你翻一下:记过的不用再记,漏了的补一条就行,不用凑数。规矩不变:能写成 fact 就别写成 episode,有承诺就带 dueAt。\n${pending.text})`,
|
|
1552
1692
|
'piggyback',
|
|
1553
1693
|
);
|
|
1554
1694
|
if (!ok) return;
|