cortico-world-memory-core 0.1.1 → 0.3.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 +38 -0
- package/ENV_PROMPT.md +1 -1
- package/README.md +29 -4
- package/assets/screenshots/graph.png +0 -0
- package/assets/screenshots/maintenance.png +0 -0
- package/assets/screenshots/table.png +0 -0
- package/assets/screenshots/timeline.png +0 -0
- package/describe.json +264 -0
- package/icon.svg +32 -0
- package/package.json +72 -49
- package/src/config.ts +19 -4
- package/src/recall.ts +6 -2
- package/src/site.ts +1 -0
- package/src/store.ts +211 -16
- package/src/tools.ts +7 -2
- package/src/world.ts +151 -31
- package/webui/app.js +141 -44
- package/webui/style.css +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- **图谱补上版本链**:被 `supersedes` 接替的旧卡会补进图(压暗、带标签),按「旧 → 新」画虚线箭头,图例注明「虚线箭头=被新版本接替」。之前这张图只有标签共现和「同一天」两种弱边,看不出记忆是怎么演进的——而版本链恰恰是这个插件最该被看见的关系。
|
|
6
|
+
- **搜索加防抖**:输入 150ms 后才重绘,不再每敲一个字就把原文 1000+ 条、表格几十行整体重建。
|
|
7
|
+
- **原文页分页**:先渲染最近 200 条,底部「还有 N 条 · 继续加载」;日期分组在只加载了一部分时显示「52 / 126 条」,不会让人以为那天只有这么几句。
|
|
8
|
+
- **「彻底删除」移出详情栏**:它原来紧挨「退休」,误触一次就不可逆。现在只能在维护面板 → 回收站里删,详情栏只留「退休 / 恢复」。
|
|
9
|
+
- 演示数据补了两组版本链,市场截图能体现新的图谱边。
|
|
10
|
+
|
|
11
|
+
## 0.2.1
|
|
12
|
+
|
|
13
|
+
- **修掉「对话原文一直是 0 行」**:默认 `captureSenders` 白名单一个真实 senderKey 都匹配不上(实际是 `private:1940008084`、`desktop-pet.chat`,旧正则写的是 `qq.` / `desktop-pet.message`)。新默认认 QQ 私聊、桌宠对话/语音、星邮私聊,群聊仍然不收;读到旧默认值会自动换成新的,不用手改设置。
|
|
14
|
+
- **原文过期不再直接删**:超过 `rawRetentionDays` 的行按天挪进 `data/memory-core/archive/YYYY-MM-DD.jsonl`,新增 `rawArchiveDays`(默认 90 天,0 = 永久)。模型用 `mcore_recall` 的 `mode=archive` 能翻回更早的对话。
|
|
15
|
+
- **归档不重复**:过期的新行直接进归档、不再留在 `turns.jsonl`;启动时按已归档的游标去重,重启不会把同一行写第二遍。
|
|
16
|
+
- **历史补录**:新增 `captureBackfill`,打开后重启一次会把水位倒回开头重扫宿主还留着的消息,补完自动停用;中途被打断会从断点接着跑。
|
|
17
|
+
- **补录分页修正**:宿主 `range` 的 `limit` 是「从区间末尾取」,之前拿它当分页,`from=0` 时直接返回全部历史的最后 400 条、水位一次跳到末尾,前面的补录全被跳过。改成分窗扫(`toCursor` 逐段推进),旧水位按版本号自动作废重来——真实数据从 55 行补到 1327 行。
|
|
18
|
+
- **诊断可见**:`state.json` 记录最近一次捕获的体检结果(扫了多少条、留下几条、被白名单挡掉的 key 样例),原文页没有数据时直接把样例显示出来。
|
|
19
|
+
- **召回打分**:标签单独加权(同一关键词命中标签比正文里顺带提到更靠前);`uses` 惩罚封顶 8 次,常用的重要记忆不会越用越沉。
|
|
20
|
+
- **疑似作废**加了老化候选:90 天没被召回、权重低于 0.45、未完成的承诺除外——仍然只是候选,要人点一下才退休。
|
|
21
|
+
- 提示词跟着加了一句 `mode=archive` 的用法(697 → 720 字符)。
|
|
22
|
+
|
|
23
|
+
## 0.2.0
|
|
24
|
+
|
|
25
|
+
- 补上扩展市场要的自描述与元数据:`describe.json`(工具、事件、环境提示词原文)、图标、四张演示截图,`cortico.locales` 中英简介。
|
|
26
|
+
- 标签改成词表里的:`memory`、`companion`、`internal-state`、`experimental`(原来的 `proactive` / `life` 不在词表里,市场会判为无效标签)。
|
|
27
|
+
- `CHANGELOG.md` 进包,市场详情页才能按版本显示更新日志。代码与 0.1.1 一致。
|
|
28
|
+
|
|
29
|
+
## 0.1.1
|
|
30
|
+
|
|
31
|
+
- 修正 `repository` / `homepage` / `bugs` 指向的 GitHub 地址(0.1.0 里写错了账号)。代码与 0.1.0 一致。
|
|
32
|
+
|
|
33
|
+
## 0.1.0
|
|
34
|
+
|
|
35
|
+
- 首个版本:一张卡片表(fact / self / episode / promise / note)、四个工具、一段静态环境提示词。
|
|
36
|
+
- 退休与版本链:编辑不覆盖,旧版标 `retired` 并由新卡记 `supersedes`;`closes` 取代旧记录后不再参与检索。
|
|
37
|
+
- 记忆域 `scope`、重复合并、疑似作废/垃圾识别,都在记忆地图的「维护」面板里先预览再执行。
|
|
38
|
+
- 记忆地图:图谱 / 时间线 / 列表 / 原文 / 文件五视图,右栏可折叠。
|
package/ENV_PROMPT.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
写法:一条一件事,40–80 字,写清楚谁、什么时候、怎么了;不要写「对方说了一些事」这种空话。同一件事不要写两遍,记不清就先查。`weight` 是这事在你心里的分量,0.3 琐事 / 0.5 一般 / 0.8 重要。
|
|
13
13
|
|
|
14
|
-
查法:`mcore_recall` 不传 `query` 就是最近几条;传 `query` 搜内容,最近 7
|
|
14
|
+
查法:`mcore_recall` 不传 `query` 就是最近几条;传 `query` 搜内容,最近 7 天的对话原文和工作区里的笔记文件也会一起搜,更早的加 `mode=archive` 翻归档;`mode=open` 看没做完的承诺和今天的安排。
|
|
15
15
|
什么时候查:对方提到某个人、某件事、某个日期、旧约定,或者问「你还记得吗」——先查再答,不要硬猜。
|
|
16
16
|
|
|
17
17
|
你自己也有状态:`mcore_state` 管精力、心情、正在做什么、在哪、睡没睡;`mcore_plan` 管今天的安排。这两样和记忆分开放,不要写进 `mcore_write`。
|
package/README.md
CHANGED
|
@@ -4,6 +4,18 @@ Cortico World 的长期记忆插件:**一张卡片表 + 4 个工具 + 一段
|
|
|
4
4
|
|
|
5
5
|
设计目标很朴素:**每轮多花的 token 控制在 1.3k 以内**(工具声明约 853 + 提示词约 381),同时让角色真的记得住事、查得到、改得对。
|
|
6
6
|
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
<p align="center"><sub>图谱:节点大小=权重,颜色=类型,连线=共同标签或同一天。</sub></p>
|
|
10
|
+
|
|
11
|
+
| 列表 | 时间线 |
|
|
12
|
+
|---|---|
|
|
13
|
+
|  |  |
|
|
14
|
+
|
|
15
|
+
<p align="center"><sub>维护面板:重复 / 疑似作废 / 垃圾 / 回收站,都先预览再执行。</sub></p>
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
7
19
|
## 安装
|
|
8
20
|
|
|
9
21
|
```bash
|
|
@@ -18,7 +30,7 @@ pnpm add cortico-world-memory-core
|
|
|
18
30
|
| 工具 | 作用 |
|
|
19
31
|
|---|---|
|
|
20
32
|
| `mcore_write` | 写一条记忆。`kind` 五选一,可带 `weight` / `tags` / `dueAt`;传 `closes` 表示「这条替代了某条旧的」 |
|
|
21
|
-
| `mcore_recall` | 查记忆。不传 `query` 就是最近几条;传了就按内容搜,同时搜最近 7 天的对话原文和工作区笔记;`mode=open`
|
|
33
|
+
| `mcore_recall` | 查记忆。不传 `query` 就是最近几条;传了就按内容搜,同时搜最近 7 天的对话原文和工作区笔记;`mode=open` 看没做完的承诺和今天的安排;`mode=archive` 翻更早的归档原文 |
|
|
22
34
|
| `mcore_state` | 角色自己的精力 / 心情 / 正在做什么 / 在哪 / 睡没睡 |
|
|
23
35
|
| `mcore_plan` | 今天的日程(增、勾、清空) |
|
|
24
36
|
|
|
@@ -41,7 +53,7 @@ pnpm add cortico-world-memory-core
|
|
|
41
53
|
| 图谱 | 力导向图:节点大小=权重、颜色=类型、连线=共同标签或同一天;滚轮缩放、拖动、双击适应 |
|
|
42
54
|
| 时间线 | 按天分组,带权重条与截止时间 |
|
|
43
55
|
| 列表 | 可排序表格(类型 / 内容 / 权重 / 来源 / 标签 / 记于 / 使用次数),权重带微条 |
|
|
44
|
-
| 原文 | 最近 7
|
|
56
|
+
| 原文 | 最近 7 天的对话原文,搜索高亮;更早的进 `archive/`,模型可用 `mode=archive` 翻回去 |
|
|
45
57
|
| 文件 | 工作区里被检索的 md / txt(只读) |
|
|
46
58
|
| 维护 | 重复 / 疑似作废 / 垃圾 / 回收站,四项都先预览再执行 |
|
|
47
59
|
|
|
@@ -70,9 +82,11 @@ pnpm add cortico-world-memory-core
|
|
|
70
82
|
|---|---|---|
|
|
71
83
|
| `memoryEnabled` | `true` | 记忆总开关 |
|
|
72
84
|
| `captureTurns` | `true` | 存对方最近的对话原文,供「搜最近聊过什么」 |
|
|
73
|
-
| `captureSenders` | `^(
|
|
85
|
+
| `captureSenders` | `^(desktop-pet\.(chat\|message\|answer\|voice)\|private:\|qq\.private\.\|starpost\.private\.)` | 哪些来源算对话(正则匹配 senderKey)。真实 key 长这样:`private:1940008084`、`desktop-pet.chat`;群聊不算 |
|
|
74
86
|
| `captureMinLength` | `4` | 短于这个字数的消息不进原文库 |
|
|
75
|
-
| `rawRetentionDays` | `7` |
|
|
87
|
+
| `rawRetentionDays` | `7` | 热数据天数,超过就按天挪进 `archive/`(不再直接删) |
|
|
88
|
+
| `rawArchiveDays` | `90` | 归档保留天数,`0` = 永久 |
|
|
89
|
+
| `captureBackfill` | `false` | 打开后重启一次:把水位倒回开头重扫历史消息,补录完自动停用 |
|
|
76
90
|
| `recallLimit` | `5` | 一次召回给几条 |
|
|
77
91
|
| `recallMaxChars` | `600` | 召回结果总字数上限 |
|
|
78
92
|
| `proactiveEnabled` | `true` | 主动开口 |
|
|
@@ -88,6 +102,7 @@ pnpm add cortico-world-memory-core
|
|
|
88
102
|
data/memory-core/
|
|
89
103
|
├─ cards.jsonl 卡片(一行一张,可以直接看)
|
|
90
104
|
├─ turns.jsonl 对方最近的对话原文(按 captureSenders 过滤)
|
|
105
|
+
├─ archive/ 过期的原文按天归档(YYYY-MM-DD.jsonl),可搜可删
|
|
91
106
|
├─ plans.json 今天的日程
|
|
92
107
|
├─ state.json 精力/心情/活动/位置/主动计数
|
|
93
108
|
└─ imported.json 旧数据导入记录(删掉它会在下次启动重新导入)
|
|
@@ -111,10 +126,20 @@ node --experimental-transform-types tools/test-store.ts
|
|
|
111
126
|
|
|
112
127
|
# World 层:用假宿主真启动一次,跑写、查、closes 取代
|
|
113
128
|
node --experimental-transform-types tools/test-world.ts
|
|
129
|
+
|
|
130
|
+
# 改了工具或提示词之后,重新生成市场详情页读的自描述
|
|
131
|
+
node --experimental-transform-types tools/build-describe.ts
|
|
132
|
+
|
|
133
|
+
# 拍市场截图:用一套虚构的示例记忆起临时站点,拍完自己清理
|
|
134
|
+
node --experimental-transform-types tools/demo-server.ts
|
|
114
135
|
```
|
|
115
136
|
|
|
116
137
|
改 `src/` 后**必须重启宿主进程**才生效:`/api/worlds/restart` 只重建实例,ESM 模块缓存不会重读。
|
|
117
138
|
|
|
139
|
+
## 市场标签
|
|
140
|
+
|
|
141
|
+
`cortico.tags` 里声明的是扩展市场词表里的标签:`memory`(记忆库)、`companion`(心情/日程/主动开口)、`internal-state`(在世界里维护角色内部状态,市场会提示更推荐放进 bot 的 Persona)、`experimental`(0.x,只在少数环境验证过)。要改标签发新版本即可,不用提申请。
|
|
142
|
+
|
|
118
143
|
## License
|
|
119
144
|
|
|
120
145
|
MIT
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/describe.json
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tools": [
|
|
3
|
+
{
|
|
4
|
+
"name": "mcore_write",
|
|
5
|
+
"description": "写一条记忆。kind:fact=关于对方的事实,self=关于你自己的,episode=发生过的一件事(带感受),promise=答应过的事(写 dueAt),note=过几天就没用的临时信息。一条只写一件事,40-80 字,写具体。同一件事不要重复写;把旧记录传进 closes 表示它已完成或作废。",
|
|
6
|
+
"parameters": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"kind": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"enum": [
|
|
13
|
+
"fact",
|
|
14
|
+
"self",
|
|
15
|
+
"episode",
|
|
16
|
+
"promise",
|
|
17
|
+
"note"
|
|
18
|
+
],
|
|
19
|
+
"description": "记忆类型"
|
|
20
|
+
},
|
|
21
|
+
"text": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "这条记忆的内容,40-80 字"
|
|
24
|
+
},
|
|
25
|
+
"weight": {
|
|
26
|
+
"type": "number",
|
|
27
|
+
"minimum": 0,
|
|
28
|
+
"maximum": 1,
|
|
29
|
+
"description": "在心里有多重:0.3 琐事 / 0.5 一般 / 0.8 重要。默认 0.5"
|
|
30
|
+
},
|
|
31
|
+
"tags": {
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"description": "关键词,最多 6 个"
|
|
37
|
+
},
|
|
38
|
+
"dueAt": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"description": "仅 promise 用:什么时候该做,ISO 时间或 YYYY-MM-DD HH:MM"
|
|
41
|
+
},
|
|
42
|
+
"closes": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"description": "要关掉的旧记录 id(已完成/已失效)"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"required": [
|
|
48
|
+
"kind",
|
|
49
|
+
"text"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"tags": [
|
|
53
|
+
"write"
|
|
54
|
+
],
|
|
55
|
+
"summary": "写一条记忆卡片(事实/自己/经历/承诺/临时)。"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "mcore_recall",
|
|
59
|
+
"description": "查记忆。不传 query 就是最近几条;传 query 按内容搜,最近 7 天的对话原文和工作区的笔记文件也会一起搜;mode=open 看还没做完的承诺与今天的安排;mode=archive 翻归档里的旧对话(要带 query)。对方提到人、事、日期、旧约定,或问「你还记得吗」时先查再答。",
|
|
60
|
+
"parameters": {
|
|
61
|
+
"type": "object",
|
|
62
|
+
"additionalProperties": false,
|
|
63
|
+
"properties": {
|
|
64
|
+
"query": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"description": "要查的内容,几个关键词就够"
|
|
67
|
+
},
|
|
68
|
+
"kind": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"enum": [
|
|
71
|
+
"fact",
|
|
72
|
+
"self",
|
|
73
|
+
"episode",
|
|
74
|
+
"promise",
|
|
75
|
+
"note"
|
|
76
|
+
],
|
|
77
|
+
"description": "只看某一类"
|
|
78
|
+
},
|
|
79
|
+
"mode": {
|
|
80
|
+
"type": "string",
|
|
81
|
+
"enum": [
|
|
82
|
+
"search",
|
|
83
|
+
"recent",
|
|
84
|
+
"open",
|
|
85
|
+
"archive"
|
|
86
|
+
],
|
|
87
|
+
"description": "默认 search;没给 query 按 recent 处理"
|
|
88
|
+
},
|
|
89
|
+
"days": {
|
|
90
|
+
"type": "integer",
|
|
91
|
+
"minimum": 1,
|
|
92
|
+
"maximum": 3650,
|
|
93
|
+
"description": "只看最近这么多天"
|
|
94
|
+
},
|
|
95
|
+
"limit": {
|
|
96
|
+
"type": "integer",
|
|
97
|
+
"minimum": 1,
|
|
98
|
+
"maximum": 12,
|
|
99
|
+
"description": "最多几条,默认 5"
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"required": []
|
|
103
|
+
},
|
|
104
|
+
"tags": [
|
|
105
|
+
"read"
|
|
106
|
+
],
|
|
107
|
+
"summary": "按内容或时间检索记忆,也能查最近 7 天的对话原文与未完成的承诺。"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"name": "mcore_state",
|
|
111
|
+
"description": "你自己的状态:精力、心情、正在做什么、在哪、睡没睡。action=get 读取;update 只改传入的字段;rest 去睡一会儿。这是你自己的,不要念成清单给对方听。",
|
|
112
|
+
"parameters": {
|
|
113
|
+
"type": "object",
|
|
114
|
+
"additionalProperties": false,
|
|
115
|
+
"properties": {
|
|
116
|
+
"action": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"enum": [
|
|
119
|
+
"get",
|
|
120
|
+
"update",
|
|
121
|
+
"rest"
|
|
122
|
+
],
|
|
123
|
+
"description": "get 读,update 改,rest 睡"
|
|
124
|
+
},
|
|
125
|
+
"energy": {
|
|
126
|
+
"type": "number",
|
|
127
|
+
"minimum": 0,
|
|
128
|
+
"maximum": 100,
|
|
129
|
+
"description": "精力 0-100"
|
|
130
|
+
},
|
|
131
|
+
"mood": {
|
|
132
|
+
"type": "number",
|
|
133
|
+
"minimum": 0,
|
|
134
|
+
"maximum": 100,
|
|
135
|
+
"description": "心情 0-100"
|
|
136
|
+
},
|
|
137
|
+
"activity": {
|
|
138
|
+
"type": "string",
|
|
139
|
+
"description": "正在做什么,例如「翻旧照片」"
|
|
140
|
+
},
|
|
141
|
+
"location": {
|
|
142
|
+
"type": "string",
|
|
143
|
+
"description": "在哪,例如「窗台」"
|
|
144
|
+
},
|
|
145
|
+
"sleeping": {
|
|
146
|
+
"type": "boolean",
|
|
147
|
+
"description": "是否在睡"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"required": [
|
|
151
|
+
"action"
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
"tags": [
|
|
155
|
+
"read",
|
|
156
|
+
"write",
|
|
157
|
+
"snapshot"
|
|
158
|
+
],
|
|
159
|
+
"summary": "读写你自己的精力、心情、正在做什么、在哪。"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"name": "mcore_plan",
|
|
163
|
+
"description": "你今天的安排。action=list 看;add 加一条(time 用 HH:MM,title 写做什么,place 可省);done 标完成(传 id);clear 清空。日程是你开口的由头,不用讲给对方听。",
|
|
164
|
+
"parameters": {
|
|
165
|
+
"type": "object",
|
|
166
|
+
"additionalProperties": false,
|
|
167
|
+
"properties": {
|
|
168
|
+
"action": {
|
|
169
|
+
"type": "string",
|
|
170
|
+
"enum": [
|
|
171
|
+
"list",
|
|
172
|
+
"add",
|
|
173
|
+
"done",
|
|
174
|
+
"clear"
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
"items": {
|
|
178
|
+
"type": "array",
|
|
179
|
+
"description": "add 用第一项",
|
|
180
|
+
"items": {
|
|
181
|
+
"type": "object",
|
|
182
|
+
"additionalProperties": false,
|
|
183
|
+
"properties": {
|
|
184
|
+
"time": {
|
|
185
|
+
"type": "string",
|
|
186
|
+
"description": "HH:MM"
|
|
187
|
+
},
|
|
188
|
+
"title": {
|
|
189
|
+
"type": "string",
|
|
190
|
+
"description": "做什么"
|
|
191
|
+
},
|
|
192
|
+
"place": {
|
|
193
|
+
"type": "string",
|
|
194
|
+
"description": "在哪,可省略"
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
"required": [
|
|
198
|
+
"time",
|
|
199
|
+
"title"
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
"id": {
|
|
204
|
+
"type": "string",
|
|
205
|
+
"description": "done 用的日程 id"
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
"required": [
|
|
209
|
+
"action"
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
"tags": [
|
|
213
|
+
"read",
|
|
214
|
+
"write"
|
|
215
|
+
],
|
|
216
|
+
"summary": "安排今天的日程,作为主动开口的由头。"
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
"events": [
|
|
220
|
+
{
|
|
221
|
+
"type": "mcore.wake",
|
|
222
|
+
"description": {
|
|
223
|
+
"zh": "主动开口的由头:从状态、未完成的承诺和日程里推出来的一小段理由,立即唤醒一轮。",
|
|
224
|
+
"en": "A reason to speak first, derived from state, open promises and today's plan."
|
|
225
|
+
},
|
|
226
|
+
"trigger": "flush"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"type": "mcore.due",
|
|
230
|
+
"description": {
|
|
231
|
+
"zh": "答应过的事到点了,立即唤醒一轮提醒角色提一句。",
|
|
232
|
+
"en": "A promise came due; wakes a turn so the character can bring it up."
|
|
233
|
+
},
|
|
234
|
+
"trigger": "flush"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"type": "mcore.context",
|
|
238
|
+
"description": {
|
|
239
|
+
"zh": "当前状态一行字,随下一批投递;默认关闭,避免每轮多带 token。",
|
|
240
|
+
"en": "One line of current state, piggybacked. Off by default."
|
|
241
|
+
},
|
|
242
|
+
"trigger": "piggyback",
|
|
243
|
+
"tags": [
|
|
244
|
+
"snapshot"
|
|
245
|
+
]
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"type": "mcore.nightly",
|
|
249
|
+
"description": {
|
|
250
|
+
"zh": "夜间整理:唤醒一轮,让它把今天写成几条 episode(默认关闭)。",
|
|
251
|
+
"en": "Nightly consolidation turn (off by default)."
|
|
252
|
+
},
|
|
253
|
+
"trigger": "flush"
|
|
254
|
+
}
|
|
255
|
+
],
|
|
256
|
+
"prompts": [
|
|
257
|
+
{
|
|
258
|
+
"key": "worlds.memory-core.envPrompt",
|
|
259
|
+
"title": "记忆核心 · 环境提示词",
|
|
260
|
+
"role": "envPrompt",
|
|
261
|
+
"content": "【记忆核心】\n\n你现在只有一套记忆:`mcore_write` 写进去,`mcore_recall` 查出来。旧的几套记忆已经并进这里,不要再提「另一个记忆系统」,也不要问对方「要记在哪」。\n\n写什么:\n- `fact` 关于对方的稳定事实(名字、作息、忌讳、正在忙的事)。\n- `self` 关于你自己的(喜欢什么、怕什么、决定过什么)。\n- `episode` 发生过的一件事,带上当时的感觉。\n- `promise` 答应过的事,写 `dueAt`;做完或改了传 `closes`(查出来的行首 8 位就是 id)。\n- `note` 过几天就没用的临时信息。\n\n写法:一条一件事,40–80 字,写清楚谁、什么时候、怎么了;不要写「对方说了一些事」这种空话。同一件事不要写两遍,记不清就先查。`weight` 是这事在你心里的分量,0.3 琐事 / 0.5 一般 / 0.8 重要。\n\n查法:`mcore_recall` 不传 `query` 就是最近几条;传 `query` 搜内容,最近 7 天的对话原文和工作区里的笔记文件也会一起搜,更早的加 `mode=archive` 翻归档;`mode=open` 看没做完的承诺和今天的安排。\n什么时候查:对方提到某个人、某件事、某个日期、旧约定,或者问「你还记得吗」——先查再答,不要硬猜。\n\n你自己也有状态:`mcore_state` 管精力、心情、正在做什么、在哪、睡没睡;`mcore_plan` 管今天的安排。这两样和记忆分开放,不要写进 `mcore_write`。\n\n分寸:记忆是你记得的东西,不是拿来念的清单。可以自然地说「我记得你说过……」;不确定的就直接问,别编。"
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
package/icon.svg
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="256" height="256" role="img" aria-label="记忆核心">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#1b1e1c"/>
|
|
5
|
+
<stop offset="1" stop-color="#101211"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<radialGradient id="glow" cx="0.5" cy="0.5" r="0.5">
|
|
8
|
+
<stop offset="0" stop-color="#2fd59b" stop-opacity="0.30"/>
|
|
9
|
+
<stop offset="1" stop-color="#2fd59b" stop-opacity="0"/>
|
|
10
|
+
</radialGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
|
|
13
|
+
<rect width="256" height="256" rx="56" fill="url(#bg)"/>
|
|
14
|
+
<rect x="1.5" y="1.5" width="253" height="253" rx="54.5" fill="none" stroke="#2f3431" stroke-width="3"/>
|
|
15
|
+
<circle cx="128" cy="124" r="92" fill="url(#glow)"/>
|
|
16
|
+
|
|
17
|
+
<g stroke="#3b413e" stroke-width="9" stroke-linecap="round">
|
|
18
|
+
<path d="M128 124 L74 76"/>
|
|
19
|
+
<path d="M128 124 L188 82"/>
|
|
20
|
+
<path d="M128 124 L68 168"/>
|
|
21
|
+
<path d="M128 124 L180 176"/>
|
|
22
|
+
</g>
|
|
23
|
+
|
|
24
|
+
<circle cx="74" cy="76" r="13" fill="#64b8ad"/>
|
|
25
|
+
<circle cx="188" cy="82" r="11" fill="#91b99d"/>
|
|
26
|
+
<circle cx="68" cy="168" r="11" fill="#c4a372"/>
|
|
27
|
+
<circle cx="180" cy="176" r="13" fill="#78cbae"/>
|
|
28
|
+
|
|
29
|
+
<circle cx="128" cy="124" r="27" fill="#0d1f19"/>
|
|
30
|
+
<circle cx="128" cy="124" r="22" fill="#2fd59b"/>
|
|
31
|
+
<circle cx="120" cy="116" r="7" fill="#8ff0cd" opacity="0.55"/>
|
|
32
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,49 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cortico-world-memory-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "Cortico World 长期记忆:一张卡片表 + 4 个工具 + 一段静态提示词,附状态、日程、主动开口与本地记忆地图。",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"cortico-world",
|
|
8
|
-
"cortico",
|
|
9
|
-
"coopanion",
|
|
10
|
-
"memory",
|
|
11
|
-
"companion"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "cortico-world-memory-core",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Cortico World 长期记忆:一张卡片表 + 4 个工具 + 一段静态提示词,附状态、日程、主动开口与本地记忆地图。",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"cortico-world",
|
|
8
|
+
"cortico",
|
|
9
|
+
"coopanion",
|
|
10
|
+
"memory",
|
|
11
|
+
"companion"
|
|
12
|
+
],
|
|
13
|
+
"author": "lutsing",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/liqin1018/cortico-world-memory-core.git"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/liqin1018/cortico-world-memory-core#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/liqin1018/cortico-world-memory-core/issues"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"main": "./src/index.ts",
|
|
27
|
+
"cortico": {
|
|
28
|
+
"kind": "world",
|
|
29
|
+
"api": 6,
|
|
30
|
+
"displayName": "记忆核心",
|
|
31
|
+
"locales": {
|
|
32
|
+
"zh": {
|
|
33
|
+
"displayName": "记忆核心",
|
|
34
|
+
"description": "一张卡片表、四个工具、一段 720 字的静态提示词。改口不覆盖:旧卡退休、新卡记下接替了谁,召回时不会再同时看到作废的和改后的那条。附带状态、日程、主动开口,以及一个本地记忆地图(图谱 / 时间线 / 维护面板)。"
|
|
35
|
+
},
|
|
36
|
+
"en": {
|
|
37
|
+
"displayName": "Memory Core",
|
|
38
|
+
"description": "One card table, four tools and a 720-character static prompt. Corrections don't overwrite: the old card is retired and the new one records what it supersedes, so a retracted plan never comes back alongside the revised one. Ships mood/energy state, today's plan, speaking first, and a local memory map with graph, timeline and a maintenance panel."
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"tags": [
|
|
42
|
+
"memory",
|
|
43
|
+
"companion",
|
|
44
|
+
"internal-state",
|
|
45
|
+
"experimental"
|
|
46
|
+
],
|
|
47
|
+
"describe": "./describe.json",
|
|
48
|
+
"icon": "./icon.svg",
|
|
49
|
+
"screenshots": [
|
|
50
|
+
"assets/screenshots/graph.png",
|
|
51
|
+
"assets/screenshots/table.png",
|
|
52
|
+
"assets/screenshots/timeline.png",
|
|
53
|
+
"assets/screenshots/maintenance.png"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"src",
|
|
58
|
+
"webui/app.js",
|
|
59
|
+
"webui/index.html",
|
|
60
|
+
"webui/style.css",
|
|
61
|
+
"assets",
|
|
62
|
+
"ENV_PROMPT.md",
|
|
63
|
+
"describe.json",
|
|
64
|
+
"icon.svg",
|
|
65
|
+
"CHANGELOG.md",
|
|
66
|
+
"README.md",
|
|
67
|
+
"LICENSE"
|
|
68
|
+
],
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -34,8 +34,12 @@ export interface MemoryCoreConfig {
|
|
|
34
34
|
captureSenders: string;
|
|
35
35
|
/** 短于这么多字的对话原文不存(过滤表情、单字、口令回执)。 */
|
|
36
36
|
captureMinLength: number;
|
|
37
|
-
/**
|
|
37
|
+
/** 对话原文保留天数(热数据,超过就按天归档)。 */
|
|
38
38
|
rawRetentionDays: number;
|
|
39
|
+
/** 归档保留天数(0 = 永久)。 */
|
|
40
|
+
rawArchiveDays: number;
|
|
41
|
+
/** 启动后把历史事件重扫一遍补录(只做一次)。 */
|
|
42
|
+
captureBackfill: boolean;
|
|
39
43
|
/** 一次召回最多给几条。 */
|
|
40
44
|
recallLimit: number;
|
|
41
45
|
/** 召回结果的总字数上限。 */
|
|
@@ -78,9 +82,13 @@ export const MEMORY_CORE_DEFAULTS: MemoryCoreConfig = {
|
|
|
78
82
|
sleepEnd: '08:00',
|
|
79
83
|
memoryEnabled: true,
|
|
80
84
|
captureTurns: true,
|
|
81
|
-
|
|
85
|
+
// 真实 senderKey 长这样:private:1940008084(QQ 私聊)、desktop-pet.chat(桌宠对话)。
|
|
86
|
+
// 老默认值一个都匹配不上,导致原文库一直是 0 行 —— 改这个 regex 前先看一遍 data/runs/*/events.jsonl。
|
|
87
|
+
captureSenders: '^(desktop-pet\\.(chat|message|answer|voice)|private:|qq\\.private\\.|starpost\\.private\\.)',
|
|
82
88
|
captureMinLength: 4,
|
|
83
89
|
rawRetentionDays: 7,
|
|
90
|
+
rawArchiveDays: 90,
|
|
91
|
+
captureBackfill: false,
|
|
84
92
|
recallLimit: 5,
|
|
85
93
|
recallMaxChars: 600,
|
|
86
94
|
contextEveryMin: 0,
|
|
@@ -170,11 +178,18 @@ export const MEMORY_CORE_CONFIG_GROUP: ConfigGroup = {
|
|
|
170
178
|
'worlds.memory-core.captureSenders': {
|
|
171
179
|
type: 'string',
|
|
172
180
|
title: '算作对话的来源',
|
|
173
|
-
description: '正则匹配事件的 senderKey
|
|
181
|
+
description: '正则匹配事件的 senderKey。默认认 QQ 私聊(private:数字)、桌宠对话(desktop-pet.chat / voice)、星邮私聊;群聊不算。填错了一个字都录不到,改完看「对话原文」页有没有进新行。',
|
|
174
182
|
'x-hot': true,
|
|
175
183
|
},
|
|
176
184
|
'worlds.memory-core.captureMinLength': num('原文最短几个字', '短于这个长度的消息不进原文库(表情、单字、口令回执照样过滤)。', 1, 20, '字'),
|
|
177
|
-
'worlds.memory-core.rawRetentionDays': num('
|
|
185
|
+
'worlds.memory-core.rawRetentionDays': num('原文热数据天数', '超过这么多天的对话会挪进 archive/ 按天归档,不再直接删。', 1, 90, '天'),
|
|
186
|
+
'worlds.memory-core.rawArchiveDays': num('归档保留天数', '归档按天存,超过这么多天的文件在启动时删掉。0 = 永久保留(占盘,自己看着办)。', 0, 3650, '天'),
|
|
187
|
+
'worlds.memory-core.captureBackfill': {
|
|
188
|
+
type: 'boolean',
|
|
189
|
+
title: '重扫历史补录',
|
|
190
|
+
description: '打开后重启一次:把水位倒回开头,把宿主还留着的历史消息重扫一遍。只做一次,做完自动关掉自己。',
|
|
191
|
+
'x-hot': false,
|
|
192
|
+
},
|
|
178
193
|
'worlds.memory-core.recallLimit': num('一次召回给几条', '默认 5 条。给多了挤占上下文。', 1, 12, '条'),
|
|
179
194
|
'worlds.memory-core.recallMaxChars': num('召回结果字数上限', '超过就截断,默认 600 字。', 120, 2000, '字'),
|
|
180
195
|
'worlds.memory-core.contextEveryMin': num('状态投递间隔', '每隔这么多分钟把「我在做什么」推到上下文里。0 = 不推(默认,最省);推一次约 60 token,但每轮都在历史里。', 0, 240, '分钟'),
|
package/src/recall.ts
CHANGED
|
@@ -81,8 +81,12 @@ export function rankCards(cards: readonly Card[], opts: RankOptions): Card[] {
|
|
|
81
81
|
return pool.slice(0, opts.limit);
|
|
82
82
|
}
|
|
83
83
|
const scored = pool.map((card) => {
|
|
84
|
-
const lexical = overlap(queryTokens,
|
|
85
|
-
|
|
84
|
+
const lexical = overlap(queryTokens, card.text);
|
|
85
|
+
// 标签单独算一次:对方说「生日」时,打了 #生日 的卡要比正文里顺嘴提到的排得靠前
|
|
86
|
+
const tagHit = card.tags.length ? overlap(queryTokens, card.tags.join(' ')) : 0;
|
|
87
|
+
// 同一张卡被反复召回只做有限的边际压制(封顶 8 次),别让常用的重要记忆越用越沉
|
|
88
|
+
const used = Math.min(card.uses || 0, 8) * 0.03;
|
|
89
|
+
const score = lexical * 2 + tagHit * 1.2 + card.weight * 0.5 + freshness(card.createdAt, now) - used;
|
|
86
90
|
return { card, score };
|
|
87
91
|
});
|
|
88
92
|
scored.sort((a, b) => b.score - a.score);
|
package/src/site.ts
CHANGED