cortico-world-memory-core 0.4.1 → 0.4.2

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,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.2
4
+
5
+ 按「第一批」做的三件事,其中第一件顺带挖出一个从 0.1.0 就带着的 bug。
6
+
7
+ - **原文页加「含归档」开关**:原来页面只搜最近 7 天的热数据,10-27 之前的句子在 `archive/` 里,一搜就是「没有匹配的对话」,看着像根本没记过。现在勾上开关会调 `/api/archive` 把归档也搜一遍,命中按天分组列在下面;开关状态记在本地,下次打开还记得。
8
+ - **深链接支持 `?q=` 和 `?archive=1`**:链接可以直接打开某个搜索结果,例如 `/?view=turns&q=泡馍&archive=1`。
9
+ - **修好搜索框**:`el.search` 的输入回调里写成了 `S.searchClear`,而 `S` 上根本没有这个属性——从 0.1.0 起,每敲一个字都在抛 `TypeError`,只是异常被吞掉,看起来像「搜索要等一会儿才生效」(实际是等 20 秒轮询重绘)。现在改成 `el.searchClear`。
10
+ - **提示词调 episode / fact 配比**:`episode` 从「发生过的一件事」收紧成「只写会改变你怎么看她的一件事,流水账不记,一天最多 2 条」,并把「能写成 fact 就别写成 episode」提到段首。实测 65 条里 48 条是 episode、只有 8 条 fact,这个比例说明它在记流水账。提示词 750 → 785 字(顺手把状态/日程那句压短,净增 28 tok)。
11
+ - 顺带把 4 条误标成 `promise` 的记录改回正确类型(两条已完成的改成 `episode`,一条常驻要求改成 `fact`),"没有截止时间"从 4 条降到 1 条。
12
+
3
13
  ## 0.4.1
4
14
 
5
15
  0.4.0 没发到 npm,这里补上它漏掉的两件事——都是「承诺闭环」那一处。
package/ENV_PROMPT.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  你现在只有一套记忆:`mcore_write` 写进去,`mcore_recall` 查出来。旧的几套记忆已经并进这里,不要再提「另一个记忆系统」,也不要问对方「要记在哪」。
4
4
 
5
- 写什么:
6
- - `fact` 关于对方的稳定事实(名字、作息、忌讳、正在忙的事)。
7
- - `self` 关于你自己的(喜欢什么、怕什么、决定过什么)。
8
- - `episode` 发生过的一件事,带上当时的感觉。
5
+ 写什么(能写成 fact 就别写成 episode):
6
+ - `fact` 关于对方的稳定事实(名字、作息、忌讳、正在忙的事、明确要求过的事)。
9
7
  - `promise` 答应过的事,必须写 `dueAt`(不知道就先问一句;确实没有截止时间就写 `none`);做完或改了传 `closes`(查出来的行首 8 位就是 id)。
8
+ - `self` 关于你自己的(喜欢什么、怕什么、决定过什么)。
9
+ - `episode` 只写会改变你怎么看她的一件事,带上当时的感受;流水账不记,一天最多 2 条。
10
10
  - `note` 过几天就没用的临时信息。
11
11
 
12
12
  写法:一条一件事,40–80 字,写清楚谁、什么时候、怎么了;不要写「对方说了一些事」这种空话。同一件事不要写两遍,记不清就先查。`weight` 是这事在你心里的分量,0.3 琐事 / 0.5 一般 / 0.8 重要。
@@ -14,6 +14,6 @@
14
14
  查法:`mcore_recall` 不传 `query` 就是最近几条;传 `query` 搜内容,最近 7 天的对话原文和工作区里的笔记文件也会一起搜,更早的加 `mode=archive` 翻归档;`mode=open` 看没做完的承诺和今天的安排。
15
15
  什么时候查:对方提到某个人、某件事、某个日期、旧约定,或者问「你还记得吗」——先查再答,不要硬猜。
