cortico-world-memory-core 0.21.1 → 0.23.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 +29 -0
- package/README.md +2 -0
- package/package.json +2 -2
- package/src/store.ts +4 -0
- package/src/world.ts +82 -4
- package/webui/app.js +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.23.0
|
|
4
|
+
|
|
5
|
+
> 墓碑对齐需要自我意识 **0.10.0** 及以上;旧版不写墓碑,只是不会自动撤卡。
|
|
6
|
+
|
|
7
|
+
**能直接删了,退休不再是唯一出口。**
|
|
8
|
+
|
|
9
|
+
- 详情栏「退休」旁边加了「彻底删除」:二次确认 + 10 秒撤销,和回收站里是同一套。
|
|
10
|
+
在用的卡不用先退休、再去回收站找。
|
|
11
|
+
- 从自我意识收下想法时记 `srcThoughtId`。她删掉那条想法后,墓碑写在
|
|
12
|
+
`../self-awareness/deleted-thoughts.jsonl`,这边下一次周期清理会撤回对应卡片。
|
|
13
|
+
只认带来源 id 的新卡片;更早的没有 id,手动删。
|
|
14
|
+
- 测试新增 `tools/test-delete.ts` 2 项:按墓碑撤回、无关卡片不动。
|
|
15
|
+
|
|
16
|
+
## 0.22.0
|
|
17
|
+
|
|
18
|
+
> 需要自我意识 **0.9.0** 及以上,才有人写冲动;单独升级这一边不会报错,只是没有可读的东西。
|
|
19
|
+
|
|
20
|
+
**她会「想说话」了,但还是不发声。**
|
|
21
|
+
|
|
22
|
+
自我意识插件在对方安静下来后,会把「想说一句」写成一条本地冲动(4–45 分钟的窗口里,每段沉默只写一条);
|
|
23
|
+
记忆核心读到之后,可以不等原定的一百分钟,提前替她开口。
|
|
24
|
+
|
|
25
|
+
- 读 `../self-awareness/urges.jsonl`:30 分钟内、没用过的那条才算数。
|
|
26
|
+
- 有冲动时,「下次开口」提前到当前;静默门从默认 20 分钟放宽到最多 6 分钟——她刚想说,但也别追着人说话。
|
|
27
|
+
- 由头换成她的原话:`(你刚才一个人在想的:…;他已经 10 分钟没说话了)`,比「几点了」具体。
|
|
28
|
+
- 用过记 `lastUrgeId`,同一条不会反复推。
|
|
29
|
+
- 睡眠 / 免打扰 / 每日上限 / 最近说过话 这几道闸仍然有效。
|
|
30
|
+
- 测试 `tools/test-urge.ts` 5 项:有冲动会提前开口、由头带原话与静默时长、用过记下、没冲动不开口。
|
|
31
|
+
|
|
3
32
|
## 0.21.1
|
|
4
33
|
|
|
5
34
|
**浅色模式里还剩几块是深色的。** 不是配色没调好,是当初把底色写死了——切主题时这些地方不会跟着变。
|
package/README.md
CHANGED
|
@@ -97,6 +97,8 @@ pnpm add cortico-world-memory-core
|
|
|
97
97
|
1. `envPromptVars()` 只回常量 —— 前缀永远不变,缓存不会因为「今天主动了几次」被冲掉。
|
|
98
98
|
2. 默认不每轮推送状态;要就开 `contextEveryMin`。
|
|
99
99
|
3. 主动开口先看对方最近 8 小时说过话没有,没有就只把 `dueAt` 往后推,不调模型。
|
|
100
|
+
4. 如果自我意识插件写了「想说话」(`../self-awareness/urges.jsonl`,30 分钟内、没用过),这一次可以不等原定间隔,
|
|
101
|
+
静默门也放宽到 6 分钟;由头用她的原话。她说「先搁着」时不会写。
|
|
100
102
|
4. 工作区文件检索有 60 秒缓存,只在 `recall` 带 query 时才发生,不增加每轮成本。
|
|
101
103
|
|
|
102
104
|
工具 schema 里不写数值边界(handler 会 clamp),提示词里不重复 schema 已经说清的 kind 定义——两边各说各的,加起来 1,003 tok 左右。`tools/test-upgrade.ts` 最后两项是守门:schema ≤ 2600 字符、提示词 ≤ 480 字,改胖了会红。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-memory-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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-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/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 关旧记录时写)。 */
|
|
@@ -87,6 +89,8 @@ export interface CoreState {
|
|
|
87
89
|
lastChillDay?: string;
|
|
88
90
|
/** 自我意识插件写过的那条想法,已经推给主模型了——别每轮都推同一条。 */
|
|
89
91
|
lastSelfThoughtId?: string;
|
|
92
|
+
/** 自我意识写下的「想说话」已经用来开过口了,别重复。 */
|
|
93
|
+
lastUrgeId?: string;
|
|
90
94
|
/** 已经收成卡片的想法 id(只留最近 100 个,够防重复了)。 */
|
|
91
95
|
absorbedThoughtIds?: string[];
|
|
92
96
|
rawWatermark?: number;
|
package/src/world.ts
CHANGED
|
@@ -1163,6 +1163,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1163
1163
|
Boolean(this.cfg().captureBackfill)
|
|
1164
1164
|
&& (Number(this.state.watermarkVersion ?? 0) < CAPTURE_WATERMARK_VERSION || !this.state.backfillDoneAt),
|
|
1165
1165
|
);
|
|
1166
|
+
this.pruneDeletedThoughts();
|
|
1166
1167
|
this.absorbThoughts(now);
|
|
1167
1168
|
await this.maybeContext(now);
|
|
1168
1169
|
await this.maybePreactivate(now);
|
|
@@ -1436,6 +1437,34 @@ export class MemoryCoreWorld implements World {
|
|
|
1436
1437
|
}
|
|
1437
1438
|
|
|
1438
1439
|
/** 读最近的想法原文,按时间倒序。没装那个插件就返回空数组。 */
|
|
1440
|
+
/**
|
|
1441
|
+
* 她写下的「想说话」:30 分钟内、还没用过的那条。
|
|
1442
|
+
* 没装自我意识插件就返回 null,不报错。
|
|
1443
|
+
*/
|
|
1444
|
+
private readFreshUrge(now: Date): { id: string; text: string; quietMin: number } | null {
|
|
1445
|
+
const file = join(this.dataDir, '..', 'self-awareness', 'urges.jsonl');
|
|
1446
|
+
if (!existsSync(file)) return null;
|
|
1447
|
+
let lines: string[] = [];
|
|
1448
|
+
try {
|
|
1449
|
+
lines = readFileSync(file, 'utf8').split('\n').filter(Boolean).slice(-20);
|
|
1450
|
+
} catch {
|
|
1451
|
+
return null;
|
|
1452
|
+
}
|
|
1453
|
+
for (const line of lines.reverse()) {
|
|
1454
|
+
try {
|
|
1455
|
+
const o = JSON.parse(line) as { id?: string; ts?: string; text?: string; quietMin?: number };
|
|
1456
|
+
if (typeof o.text !== 'string' || !o.text.trim()) continue;
|
|
1457
|
+
if (o.id && o.id === this.state.lastUrgeId) continue;
|
|
1458
|
+
const at = Date.parse(String(o.ts ?? ''));
|
|
1459
|
+
if (!Number.isFinite(at) || now.getTime() - at > 30 * 60_000) continue;
|
|
1460
|
+
return { id: String(o.id ?? ''), text: o.text, quietMin: Number(o.quietMin) || 0 };
|
|
1461
|
+
} catch {
|
|
1462
|
+
// 坏行跳过
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
return null;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1439
1468
|
private readThoughts(limit = 40): { id: string; ts: string; text: string; importance: number }[] {
|
|
1440
1469
|
const file = join(this.dataDir, '..', 'self-awareness', 'thoughts.jsonl');
|
|
1441
1470
|
if (!existsSync(file)) return [];
|
|
@@ -1469,6 +1498,44 @@ export class MemoryCoreWorld implements World {
|
|
|
1469
1498
|
* 文本前面加「独处时写下」——不然它会以卡片的身份进上下文,被当成此刻的想法,
|
|
1470
1499
|
* 那又变成替她认领了。
|
|
1471
1500
|
*/
|
|
1501
|
+
/**
|
|
1502
|
+
* 她删掉的想法,墓碑写在 `deleted-thoughts.jsonl`。
|
|
1503
|
+
* 由那条想法收成的卡片要一起清掉——不然时间线里没了,星图上还挂着。
|
|
1504
|
+
* 只认带 srcThoughtId 的新卡片;老卡片没有来源 id,只能手动删。
|
|
1505
|
+
*/
|
|
1506
|
+
private pruneDeletedThoughts(): void {
|
|
1507
|
+
const file = join(this.dataDir, '..', 'self-awareness', 'deleted-thoughts.jsonl');
|
|
1508
|
+
if (!existsSync(file)) return;
|
|
1509
|
+
const ids = new Set<string>();
|
|
1510
|
+
try {
|
|
1511
|
+
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
1512
|
+
const s = line.trim();
|
|
1513
|
+
if (!s) continue;
|
|
1514
|
+
try {
|
|
1515
|
+
const o = JSON.parse(s) as { id?: unknown };
|
|
1516
|
+
if (typeof o.id === 'string' && o.id) ids.add(o.id);
|
|
1517
|
+
} catch {
|
|
1518
|
+
// 坏行跳过
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
} catch {
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
if (!ids.size) return;
|
|
1525
|
+
const victims = this.store
|
|
1526
|
+
.all()
|
|
1527
|
+
.filter((c) => c.srcThoughtId && ids.has(c.srcThoughtId))
|
|
1528
|
+
.map((c) => c.id);
|
|
1529
|
+
if (victims.length) {
|
|
1530
|
+
this.store.purge(victims);
|
|
1531
|
+
try {
|
|
1532
|
+
this.host?.log?.info?.('[memory-core] 她删了想法,跟着撤回卡片', { count: victims.length });
|
|
1533
|
+
} catch {
|
|
1534
|
+
// ignore
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1472
1539
|
private absorbThoughts(now: Date): void {
|
|
1473
1540
|
if (this.cfg().absorbSelfThought === false) return;
|
|
1474
1541
|
const done = new Set(this.state.absorbedThoughtIds ?? []);
|
|
@@ -1489,6 +1556,7 @@ export class MemoryCoreWorld implements World {
|
|
|
1489
1556
|
tags: ['独处'],
|
|
1490
1557
|
source: 'self-awareness',
|
|
1491
1558
|
origin: 'tool',
|
|
1559
|
+
srcThoughtId: t.id,
|
|
1492
1560
|
});
|
|
1493
1561
|
added += 1;
|
|
1494
1562
|
}
|
|
@@ -1567,7 +1635,10 @@ export class MemoryCoreWorld implements World {
|
|
|
1567
1635
|
const cfg = this.cfg();
|
|
1568
1636
|
if (!cfg.proactiveEnabled) return;
|
|
1569
1637
|
const p = localParts(now, this.tz());
|
|
1570
|
-
|
|
1638
|
+
// 她想说话了:这份冲动可以把「下一次」提前,但仍然要过睡眠/免打扰/上限/静默门
|
|
1639
|
+
const urge = this.cfg().shareSelfThought === false ? null : this.readFreshUrge(now);
|
|
1640
|
+
let due = this.state.proactiveDueAt ? Date.parse(this.state.proactiveDueAt) : 0;
|
|
1641
|
+
if (urge) due = 0;
|
|
1571
1642
|
if (Number.isFinite(due) && due > now.getTime()) return;
|
|
1572
1643
|
|
|
1573
1644
|
const defer = (minutes: number) => {
|
|
@@ -1596,7 +1667,9 @@ export class MemoryCoreWorld implements World {
|
|
|
1596
1667
|
defer(30);
|
|
1597
1668
|
return;
|
|
1598
1669
|
}
|
|
1599
|
-
const
|
|
1670
|
+
const baseGate = Number(cfg.idleGateMin) || 0;
|
|
1671
|
+
// 她刚说「想说话」,就别按 20 分钟等——但也至少要静 6 分钟,别追着人说话
|
|
1672
|
+
const gate = urge ? Math.min(baseGate || 6, 6) : baseGate;
|
|
1600
1673
|
if (lastUser && gate > 0 && now.getTime() - lastUser < gate * 60_000) {
|
|
1601
1674
|
defer(Math.ceil((gate * 60_000 - (now.getTime() - lastUser)) / 60_000) + 1);
|
|
1602
1675
|
return;
|
|
@@ -1612,12 +1685,17 @@ export class MemoryCoreWorld implements World {
|
|
|
1612
1685
|
const age = now.getTime() - (Date.parse(t.ts) || 0);
|
|
1613
1686
|
return Number.isFinite(age) && age < 1.5 * 3_600_000;
|
|
1614
1687
|
}) ?? null;
|
|
1615
|
-
const thinkLine =
|
|
1688
|
+
const thinkLine = urge
|
|
1689
|
+
? `\n(你刚才一个人在想的:${clip(urge.text, 60)};他已经 ${urge.quietMin} 分钟没说话了)`
|
|
1690
|
+
: think ? `\n(你刚才一个人在想的:${clip(think.text, 60)})` : '';
|
|
1616
1691
|
const text = `(由头:${formatLocal(now, this.tz()).slice(11)},你${this.state.activity}`
|
|
1617
1692
|
+ `${this.state.location ? `,在${this.state.location}` : ''},精力 ${Math.round(this.state.energy)}`
|
|
1618
1693
|
+ `${since ? `;上次说话是 ${since} 前` : ''}。${reason}${thinkLine})想主动跟对方说一句,别问「在吗」,直接说你此刻的事。`;
|
|
1619
1694
|
const ok = await this.push('mcore.wake', text, 'flush');
|
|
1620
|
-
if (ok &&
|
|
1695
|
+
if (ok && urge) {
|
|
1696
|
+
this.state.lastUrgeId = urge.id;
|
|
1697
|
+
this.save();
|
|
1698
|
+
} else if (ok && think) {
|
|
1621
1699
|
this.state.lastSelfThoughtId = think.id;
|
|
1622
1700
|
this.save();
|
|
1623
1701
|
}
|
package/webui/app.js
CHANGED
|
@@ -2355,6 +2355,7 @@ function renderInspector() {
|
|
|
2355
2355
|
? `<button class="btn tiny" id="btn-restore">恢复这条</button>`
|
|
2356
2356
|
: `<button class="btn tiny" id="btn-retire">退休</button>`
|
|
2357
2357
|
}
|
|
2358
|
+
<button class="btn tiny danger" id="btn-purge">彻底删除</button>
|
|
2358
2359
|
</div>
|
|
2359
2360
|
${lineageHtml(card)}
|
|
2360
2361
|
${
|
|
@@ -2391,7 +2392,14 @@ function renderInspector() {
|
|
|
2391
2392
|
toast('复制失败,浏览器不给剪贴板权限', true);
|
|
2392
2393
|
}
|
|
2393
2394
|
});
|
|
2394
|
-
//
|
|
2395
|
+
// 详情栏也能直接删:二次确认 + 10 秒撤销,和回收站里是同一套
|
|
2396
|
+
const purgeBtn = $('#btn-purge');
|
|
2397
|
+
if (purgeBtn) {
|
|
2398
|
+
purgeBtn.addEventListener('click', async () => {
|
|
2399
|
+
const n = await purgeWithUndo([card.id]);
|
|
2400
|
+
if (n) await load();
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2395
2403
|
const retireBtn = $('#btn-retire');
|
|
2396
2404
|
if (retireBtn) {
|
|
2397
2405
|
retireBtn.addEventListener('click', async () => {
|