cortico-world-memory-core 0.15.0 → 0.17.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 +28 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/config.ts +9 -0
- package/src/store.ts +2 -0
- package/src/world.ts +68 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
按她自己的意见改的。三条都成立,第三条是根本问题。
|
|
6
|
+
|
|
7
|
+
- **不再冒充回忆**:原来写「你一个人待着的时候想过:…」。但那句话是另一次调用产出的,她并没有经历那个思考过程——说成回忆,就是拿一段别人写的文字逼她认领。现在改成
|
|
8
|
+
`(22:31 你一个人时在本子上写过:…——不一定是你现在的想法,看着用。)`
|
|
9
|
+
从「我的回忆」降级为「我写过的东西」,并且明确免责。
|
|
10
|
+
- **窗口 6 小时 → 2 小时**:攒太久就过时了,那时候连「当时什么感觉」都不成立。
|
|
11
|
+
- **夜间整理不再逼产出**:去掉「最多写 3 条」,改成「记过的不用再记,漏了的补一条就行,不用凑数」。
|
|
12
|
+
原来那句是数量压力,模型收到「要求产出 + 空白素材」最容易编。
|
|
13
|
+
- 新增开关「带上她独处时写下的话」(默认开)。关掉就只是本地记录,永远不进对话。
|
|
14
|
+
- 测试:15 改断言(不再要求「最多 3 条」)、26 加两条(免责声明、时间戳)、新增 27(2 小时窗口 + 开关)。
|
|
15
|
+
|
|
16
|
+
## 0.16.0
|
|
17
|
+
## 0.16.0
|
|
18
|
+
|
|
19
|
+
和「自我意识」插件对接:**她一个人待着时想过的事,会在你开口时被带进来。**
|
|
20
|
+
|
|
21
|
+
- 预激活多一段:`(你一个人待着的时候想过:…)`。素材读同级目录的 `self-awareness/thoughts.jsonl`。
|
|
22
|
+
- 挑哪一条:先看和对方这句话有没有词面重叠(重叠算两分),再看新鲜度(一分);**6 小时以外的不带**。
|
|
23
|
+
- **一句都不沾边就不带**(除非是半小时内刚想的)。实测过:问「帖子怎么样」却答「我想起你说的错字」,比不想还怪。
|
|
24
|
+
- 同一条想法只推一次,记在 `state.lastSelfThoughtId`。没装那个插件就跳过,不报错。
|
|
25
|
+
- 顺手修了个拦路的:以前 `if (!picked.length) return`,卡片一条都没命中就整段不推——现在只要有想法照样推。
|
|
26
|
+
- 测试 26(4 项):想法进预激活、带的是正文、记住已推哪条、换轮对话不重复推。
|
|
27
|
+
|
|
28
|
+
常驻 token 不变;只在真有想法时多约 25 token。
|
|
29
|
+
|
|
30
|
+
## 0.15.0
|
|
3
31
|
## 0.15.0
|
|
4
32
|
|
|
5
33
|
一个用户反馈:「它记的是事实和承诺,那些零碎的口气,还得我自己往本子上写。」
|
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.17.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,8 @@ export const MEMORY_CORE_DEFAULTS: MemoryCoreConfig = {
|
|
|
104
104
|
recallMaxChars: 600,
|
|
105
105
|
recallUseAging: true,
|
|
106
106
|
preactivateLines: 2,
|
|
107
|
+
/** 对方开口时,把「自我意识」插件独处时写下的那一句带进上下文。 */
|
|
108
|
+
shareSelfThought: true,
|
|
107
109
|
chillAfterDays: 30,
|
|
108
110
|
contextEveryMin: 0,
|
|
109
111
|
nightlyConsolidate: true,
|
|
@@ -184,6 +186,12 @@ const RAW_GROUP: ConfigGroup = {
|
|
|
184
186
|
description: '关掉后不再读写卡片,已有记录仍留在数据目录。',
|
|
185
187
|
'x-hot': true,
|
|
186
188
|
},
|
|
189
|
+
'worlds.memory-core.shareSelfThought': {
|
|
190
|
+
type: 'boolean',
|
|
191
|
+
title: '带上她独处时写下的话',
|
|
192
|
+
description: '对方开口时,把她一个人待着时写在本子上的一句带进上下文——会标明时间,也会说明「不一定是你现在的想法」。关掉就只是本地记录,永远不进对话。',
|
|
193
|
+
default: true,
|
|
194
|
+
},
|
|
187
195
|
'worlds.memory-core.captureTurns': {
|
|
188
196
|
type: 'boolean',
|
|
189
197
|
title: '存对话原文',
|
|
@@ -285,6 +293,7 @@ const SETTINGS_ORDER = [
|
|
|
285
293
|
'worlds.memory-core.siteEnabled',
|
|
286
294
|
'worlds.memory-core.sitePort',
|
|
287
295
|
'worlds.memory-core.preactivateLines',
|
|
296
|
+
'worlds.memory-core.shareSelfThought',
|
|
288
297
|
'worlds.memory-core.captureTurns',
|
|
289
298
|
'worlds.memory-core.captureAll',
|
|
290
299
|
'worlds.memory-core.captureSenders',
|
package/src/store.ts
CHANGED
|
@@ -85,6 +85,8 @@ export interface CoreState {
|
|
|
85
85
|
nightlyPending?: { day: string; text: string };
|
|
86
86
|
/** 冷层每天只判一次,记下今天判过了。 */
|
|
87
87
|
lastChillDay?: string;
|
|
88
|
+
/** 自我意识插件写过的那条想法,已经推给主模型了——别每轮都推同一条。 */
|
|
89
|
+
lastSelfThoughtId?: string;
|
|
88
90
|
rawWatermark?: number;
|
|
89
91
|
/** 水位是按哪一版捕获逻辑推进的。旧版用了错的 range 语义,水位不可信,见 CAPTURE_WATERMARK_VERSION。 */
|
|
90
92
|
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';
|
|
@@ -1404,18 +1404,76 @@ export class MemoryCoreWorld implements World {
|
|
|
1404
1404
|
})
|
|
1405
1405
|
.slice(0, lines)
|
|
1406
1406
|
.map((x) => x.card);
|
|
1407
|
-
|
|
1407
|
+
// 她一个人待着时写下的那句:优先挑和这句话沾边的那条。
|
|
1408
|
+
// 措辞是「写过」不是「想过」——那句话是另一次调用产出的,她并没有真的经历那个思考过程,
|
|
1409
|
+
// 说成回忆就是在逼她认领一段不存在的经历。
|
|
1410
|
+
const think = this.cfg().shareSelfThought === false ? null : this.pickSelfThought(now, turn.text);
|
|
1411
|
+
if (!picked.length && !think) return;
|
|
1408
1412
|
|
|
1409
1413
|
const tz = this.tz();
|
|
1410
|
-
const
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
)
|
|
1414
|
+
const parts: string[] = [];
|
|
1415
|
+
if (think) {
|
|
1416
|
+
const when = think.ts ? formatLocal(think.ts, tz).slice(11, 16) : '';
|
|
1417
|
+
parts.push(`(${when ? `${when} ` : ''}你一个人时在本子上写过:${clip(think.text, 70)}——不一定是你现在的想法,看着用。)`);
|
|
1418
|
+
}
|
|
1419
|
+
if (picked.length) {
|
|
1420
|
+
const body = picked.map((c) => `· ${clip(c.text, 60)}(${formatLocal(c.createdAt, tz).slice(5, 10)})`).join('\n');
|
|
1421
|
+
parts.push(`(你想起几件事(不是对方刚说的),合适就用,别当清单念:\n${body})`);
|
|
1422
|
+
}
|
|
1423
|
+
const ok = await this.push('mcore.prime', parts.join('\n'), 'piggyback');
|
|
1416
1424
|
if (!ok) return;
|
|
1417
1425
|
this.primedFor = key;
|
|
1418
|
-
this.store.prime(picked.map((c) => c.id));
|
|
1426
|
+
if (picked.length) this.store.prime(picked.map((c) => c.id));
|
|
1427
|
+
if (think) {
|
|
1428
|
+
// 记下来,同一条想法只推一次;错过了就等她自己再想一条
|
|
1429
|
+
this.state.lastSelfThoughtId = think.id;
|
|
1430
|
+
this.save();
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
/**
|
|
1435
|
+
* 从自我意识插件的 thoughts.jsonl 里挑一条。
|
|
1436
|
+
* 选法:和对方刚说的话有词面重叠的优先,其次挑新鲜的;6 小时以外的不要。
|
|
1437
|
+
* 没装那个插件就返回 null,不报错。
|
|
1438
|
+
*/
|
|
1439
|
+
private pickSelfThought(now: Date, query: string): { id: string; text: string; ts: string } | null {
|
|
1440
|
+
const file = join(this.dataDir, '..', 'self-awareness', 'thoughts.jsonl');
|
|
1441
|
+
if (!existsSync(file)) return null;
|
|
1442
|
+
let lines: string[] = [];
|
|
1443
|
+
try {
|
|
1444
|
+
lines = readFileSync(file, 'utf8').split('\n').filter(Boolean).slice(-20);
|
|
1445
|
+
} catch {
|
|
1446
|
+
return null;
|
|
1447
|
+
}
|
|
1448
|
+
if (!lines.length) return null;
|
|
1449
|
+
|
|
1450
|
+
const qTokens = new Set(tokenize(query).filter(isContentToken));
|
|
1451
|
+
let best: { id: string; text: string; ts: string; score: number } | null = null;
|
|
1452
|
+
for (const line of lines) {
|
|
1453
|
+
let t: { id?: string; ts?: string; text?: string };
|
|
1454
|
+
try {
|
|
1455
|
+
t = JSON.parse(line) as typeof t;
|
|
1456
|
+
} catch {
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
if (!t.text) continue;
|
|
1460
|
+
const at = Date.parse(String(t.ts ?? ''));
|
|
1461
|
+
if (!Number.isFinite(at)) continue;
|
|
1462
|
+
// 2 小时:攒太久就过时了——那时候连「当时什么感觉」都不成立了
|
|
1463
|
+
const ageH = (now.getTime() - at) / 3_600_000;
|
|
1464
|
+
if (ageH > 2) continue;
|
|
1465
|
+
if (t.id && t.id === this.state.lastSelfThoughtId) continue;
|
|
1466
|
+
let hit = 0;
|
|
1467
|
+
for (const tok of tokenize(String(t.text)).filter(isContentToken)) if (qTokens.has(tok)) hit += 1;
|
|
1468
|
+
// 一句都不沾边就别硬塞:问「帖子怎么样」却答「我想起你说的错字」,比不想还怪。
|
|
1469
|
+
// 唯一的例外是刚想的(半小时内)——那确实还在脑子里,冒出来是自然的。
|
|
1470
|
+
if (hit === 0 && ageH > 0.5) continue;
|
|
1471
|
+
const score = hit * 2 + Math.max(0, 1 - ageH / 2);
|
|
1472
|
+
if (!best || score > best.score) {
|
|
1473
|
+
best = { id: String(t.id ?? ''), text: String(t.text), ts: String(t.ts ?? ''), score };
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
return best ? { id: best.id, text: best.text, ts: best.ts } : null;
|
|
1419
1477
|
}
|
|
1420
1478
|
|
|
1421
1479
|
private async maybeRemind(now: Date): Promise<void> {
|
|
@@ -1548,7 +1606,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1548
1606
|
}
|
|
1549
1607
|
const ok = await this.push(
|
|
1550
1608
|
'mcore.nightly',
|
|
1551
|
-
|
|
1609
|
+
`(昨天留下的这些,你翻一下:记过的不用再记,漏了的补一条就行,不用凑数。规矩不变:能写成 fact 就别写成 episode,有承诺就带 dueAt。\n${pending.text})`,
|
|
1552
1610
|
'piggyback',
|
|
1553
1611
|
);
|
|
1554
1612
|
if (!ok) return;
|