16
16
 
17
- 你自己也有状态:`mcore_state` 管精力、心情、正在做什么、在哪、睡没睡;`mcore_plan` 管今天的安排。这两样和记忆分开放,不要写进 `mcore_write`。
17
+ 状态和日程用 `mcore_state` / `mcore_plan`(精力、心情、在做什么、今天的安排),不要写进 `mcore_write`。
18
18
 
19
19
  分寸:记忆是你记得的东西,不是拿来念的清单。可以自然地说「我记得你说过……」;不确定的就直接问,别编。
package/README.md CHANGED
@@ -53,7 +53,7 @@ pnpm add cortico-world-memory-core
53
53
  | 图谱 | 力导向图:节点大小=权重、颜色=类型、连线=共同标签或同一天;滚轮缩放、拖动、双击适应 |
54
54
  | 时间线 | 按天分组,带权重条与截止时间 |
55
55
  | 列表 | 可排序表格(类型 / 内容 / 权重 / 来源 / 标签 / 记于 / 使用次数),权重带微条 |
56
- | 原文 | 最近 7 天的对话原文,搜索高亮;更早的进 `archive/`,模型可用 `mode=archive` 翻回去 |
56
+ | 原文 | 最近 7 天的对话原文,搜索高亮;勾「含归档」能连 `archive/` 里更早的句子一起搜,命中按天分组列在下面 |
57
57
  | 文件 | 工作区里被检索的 md / txt(只读) |
58
58
  | 维护 | 重复 / 疑似作废 / 垃圾 / **承诺** / 回收站;承诺页能补截止时间、标记做完;彻底的删除会先列出要删的东西,10 秒内可撤销 |
59
59
  | 体检 | 在用 / 从没被召回 / 召回次数 / 原文规模、近 14 天新增、承诺与备份状态;从没被召回的卡能一键退休 |
@@ -61,7 +61,7 @@ pnpm add cortico-world-memory-core
61
61
  右栏是详情:可改文本、类型、权重、标签、截止时间,能复制、看相关记忆与版本链;没有选中时收成一条 46px 的窄条,把宽度还给舞台。
62
62
 
63
63
  快捷键:`/` 搜索 · `1–6` 切视图 · `J/K` 移动 · `Enter` 打开 · `E` 改 · `N` 新建 · `I` 右栏 · `R` 刷新 · `?` 帮助。
64
- 深链接:`/?view=timeline`、`/?card=<id>`。
64
+ 深链接:`/?view=timeline`、`/?card=<id>`、`/?view=turns&q=泡馍&archive=1`(第二个参数表示连归档一起搜)。
65
65
 
66
66
  导出与导入:`⋯` 菜单里能导出 Markdown / JSON。JSON 是整包(卡片 + 原文 + 日程 + 状态),可以原样 `POST /api/import` 导回来——**只加不覆盖**,同 id 或同类型同文本会跳过,所以重复导同一个文件是安全的。水位只往前推,不会被旧备份倒回去。
67
67
 
