cortico-world-memory-core 0.17.0 → 0.18.1

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 CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.18.1
4
+
5
+ 「独处」独立成团后有自己的颜色了。
6
+
7
+ - 攒够 3 张的标签会从「自己」里分出去单独成团(星图本来就有这个逻辑),但**颜色一直跟着 kind 走**,
8
+ 和「自己」同色,看上去像没分开。现在给这类团单独配色:`独处 = 淡紫 #c9a2ff`。
9
+ - 图例补一行「独处 N」,只在 ≥3 张(真正独立成团)时出现,否则会和「自己」重复计数。
10
+ - **星点本身仍是 kind 的颜色**:星点回答「这是谁说的」,光晕回答「哪一类」。两者分开是有意的。
11
+
12
+ ## 0.18.0
13
+ ## 0.18.0
14
+
15
+ 把她独处时想的东西,接进记忆和主动开口。
16
+
17
+ - **重要的进记忆**:她自己标成 8 分以上的想法,会收成一张 `self` 卡片、打上「独处」标签、上星图。
18
+ 文本前面加「独处时写下:」——**不然它会以卡片身份进上下文,被当成此刻的想法,那又变成替她认领了**。
19
+ 只收 24 小时内的;同一个 id 不重复收。
20
+ - **主动开口有了由头**:以前由头是「几点几分、你在干嘛、精力多少」,现在多一句
21
+ 「你刚才一个人在想的:…」(1.5 小时内、还没被用过的那条)。想得越具体,开口越像真有话说。
22
+ - 新开关 `absorbSelfThought`(默认开)。
23
+ - 测试 28(7 项):收 8 分以上不收 4 分、带「独处时写下」、带标签、只写一张、不重复收、只记收下的 id。
24
+
25
+ ## 0.17.0
3
26
  ## 0.17.0
4
27
 
5
28
  按她自己的意见改的。三条都成立,第三条是根本问题。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-memory-core",
3
- "version": "0.17.0",
3
+ "version": "0.18.1",
4
4
  "type": "module",
5
5
  "description": "四个工具写卡、查卡、改状态、排日程,改口不覆盖。每轮自动把 2 条相关旧记忆推到眼前,不用模型自己查;搜索分「对得上 / 可能沾边」两档。冷层收走三个月没想起的流水账,不删、可回暖。3D 星图一眼看完整个库。常驻约 1,000 token,本地不联网,MIT。\n\nQQ 交流群:745879632",
