cortico-world-memory-core 0.21.1 → 0.22.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.22.0
4
+
5
+ > 需要自我意识 **0.9.0** 及以上,才有人写冲动;单独升级这一边不会报错,只是没有可读的东西。
6
+
7
+ **她会「想说话」了,但还是不发声。**
8
+
9
+ 自我意识插件在对方安静下来后,会把「想说一句」写成一条本地冲动(4–45 分钟的窗口里,每段沉默只写一条);
10
+ 记忆核心读到之后,可以不等原定的一百分钟,提前替她开口。
11
+
12
+ - 读 `../self-awareness/urges.jsonl`:30 分钟内、没用过的那条才算数。
13
+ - 有冲动时,「下次开口」提前到当前;静默门从默认 20 分钟放宽到最多 6 分钟——她刚想说,但也别追着人说话。
14
+ - 由头换成她的原话:`(你刚才一个人在想的:…;他已经 10 分钟没说话了)`,比「几点了」具体。
15
+ - 用过记 `lastUrgeId`,同一条不会反复推。
16
+ - 睡眠 / 免打扰 / 每日上限 / 最近说过话 这几道闸仍然有效。
17
+ - 测试 `tools/test-urge.ts` 5 项:有冲动会提前开口、由头带原话与静默时长、用过记下、没冲动不开口。
18
+
3
19
  ## 0.21.1
4
20
 
5
21
  **浅色模式里还剩几块是深色的。** 不是配色没调好,是当初把底色写死了——切主题时这些地方不会跟着变。
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.21.1",
3
+ "version": "0.22.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-site-auth.ts && node --experimental-transform-types --no-warnings tools/audit-webui.ts"
77
77
  }
78
78
  }
package/src/store.ts CHANGED
@@ -87,6 +87,8 @@ export interface CoreState {
87
87
  lastChillDay?: string;
88
88
  /** 自我意识插件写过的那条想法,已经推给主模型了——别每轮都推同一条。 */
89
89
  lastSelfThoughtId?: string;
90
+ /** 自我意识写下的「想说话」已经用来开过口了,别重复。 */
91
+ lastUrgeId?: string;
90
92
  /** 已经收成卡片的想法 id(只留最近 100 个,够防重复了)。 */
91
93
  absorbedThoughtIds?: string[];
92
94
  rawWatermark?: number;
package/src/world.ts CHANGED
@@ -1436,6 +1436,34 @@ export class MemoryCoreWorld implements World {
1436
1436
  }
1437
1437
 
1438
1438
  /** 读最近的想法原文,按时间倒序。没装那个插件就返回空数组。 */
1439
+ /**
1440
+ * 她写下的「想说话」:30 分钟内、还没用过的那条。
1441
+ * 没装自我意识插件就返回 null,不报错。
1442
+ */
1443
+ private readFreshUrge(now: Date): { id: string; text: string; quietMin: number } | null {
1444
+ const file = join(this.dataDir, '..', 'self-awareness', 'urges.jsonl');
1445
+ if (!existsSync(file)) return null;
1446
+ let lines: string[] = [];
1447
+ try {
1448
+ lines = readFileSync(file, 'utf8').split('\n').filter(Boolean).slice(-20);
1449
+ } catch {
1450
+ return null;
1451
+ }
1452
+ for (const line of lines.reverse()) {
1453
+ try {
1454
+ const o = JSON.parse(line) as { id?: string; ts?: string; text?: string; quietMin?: number };
1455
+ if (typeof o.text !== 'string' || !o.text.trim()) continue;
1456
+ if (o.id && o.id === this.state.lastUrgeId) continue;
1457
+ const at = Date.parse(String(o.ts ?? ''));
1458
+ if (!Number.isFinite(at) || now.getTime() - at > 30 * 60_000) continue;
1459
+ return { id: String(o.id ?? ''), text: o.text, quietMin: Number(o.quietMin) || 0 };
1460
+ } catch {
1461
+ // 坏行跳过
1462
+ }
1463
+ }
1464
+ return null;
1465
+ }
1466
+
1439
1467
  private readThoughts(limit = 40): { id: string; ts: string; text: string; importance: number }[] {
1440
1468
  const file = join(this.dataDir, '..', 'self-awareness', 'thoughts.jsonl');
1441
1469
  if (!existsSync(file)) return [];
@@ -1567,7 +1595,10 @@ export class MemoryCoreWorld implements World {
1567
1595
  const cfg = this.cfg();
1568
1596
  if (!cfg.proactiveEnabled) return;
1569
1597
  const p = localParts(now, this.tz());
1570
- const due = this.state.proactiveDueAt ? Date.parse(this.state.proactiveDueAt) : 0;
1598
+ // 她想说话了:这份冲动可以把「下一次」提前,但仍然要过睡眠/免打扰/上限/静默门
1599
+ const urge = this.cfg().shareSelfThought === false ? null : this.readFreshUrge(now);
1600
+ let due = this.state.proactiveDueAt ? Date.parse(this.state.proactiveDueAt) : 0;
1601
+ if (urge) due = 0;
1571
1602
  if (Number.isFinite(due) && due > now.getTime()) return;
1572
1603
 
1573
1604
  const defer = (minutes: number) => {
@@ -1596,7 +1627,9 @@ export class MemoryCoreWorld implements World {
1596
1627
  defer(30);
1597
1628
  return;
1598
1629
  }
1599
- const gate = Number(cfg.idleGateMin) || 0;
1630
+ const baseGate = Number(cfg.idleGateMin) || 0;
1631
+ // 她刚说「想说话」,就别按 20 分钟等——但也至少要静 6 分钟,别追着人说话
1632
+ const gate = urge ? Math.min(baseGate || 6, 6) : baseGate;
1600
1633
  if (lastUser && gate > 0 && now.getTime() - lastUser < gate * 60_000) {
1601
1634
  defer(Math.ceil((gate * 60_000 - (now.getTime() - lastUser)) / 60_000) + 1);
1602
1635
  return;
@@ -1612,12 +1645,17 @@ export class MemoryCoreWorld implements World {
1612
1645
  const age = now.getTime() - (Date.parse(t.ts) || 0);
1613
1646
  return Number.isFinite(age) && age < 1.5 * 3_600_000;
1614
1647
  }) ?? null;
1615
- const thinkLine = think ? `\n(你刚才一个人在想的:${clip(think.text, 60)})` : '';
1648
+ const thinkLine = urge
1649
+ ? `\n(你刚才一个人在想的:${clip(urge.text, 60)};他已经 ${urge.quietMin} 分钟没说话了)`
1650
+ : think ? `\n(你刚才一个人在想的:${clip(think.text, 60)})` : '';
1616
1651
  const text = `(由头:${formatLocal(now, this.tz()).slice(11)},你${this.state.activity}`
1617
1652
  + `${this.state.location ? `,在${this.state.location}` : ''},精力 ${Math.round(this.state.energy)}`
1618
1653
  + `${since ? `;上次说话是 ${since} 前` : ''}。${reason}${thinkLine})想主动跟对方说一句,别问「在吗」,直接说你此刻的事。`;
1619
1654
  const ok = await this.push('mcore.wake', text, 'flush');
1620
- if (ok && think) {
1655
+ if (ok && urge) {
1656
+ this.state.lastUrgeId = urge.id;
1657
+ this.save();
1658
+ } else if (ok && think) {
1621
1659
  this.state.lastSelfThoughtId = think.id;
1622
1660
  this.save();
1623
1661
  }