package/describe.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "tools": [
3
3
  {
4
4
  "name": "mcore_write",
5
- "description": "写一条记忆。kind:fact=关于对方的事实,self=关于你自己的,episode=发生过的一件事(带感受),promise=答应过的事(写 dueAt),note=过几天就没用的临时信息。一条只写一件事,40-80 字,写具体。同一件事不要重复写;把旧记录传进 closes 表示它已完成或作废。",
5
+ "description": "写一条记忆。kind:fact=关于对方的事实,self=关于你自己的,episode=会改变你怎么看她的一件事(别记流水账),promise=答应过的事(必须写 dueAt),note=过几天就没用的临时信息。能写成 fact 就别写成 episode。一条只写一件事,40-80 字,写具体。同一件事不要重复写;把旧记录传进 closes 表示它已完成或作废。",
6
6
  "parameters": {
7
7
  "type": "object",
8
8
  "additionalProperties": false,
@@ -258,7 +258,7 @@
258
258
  "key": "worlds.memory-core.envPrompt",
259
259
  "title": "记忆核心 · 环境提示词",
260
260
  "role": "envPrompt",
261
- "content": "【记忆核心】\n\n你现在只有一套记忆:`mcore_write` 写进去,`mcore_recall` 查出来。旧的几套记忆已经并进这里,不要再提「另一个记忆系统」,也不要问对方「要记在哪」。\n\n写什么:\n- `fact` 关于对方的稳定事实(名字、作息、忌讳、正在忙的事)。\n- `self` 关于你自己的(喜欢什么、怕什么、决定过什么)。\n- `episode` 发生过的一件事,带上当时的感觉。\n- `promise` 答应过的事,必须写 `dueAt`(不知道就先问一句;确实没有截止时间就写 `none`);做完或改了传 `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分寸:记忆是你记得的东西,不是拿来念的清单。可以自然地说「我记得你说过……」;不确定的就直接问,别编。"
261
+ "content": "【记忆核心】\n\n你现在只有一套记忆:`mcore_write` 写进去,`mcore_recall` 查出来。旧的几套记忆已经并进这里,不要再提「另一个记忆系统」,也不要问对方「要记在哪」。\n\n写什么(能写成 fact 就别写成 episode):\n- `fact` 关于对方的稳定事实(名字、作息、忌讳、正在忙的事、明确要求过的事)。\n- `promise` 答应过的事,必须写 `dueAt`(不知道就先问一句;确实没有截止时间就写 `none`);做完或改了传 `closes`(查出来的行首 8 位就是 id)。\n- `self` 关于你自己的(喜欢什么、怕什么、决定过什么)。\n- `episode` 只写会改变你怎么看她的一件事,带上当时的感受;流水账不记,一天最多 2 条。\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
262
  }
263
263
  ]
264
264
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-memory-core",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "Cortico World 长期记忆:一张卡片表 + 4 个工具 + 一段静态提示词,附状态、日程、主动开口与本地记忆地图。\n\nQQ 交流群:745879632",
6
6
  "keywords": [
@@ -31,11 +31,11 @@
31
31
  "locales": {
32
32
  "zh": {
33
33
  "displayName": "记忆核心",
34
- "description": "一张卡片表、四个工具、一段 750 字的静态提示词。改口不覆盖:旧卡退休、新卡记下接替了谁,召回时不会再同时看到作废的和改后的那条。附带状态、日程、主动开口,以及一个本地记忆地图(图谱 / 时间线 / 维护面板)。\n\nQQ 交流群:745879632"
34
+ "description": "一张卡片表、四个工具、一段 785 字的静态提示词。改口不覆盖:旧卡退休、新卡记下接替了谁,召回时不会再同时看到作废的和改后的那条。附带状态、日程、主动开口,以及一个本地记忆地图(图谱 / 时间线 / 维护面板)。\n\nQQ 交流群:745879632"
35
35
  },
36
36
  "en": {
37
37
  "displayName": "Memory Core",
38
- "description": "One card table, four tools and a 750-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.\n\nQQ group: 745879632"
38
+ "description": "One card table, four tools and a 785-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.\n\nQQ group: 745879632"
39
39
  }
40
40
  },
41
41
  "tags": [
package/src/site.ts CHANGED
@@ -51,7 +51,7 @@ export interface Snapshot {
51
51
  scopes: Array<{ scope: string; n: number }>;
52
52
  };
53
53
  docs: { enabled: boolean; count: number; dirs: string[] };
54
- archive: { days: number; bytes: number; oldest: string };
54
+ archive: { days: number; bytes: number; oldest: string; retention: number };
55
55
  site: { port: number; origin: string };
56
56
  }
57
57
 
@@ -98,6 +98,8 @@ export interface SiteHooks {
98
98
  purgeCards(ids: string[]): number;
99
99
  health(): HealthReport;
100
100
  importData(payload: Record<string, unknown>): ImportReport;
101
+ /** 在按天归档的旧原文里搜(页面上的「含归档」开关)。 */
102
+ archiveSearch(q: string, days: number, limit: number): RawEntry[];
101
103
  patchState(input: Record<string, unknown>): CoreState;
102
104
  planAction(input: Record<string, unknown>): unknown;
103
105
  exportAll(fmt: string): { body: string; mime: string; filename: string };
@@ -225,6 +227,12 @@ export class MemorySite {
225
227
  if (path === '/api/health' && req.method === 'GET') {
226
228
  return this.json(rsp, 200, this.hooks.health());
227
229
  }
230
+ if (path === '/api/archive' && req.method === 'GET') {
231
+ const q = (url.searchParams.get('q') ?? '').trim();
232
+ const days = Number(url.searchParams.get('days') ?? 90) || 90;
233
+ const limit = Number(url.searchParams.get('limit') ?? 40) || 40;
234
+ return this.json(rsp, 200, q ? this.hooks.archiveSearch(q, days, limit) : []);
235
+ }
228
236
  if (path === '/api/import' && req.method === 'POST') {
229
237
  let body: Record<string, unknown>;
230
238
  try {
package/src/tools.ts CHANGED
@@ -15,8 +15,8 @@ export const TOOL_SPECS: ToolSpec[] = [
15
15
  {
16
16
  name: 'mcore_write',
17
17
  description:
18
- '写一条记忆。kind:fact=关于对方的事实,self=关于你自己的,episode=发生过的一件事(带感受),'
19
- + 'promise=答应过的事(写 dueAt),note=过几天就没用的临时信息。'
18
+ '写一条记忆。kind:fact=关于对方的事实,self=关于你自己的,episode=会改变你怎么看她的一件事(别记流水账),'
19
+ + 'promise=答应过的事(必须写 dueAt),note=过几天就没用的临时信息。能写成 fact 就别写成 episode。'
20
20
  + '一条只写一件事,40-80 字,写具体。同一件事不要重复写;把旧记录传进 closes 表示它已完成或作废。',
21
21
  parameters: obj(
22
22
  {
package/src/world.ts CHANGED
@@ -385,7 +385,7 @@ export class MemoryCoreWorld implements World {
385
385
  scopes: this.store.scopes(),
386
386
  },
387
387
  docs: { enabled: Boolean(cfg.workspaceScanEnabled), count: docs.length, dirs: cfg.workspaceScanEnabled ? expandDirs(cfg.workspaceDirs, this.ctx.botDir) : [] },
388
- archive: this.raw.stats(),
388
+ archive: { ...this.raw.stats(), retention: Math.max(0, Number(cfg.rawArchiveDays) || 0) },
389
389
  site: { port: origin ? Number(new URL(origin).port) : 0, origin },
390
390
  };
391
391
  }
@@ -456,6 +456,13 @@ export class MemoryCoreWorld implements World {
456
456
  }),
457
457
  health: () => this.healthReport(),
458
458
  importData: (payload: Record<string, unknown>) => this.importBackup(payload),
459
+ archiveSearch: (q: string, days: number, limit: number) => {
460
+ const query = String(q ?? '').trim();
461
+ if (!query) return [];
462
+ const span = Math.min(3650, Math.max(1, Number(days) || 90));
463
+ const cap = Math.min(50, Math.max(1, Number(limit) || 40));
464
+ return rankRaw(this.raw.readArchive(span, 20000), query, cap);
465
+ },
459
466
  mergeCards: (keepId: string, dropIds: string[]) => this.store.merge(keepId, dropIds),
460
467
  purgeCards: (ids: string[]) => this.store.purge(ids),
461
468
  patchState: (input: Record<string, unknown>) => {