6
6
  "keywords": [
package/src/config.ts CHANGED
@@ -106,6 +106,8 @@ export const MEMORY_CORE_DEFAULTS: MemoryCoreConfig = {
106
106
  preactivateLines: 2,
107
107
  /** 对方开口时,把「自我意识」插件独处时写下的那一句带进上下文。 */
108
108
  shareSelfThought: true,
109
+ /** 把她独处时特别在意的那些(重要度 8 以上)写成 self 卡片,进星图。 */
110
+ absorbSelfThought: true,
109
111
  chillAfterDays: 30,
110
112
  contextEveryMin: 0,
111
113
  nightlyConsolidate: true,
@@ -192,6 +194,12 @@ const RAW_GROUP: ConfigGroup = {
192
194
  description: '对方开口时,把她一个人待着时写在本子上的一句带进上下文——会标明时间,也会说明「不一定是你现在的想法」。关掉就只是本地记录,永远不进对话。',
193
195
  default: true,
194
196
  },
197
+ 'worlds.memory-core.absorbSelfThought': {
198
+ type: 'boolean',
199
+ title: '独处时的想法进记忆',
200
+ description: '她独处时写下的、她自己标成「很重要」的那些(8 分以上),会收成一条「关于她自己」的记忆,出现在星图上。卡片里会写清「独处时写下」,不会被当成此刻的想法。',
201
+ default: true,
202
+ },
195
203
  'worlds.memory-core.captureTurns': {
196
204
  type: 'boolean',
197
205
  title: '存对话原文',
@@ -294,6 +302,7 @@ const SETTINGS_ORDER = [
294
302
  'worlds.memory-core.sitePort',
295
303
  'worlds.memory-core.preactivateLines',
296
304
  'worlds.memory-core.shareSelfThought',
305
+ 'worlds.memory-core.absorbSelfThought',
297
306
  'worlds.memory-core.captureTurns',
298
307
  'worlds.memory-core.captureAll',
299
308
  'worlds.memory-core.captureSenders',
package/src/store.ts CHANGED
@@ -87,6 +87,8 @@ export interface CoreState {
87
87
  lastChillDay?: string;
88
88
  /** 自我意识插件写过的那条想法,已经推给主模型了——别每轮都推同一条。 */
89
89
  lastSelfThoughtId?: string;
90
+ /** 已经收成卡片的想法 id(只留最近 100 个,够防重复了)。 */
91
+ absorbedThoughtIds?: string[];
90
92
  rawWatermark?: number;
91
93
  /** 水位是按哪一版捕获逻辑推进的。旧版用了错的 range 语义,水位不可信,见 CAPTURE_WATERMARK_VERSION。 */
92
94
  watermarkVersion?: number;
package/src/world.ts CHANGED
@@ -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);
@@ -1431,6 +1432,74 @@ export class MemoryCoreWorld implements World {
1431
1432
  }
1432
1433
  }
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
+
1434
1503
  /**
1435
1504
  * 从自我意识插件的 thoughts.jsonl 里挑一条。
1436
1505
  * 选法:和对方刚说的话有词面重叠的优先,其次挑新鲜的;6 小时以外的不要。
@@ -1531,10 +1600,23 @@ export class MemoryCoreWorld implements World {
1531
1600
 
1532
1601
  const since = lastUser ? humanSpan(now.getTime() - lastUser) : null;
1533
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)})` : '';
1534
1612
  const text = `(由头:${formatLocal(now, this.tz()).slice(11)},你${this.state.activity}`
1535
1613
  + `${this.state.location ? `,在${this.state.location}` : ''},精力 ${Math.round(this.state.energy)}`
1536
- + `${since ? `;上次说话是 ${since} 前` : ''}。${reason})想主动跟对方说一句,别问「在吗」,直接说你此刻的事。`;
1614
+ + `${since ? `;上次说话是 ${since} 前` : ''}。${reason}${thinkLine})想主动跟对方说一句,别问「在吗」,直接说你此刻的事。`;
1537
1615
  const ok = await this.push('mcore.wake', text, 'flush');
1616
+ if (ok && think) {
1617
+ this.state.lastSelfThoughtId = think.id;
1618
+ this.save();
1619
+ }
1538
1620
  if (!ok) {
1539
1621
  defer(15);
1540
1622
  return;
package/webui/app.js CHANGED
@@ -996,6 +996,8 @@ class Graph {
996
996
 
997
997
  const GALAXY_KIND = { fact: '事实', self: '自己', episode: '经历', promise: '承诺', note: '临时' };
998
998
  const GALAXY_COLOR = { fact: '#8ef0dc', self: '#9ab8ff', episode: '#ffc078', promise: '#ff9ec4', note: '#c3ccd8' };
999
+ /** 攒够 3 张就独立成团的标签,可以有自己的颜色。色相要和它的 kind 拉开,一眼能分。 */
1000
+ const GALAXY_TAG_COLOR = { 独处: '#c9a2ff' };
999
1001
  const GALAXY_CAM = 1900;
1000
1002
 
1001
1003
  /** 固定种子:同一批卡片每次布出来的星系一样。 */
@@ -1321,7 +1323,7 @@ class Galaxy {
1321
1323
  this.nodes.push(node);
1322
1324
  });
1323
1325
  g.hub = g.nodes.reduce((b, n) => (Number(n.card.weight) > Number(b.card.weight) ? n : b), g.nodes[0]);
1324
- g.color = GALAXY_COLOR[g.hub.card.kind] ?? '#c3ccd8';
1326
+ g.color = GALAXY_TAG_COLOR[g.name] ?? GALAXY_COLOR[g.hub.card.kind] ?? '#c3ccd8';
1325
1327
  g.rz = gauss() * RMAX * 0.04;
1326
1328
  }
1327
1329
 
@@ -1804,13 +1806,18 @@ function renderGalaxyLegend() {
1804
1806
  const host = $('#galaxy-legend');
1805
1807
  if (!host || !galaxy) return;
1806
1808
  const counts = galaxy.kindCounts ?? {};
1807
- host.innerHTML = Object.keys(GALAXY_KIND)
1809
+ const parts = Object.keys(GALAXY_KIND)
1808
1810
  .filter((k) => counts[k])
1809
1811
  .map(
1810
1812
  (k) =>
1811
1813
  `<span style="color:${GALAXY_COLOR[k]}"><i style="background:${GALAXY_COLOR[k]}"></i>${GALAXY_KIND[k]} ${counts[k]}</span>`,
1812
- )
1813
- .join('');
1814
+ );
1815
+ // 独立成团的标签单独列一行:它已经从「自己」里分出去了,混在一起会让人数不上
1816
+ for (const [tag, color] of Object.entries(GALAXY_TAG_COLOR)) {
1817
+ const n = cards().filter((c) => (c.tags ?? []).includes(tag)).length;
1818
+ if (n >= 3) parts.push(`<span style="color:${color}"><i style="background:${color}"></i>${tag} ${n}</span>`);
1819
+ }
1820
+ host.innerHTML = parts.join('');
1814
1821
  }
1815
1822
 
1816
1823
  let graph = null;