lingshu-skill 5.52.0 → 5.54.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 +59 -0
- package/README.md +1 -1
- package/SKILL-lite.md +1 -1
- package/SKILL-tiny.md +1 -1
- package/SKILL.md +1 -1
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +7 -7
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +59 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +13 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +122 -38
- package/scripts/emotion.py +13 -0
- package/scripts/persona.py +122 -38
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v5.54(2026-12-04)
|
|
4
|
+
|
|
5
|
+
### 🩺 人格自愈兜底(PERSONA-AUTOHEAL)
|
|
6
|
+
|
|
7
|
+
排查中发现人格会被未预见的路径写空(本次已是第五至第七次),逐条堵漏成本过高。
|
|
8
|
+
改为**自愈兜底**:
|
|
9
|
+
- `save_persona` 每次成功保存"有名字"的人格时,同步写一份 `persona.lastgood.json`;
|
|
10
|
+
- `load_persona` 读到空态(无名字无特质)时**自动从 lastgood 回滚**,保留瞬态字段(state.affection)。
|
|
11
|
+
|
|
12
|
+
实测:人为清空 persona.json 后调用 `load_persona()` → 自动回滚到「砚」,无需人工恢复。
|
|
13
|
+
|
|
14
|
+
### 🐛 emotion.py 命名空间缺陷(NAMESPACE-FIX)
|
|
15
|
+
|
|
16
|
+
**这是情绪事件长期几乎不产生的隐藏根因**:`emotion.py` 里的 `load_persona`/`mind_state` 等名字
|
|
17
|
+
依赖 `brain.py` 的星号合并命名空间——**单独 import emotion 就 NameError**。
|
|
18
|
+
所以 `persona.daily_drift` 调 `_emo.feel()` 时直接崩(被 try/except 吞掉),心情快照写不进去。
|
|
19
|
+
|
|
20
|
+
**修复**:emotion.py 加安全 fallback——优先用合并名,缺失则 `from persona import load_persona`。
|
|
21
|
+
实测 `feel()` 追加 1→2 条,timeline 正常增长。
|
|
22
|
+
|
|
23
|
+
### 🌊 心情快照端到端打通
|
|
24
|
+
|
|
25
|
+
daily_drift 的每日实测 EMA 快照现在真的能写入 emotions.jsonl(timeline 1→2 实测通过)。
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## v5.53(2026-12-04)
|
|
30
|
+
|
|
31
|
+
### 🧠 自我认知四桶真实填充(SELF-MODEL-FILL)
|
|
32
|
+
|
|
33
|
+
四桶长期为空(strengths/uncertainties/autobiography),排查发现两个数据通路依赖**真实数据里不存在的字段**:
|
|
34
|
+
- `uncertainties` 要求 insight 带 confidence 0.4~0.6 ——实测 23 条 insight 里 **0 条**有该字段(只有教训库用)
|
|
35
|
+
- `strengths` 要求带 emotion 字段 ——实测高重要度记忆 **emo 全为 None**
|
|
36
|
+
|
|
37
|
+
**改用真实存在的信号**:
|
|
38
|
+
- `uncertainties` ← `superseded_by`(被新结论取代的旧记忆):"曾经以为…"是认知修正最诚实的痕迹
|
|
39
|
+
- `strengths` ← 重要度≥0.75 且 `access_count`≥3:被系统反复召回=真的在用,不靠自夸
|
|
40
|
+
- `limitations` ← 补 `mistake` 类记忆(13 条)——原路只认 correction=True(全库仅 1 条)
|
|
41
|
+
|
|
42
|
+
**实测**:strengths 8 / uncertainties 8 / limitations 9,全部可溯源到具体记忆。
|
|
43
|
+
|
|
44
|
+
### 🌊 心情流水快照(MOOD-SNAPSHOT)
|
|
45
|
+
|
|
46
|
+
emotion_timeline 长期只有 1 条——根因是 `auto_appraise` 只在 `extract`(封存对话)时调用,日常 remember/capture 不经过它。
|
|
47
|
+
|
|
48
|
+
**补充**:daily_drift 每天写一条**实测** EMA 快照进 emotions.jsonl(genesis=False,标"每日快照")——不是编造情绪,是把真实测得的心情记进流水,让时间线有连续曲线。20h 内只记一次。
|
|
49
|
+
|
|
50
|
+
### 🛡️ PERSONA-GUARD v3(守卫自身缺陷修正)
|
|
51
|
+
|
|
52
|
+
本轮排查中发现 v2 守卫方向错了:无条件拒绝空态写入会让**首次初始化返回 None**,连锁崩掉 overview 与全部单测(实测 9/11、10/12、3/5 挂)。
|
|
53
|
+
|
|
54
|
+
**修正**:只在【会丢数据】时拦(盘上已有名字/特质/历史 + 产物为空);首次创建必须放行;`compile_persona` 任何分支都不返回 None。
|
|
55
|
+
|
|
56
|
+
### 🐛 附带发现
|
|
57
|
+
|
|
58
|
+
四桶条目必须是**纯字符串**——`_ensure_self_model` 会丢弃 dict 类型条目(v5.52 的 {ts,text} 形式被静默清空,导致 added 报 8 但桶里为 0)。
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
3
62
|
## v5.52(2026-12-04)
|
|
4
63
|
|
|
5
64
|
### 🌱 内驱真实演化(DRIVE-EVOLVE)
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
> 当前版本 **v5.
|
|
5
|
+
> 当前版本 **v5.54**(变更见 [CHANGELOG.md](CHANGELOG.md))
|
|
6
6
|
|
|
7
7
|
> 🔁 **双仓库镜像**:GitHub(主)与 Gitee(镜像)保持同步——[gitee.com/htmcwy_0/lingshu-skill](https://gitee.com/htmcwy_0/lingshu-skill)。灵枢的更新检查会探测两边最新提交,**谁更新就自动从谁拉取**;任一边不可达(Gitee 匿名风控 / GitHub 限额)时走另一边兜底。
|
|
8
8
|
|
package/SKILL-lite.md
CHANGED
package/SKILL-tiny.md
CHANGED
package/SKILL.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingshu-skill",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.54.0",
|
|
4
4
|
"description": "Brain-inspired persistent memory, persona and growth system for AI coding agents. Local-only, zero-dependency Python. Requires Python 3.10+.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"PATCH_NOTES.md": "9296e524f743f358fd11115598398a754cfd69534526dde9c8ad85f14a418f89",
|
|
3
3
|
"README.md": "3d634d743b085eebd2cbb5dd3a00edfa728ed23947e20cc29e7c3b29087ec043",
|
|
4
|
-
"engine/CHANGELOG.md": "
|
|
5
|
-
"engine/README.md": "
|
|
6
|
-
"engine/SKILL-lite.md": "
|
|
7
|
-
"engine/SKILL-tiny.md": "
|
|
8
|
-
"engine/SKILL.md": "
|
|
4
|
+
"engine/CHANGELOG.md": "b4e298460f44a4fbc3ff6767e8cacdc17971900e99830940e41d0f689e6ee6ca",
|
|
5
|
+
"engine/README.md": "ba60a2eac513de30e7fcf7b16e07cfd26e83f287967db868f8e584729592bbf9",
|
|
6
|
+
"engine/SKILL-lite.md": "f8b90fafcc48b6c8cb0e0e107701bd06af71b42546fc6255e412f6231199d53e",
|
|
7
|
+
"engine/SKILL-tiny.md": "1bf1fed97d93a1b08a4894dfcd876fe99661c6f11e11402342faf9aaf0cab25d",
|
|
8
|
+
"engine/SKILL.md": "d5d3e9ea49cee1e704641affdf827dbfdcd05a58fb1837ab2ae1114c1c708ff2",
|
|
9
9
|
"engine/assets/panel.html": "1b015d80e2d6ec8d52eee7a970f535877938adddc1cef0fd6629778e87f63c42",
|
|
10
10
|
"engine/docs/commands.md": "0ce8c88e5d2d04a8055b45c060ebd53b50c52b79b650312e2ee440845804ca4b",
|
|
11
11
|
"engine/docs/mechanics.md": "aa9683c827ed3419106e84d847ab16dc310c27fc62f588184192aaa1617523cc",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"engine/scripts/delivery.py": "6a4bf2caac9dca41b43c06d31f7cfc328bae19d3fb618da26b35f1a214071a11",
|
|
31
31
|
"engine/scripts/desktop_shortcut.py": "77ea248bfaaf28e1e4299979d0c0d8c80a055642dde9a40f5e297b2008474091",
|
|
32
32
|
"engine/scripts/dream.py": "a8c6784ca5f0d9bcce6f1e70e13bc38e70ecb94930941dea943934903d45dc53",
|
|
33
|
-
"engine/scripts/emotion.py": "
|
|
33
|
+
"engine/scripts/emotion.py": "e038024dfced6b497b7cc673474b2b4948323cae09b0a6df15498af1c9002daa",
|
|
34
34
|
"engine/scripts/failures.py": "3a16234a1871f62e3ba7b7b743110b4044fb7b715b4d0e924b8ebf1cf0be50d0",
|
|
35
35
|
"engine/scripts/fallback_embed.py": "11339a9f5040aea8952fdd45f4183cdfb0f00266ff61e200f3b4e8a62778f6e0",
|
|
36
36
|
"engine/scripts/gap_memory.py": "cb4b46479cf77b706205bf2e2e2c806d6b1952a7924ee9517425e026f53df577",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"engine/scripts/panel_splash.py": "36cd59e593ce52557a180a8767bfa9cd9c803f0cccaa141e7da8babd5a35e925",
|
|
62
62
|
"engine/scripts/panel_update.py": "6ff1a0687c05e3ef4ae846058abea4dacf985a3fe6adcdbb4eef1b38e27139b5",
|
|
63
63
|
"engine/scripts/panels.py": "9db94038c2c11fc5da0f2f7c3292d01053acfaf1b74f1517a1f1c4402895fef4",
|
|
64
|
-
"engine/scripts/persona.py": "
|
|
64
|
+
"engine/scripts/persona.py": "88c78b957c875bad62d67ff5d4073c713e9e469de08f1e02b329f245d3b793fe",
|
|
65
65
|
"engine/scripts/prepublish_tests.py": "8d116de1edd3ab57584a6a2749598cf127e918383da67e50118601e5a3970c2a",
|
|
66
66
|
"engine/scripts/release.py": "b4271c06802d6154e90715cc566e4104f5d6de0b9efa6f4907643e686bb5c48e",
|
|
67
67
|
"engine/scripts/retriever.py": "85a35f8f660767cff1c068e722b51e3b5623c4dffe4822527eee96f9220240d3",
|
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v5.54(2026-12-04)
|
|
4
|
+
|
|
5
|
+
### 🩺 人格自愈兜底(PERSONA-AUTOHEAL)
|
|
6
|
+
|
|
7
|
+
排查中发现人格会被未预见的路径写空(本次已是第五至第七次),逐条堵漏成本过高。
|
|
8
|
+
改为**自愈兜底**:
|
|
9
|
+
- `save_persona` 每次成功保存"有名字"的人格时,同步写一份 `persona.lastgood.json`;
|
|
10
|
+
- `load_persona` 读到空态(无名字无特质)时**自动从 lastgood 回滚**,保留瞬态字段(state.affection)。
|
|
11
|
+
|
|
12
|
+
实测:人为清空 persona.json 后调用 `load_persona()` → 自动回滚到「砚」,无需人工恢复。
|
|
13
|
+
|
|
14
|
+
### 🐛 emotion.py 命名空间缺陷(NAMESPACE-FIX)
|
|
15
|
+
|
|
16
|
+
**这是情绪事件长期几乎不产生的隐藏根因**:`emotion.py` 里的 `load_persona`/`mind_state` 等名字
|
|
17
|
+
依赖 `brain.py` 的星号合并命名空间——**单独 import emotion 就 NameError**。
|
|
18
|
+
所以 `persona.daily_drift` 调 `_emo.feel()` 时直接崩(被 try/except 吞掉),心情快照写不进去。
|
|
19
|
+
|
|
20
|
+
**修复**:emotion.py 加安全 fallback——优先用合并名,缺失则 `from persona import load_persona`。
|
|
21
|
+
实测 `feel()` 追加 1→2 条,timeline 正常增长。
|
|
22
|
+
|
|
23
|
+
### 🌊 心情快照端到端打通
|
|
24
|
+
|
|
25
|
+
daily_drift 的每日实测 EMA 快照现在真的能写入 emotions.jsonl(timeline 1→2 实测通过)。
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## v5.53(2026-12-04)
|
|
30
|
+
|
|
31
|
+
### 🧠 自我认知四桶真实填充(SELF-MODEL-FILL)
|
|
32
|
+
|
|
33
|
+
四桶长期为空(strengths/uncertainties/autobiography),排查发现两个数据通路依赖**真实数据里不存在的字段**:
|
|
34
|
+
- `uncertainties` 要求 insight 带 confidence 0.4~0.6 ——实测 23 条 insight 里 **0 条**有该字段(只有教训库用)
|
|
35
|
+
- `strengths` 要求带 emotion 字段 ——实测高重要度记忆 **emo 全为 None**
|
|
36
|
+
|
|
37
|
+
**改用真实存在的信号**:
|
|
38
|
+
- `uncertainties` ← `superseded_by`(被新结论取代的旧记忆):"曾经以为…"是认知修正最诚实的痕迹
|
|
39
|
+
- `strengths` ← 重要度≥0.75 且 `access_count`≥3:被系统反复召回=真的在用,不靠自夸
|
|
40
|
+
- `limitations` ← 补 `mistake` 类记忆(13 条)——原路只认 correction=True(全库仅 1 条)
|
|
41
|
+
|
|
42
|
+
**实测**:strengths 8 / uncertainties 8 / limitations 9,全部可溯源到具体记忆。
|
|
43
|
+
|
|
44
|
+
### 🌊 心情流水快照(MOOD-SNAPSHOT)
|
|
45
|
+
|
|
46
|
+
emotion_timeline 长期只有 1 条——根因是 `auto_appraise` 只在 `extract`(封存对话)时调用,日常 remember/capture 不经过它。
|
|
47
|
+
|
|
48
|
+
**补充**:daily_drift 每天写一条**实测** EMA 快照进 emotions.jsonl(genesis=False,标"每日快照")——不是编造情绪,是把真实测得的心情记进流水,让时间线有连续曲线。20h 内只记一次。
|
|
49
|
+
|
|
50
|
+
### 🛡️ PERSONA-GUARD v3(守卫自身缺陷修正)
|
|
51
|
+
|
|
52
|
+
本轮排查中发现 v2 守卫方向错了:无条件拒绝空态写入会让**首次初始化返回 None**,连锁崩掉 overview 与全部单测(实测 9/11、10/12、3/5 挂)。
|
|
53
|
+
|
|
54
|
+
**修正**:只在【会丢数据】时拦(盘上已有名字/特质/历史 + 产物为空);首次创建必须放行;`compile_persona` 任何分支都不返回 None。
|
|
55
|
+
|
|
56
|
+
### 🐛 附带发现
|
|
57
|
+
|
|
58
|
+
四桶条目必须是**纯字符串**——`_ensure_self_model` 会丢弃 dict 类型条目(v5.52 的 {ts,text} 形式被静默清空,导致 added 报 8 但桶里为 0)。
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
3
62
|
## v5.52(2026-12-04)
|
|
4
63
|
|
|
5
64
|
### 🌱 内驱真实演化(DRIVE-EVOLVE)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
> 当前版本 **v5.
|
|
5
|
+
> 当前版本 **v5.54**(变更见 [CHANGELOG.md](CHANGELOG.md))
|
|
6
6
|
|
|
7
7
|
> 🔁 **双仓库镜像**:GitHub(主)与 Gitee(镜像)保持同步——[gitee.com/htmcwy_0/lingshu-skill](https://gitee.com/htmcwy_0/lingshu-skill)。灵枢的更新检查会探测两边最新提交,**谁更新就自动从谁拉取**;任一边不可达(Gitee 匿名风控 / GitHub 限额)时走另一边兜底。
|
|
8
8
|
|
|
@@ -1086,6 +1086,19 @@ def emotion_arc(days: int = 7) -> dict:
|
|
|
1086
1086
|
# 情绪太激动时杏仁核会压制前额叶——理智值会临时下降,但永远压不掉一半以上。
|
|
1087
1087
|
# * 重要的事(钱/关系/承诺/健康)在任何情绪下都留给用户决定,情绪不替用户拍板。
|
|
1088
1088
|
|
|
1089
|
+
# NAMESPACE-FIX(v5.54):emotion.py 里的 load_persona / mind_state / feel 等名字
|
|
1090
|
+
# 原依赖 brain.py 的星号合并命名空间——单独 import emotion 就 NameError
|
|
1091
|
+
# (实测:persona.daily_drift 调 _emo.feel 时崩 "load_persona is not defined")。
|
|
1092
|
+
# 这里补一个安全的本地绑定:优先用已有合并名,缺失则直接取 persona 模块的实现。
|
|
1093
|
+
try:
|
|
1094
|
+
load_persona # noqa: B018 已由 brain 合并命名空间提供
|
|
1095
|
+
except NameError: # pragma: no cover - 仅在单独 import 时触发
|
|
1096
|
+
try:
|
|
1097
|
+
from persona import load_persona, save_persona # type: ignore
|
|
1098
|
+
except Exception:
|
|
1099
|
+
pass
|
|
1100
|
+
|
|
1101
|
+
|
|
1089
1102
|
def emotion_cfg() -> dict:
|
|
1090
1103
|
"""情感设置(用户随时可改):共情程度 / 抑制的情绪 / 备注。存在人格档案里。"""
|
|
1091
1104
|
p = load_persona()
|
|
@@ -270,11 +270,17 @@ def compile_persona() -> dict:
|
|
|
270
270
|
_disk_now = _slurp_json(HOME / "persona.json") if (HOME / "persona.json").exists() else None
|
|
271
271
|
_disk_named = bool((( _disk_now or {}).get("identity") or {}).get("名字"))
|
|
272
272
|
_incoming_named = bool(((p.get("identity") or {}).get("名字") or "").strip())
|
|
273
|
-
|
|
273
|
+
# PERSONA-GUARD v3:只在【会丢数据】时拦(盘上已有实质内容 + 产物为空),
|
|
274
|
+
# 首次创建(无文件/盘上空)必须放行——v2 的无条件拒绝让初始化返回 None,
|
|
275
|
+
# 连锁崩掉 overview 与全部单测(12-04 03:22 实测)。
|
|
276
|
+
_disk_sub = (bool(str((_disk_now.get("identity") or {}).get("名字") or "").strip())
|
|
277
|
+
or bool(_disk_now.get("traits") or {})
|
|
278
|
+
or bool(_disk_now.get("history") or [])) if isinstance(_disk_now, dict) else False
|
|
279
|
+
if _disk_sub and not _incoming_named and not (p.get("traits") or {}):
|
|
274
280
|
log_event("persona",
|
|
275
|
-
"compile_persona
|
|
281
|
+
"compile_persona 拒绝覆盖:盘上已有实质人格而被空态重建覆盖——已拦下。",
|
|
276
282
|
level="error")
|
|
277
|
-
return
|
|
283
|
+
return _disk_now if isinstance(_disk_now, dict) else default_persona()
|
|
278
284
|
atomic_json(HOME / "persona.json", p)
|
|
279
285
|
# SPEED-1 缓存同步失效:compile_persona 直写绕过了 save_persona 的失效点
|
|
280
286
|
global _lp_cache, _lp_cache_mtime, _lp_cache_time
|
|
@@ -327,6 +333,24 @@ def load_persona() -> dict:
|
|
|
327
333
|
else:
|
|
328
334
|
# 只读且档案缺失:给一份内存默认值,不影响读取已有记忆
|
|
329
335
|
p = compile_persona() if not READONLY else default_persona()
|
|
336
|
+
# PERSONA-AUTOHEAL(v5.54):读到空态(无名字无特质)时自动从 lastgood 回滚。
|
|
337
|
+
# 这是最后一道网——即使某条未预见的路径把盘写空,人格也不会真的丢。
|
|
338
|
+
try:
|
|
339
|
+
_empty_now = (not str(((p.get("identity") or {}).get("名字") or "")).strip()
|
|
340
|
+
and not (p.get("traits") or {}))
|
|
341
|
+
_lg = HOME / "persona.lastgood.json"
|
|
342
|
+
if _empty_now and _lg.exists():
|
|
343
|
+
_good = _slurp_json(_lg)
|
|
344
|
+
if isinstance(_good, dict) and str(((_good.get("identity") or {}).get("名字") or "")).strip():
|
|
345
|
+
if isinstance(p.get("state"), dict) and isinstance(_good.get("state"), dict):
|
|
346
|
+
_merged = dict(_good["state"])
|
|
347
|
+
_merged.update({kk: vv for kk, vv in p["state"].items() if vv is not None})
|
|
348
|
+
_good["state"] = _merged
|
|
349
|
+
p = _good
|
|
350
|
+
log_event("persona", "检测到人格空态,已自动从 persona.lastgood.json 回滚", level="warn")
|
|
351
|
+
except Exception:
|
|
352
|
+
pass
|
|
353
|
+
|
|
330
354
|
changed = False
|
|
331
355
|
if "onboarding" not in p:
|
|
332
356
|
p["onboarding"] = default_onboarding()
|
|
@@ -394,6 +418,13 @@ def save_persona(p: dict) -> None:
|
|
|
394
418
|
pass # 守卫自身绝不阻塞正常保存
|
|
395
419
|
with _locked(HOME / "persona.json"):
|
|
396
420
|
atomic_json(HOME / "persona.json", p)
|
|
421
|
+
# PERSONA-AUTOHEAL(v5.54):每次成功保存"有名字"的人格,同步留一份 lastgood。
|
|
422
|
+
# 这样无论哪条路径把人格写空,load_persona 都能自动回滚——不再依赖人工恢复。
|
|
423
|
+
try:
|
|
424
|
+
if str(((p.get("identity") or {}).get("名字") or "")).strip():
|
|
425
|
+
atomic_json(HOME / "persona.lastgood.json", p)
|
|
426
|
+
except Exception:
|
|
427
|
+
pass
|
|
397
428
|
|
|
398
429
|
|
|
399
430
|
def _snapshot_path() -> Path:
|
|
@@ -1469,6 +1500,26 @@ def daily_drift(days: int = 1) -> dict:
|
|
|
1469
1500
|
applied = True
|
|
1470
1501
|
audit_log("ai", "daily_drift", "state.mood_score",
|
|
1471
1502
|
f"{int(cur)}→{new}(近{days}天 net={net})")
|
|
1503
|
+
# —— 心情快照(MOOD-SNAPSHOT v5.53)——
|
|
1504
|
+
# 历史问题:emotion_timeline 只有 1 条——因为 auto_appraise 只在 extract(封存对话)
|
|
1505
|
+
# 时调用,日常 remember/capture 不经过它。补一条**每��实测**的 EMA 快照进
|
|
1506
|
+
# emotions.jsonl(genesis=False,标 source=daily-snapshot):
|
|
1507
|
+
# 不是编造情绪,是把当天真实测得的心情记进流水,让时间线有连续曲线。
|
|
1508
|
+
try:
|
|
1509
|
+
import emotion as _emo
|
|
1510
|
+
_m = _emo.mood_now()
|
|
1511
|
+
if _m.get("active") or _m.get("label") not in (None, "", "平静"):
|
|
1512
|
+
_mood_hist = p.setdefault("state", {}).setdefault("_mood_snap_ts", 0)
|
|
1513
|
+
if now - _num(_mood_hist, 0) >= 20 * 3600: # 20h 内只记一次
|
|
1514
|
+
_emo.feel(_m.get("label") or "平静",
|
|
1515
|
+
intensity=max(0.05, min(0.6, _num(_m.get("intensity"), 0.1))),
|
|
1516
|
+
why=f"每日心情快照:{_m.get('label')}(强度 {_num(_m.get('intensity'), 0):.0%})",
|
|
1517
|
+
about="每日快照", genesis=False)
|
|
1518
|
+
p["state"]["_mood_snap_ts"] = now
|
|
1519
|
+
applied = True
|
|
1520
|
+
except Exception as _e:
|
|
1521
|
+
log_event("persona", f"心情快照写入失败(不影响其他):{_e}", level="warn")
|
|
1522
|
+
|
|
1472
1523
|
# —— 内驱演化(DRIVE-EVOLVE v5.52)——
|
|
1473
1524
|
# 历史问题:mind_tune 只有 CLI 手动路径,从初识后好奇/理智永远不变。
|
|
1474
1525
|
# 这里用【真实信号】驱动(都可追溯到记忆库),每天最多 ±2,带 history 留痕:
|
|
@@ -2625,61 +2676,94 @@ def self_model_autosink() -> dict:
|
|
|
2625
2676
|
sm["autobiography"].sort(key=lambda e: _num(e.get("ts"), 0), reverse=True)
|
|
2626
2677
|
del sm["autobiography"][_SELF_MODEL_MAX:]
|
|
2627
2678
|
|
|
2628
|
-
# —— 路 3
|
|
2629
|
-
# confidence 0.4~0.6
|
|
2679
|
+
# —— 路 3:被取代的旧结论 → uncertainties(IDEA-10 实装版)——
|
|
2680
|
+
# 原实现要求 insight 带 confidence 0.4~0.6 字段,但实测 23 条 insight 里
|
|
2681
|
+
# **0 条有 confidence**(该字段只有教训库用)→ 死代码。
|
|
2682
|
+
# 改用真实存在的信号:superseded_by(被新结论取代的旧记忆)——
|
|
2683
|
+
# "我当时是这么想的,后来发现不成立"正是最诚实的认知修正痕迹。
|
|
2630
2684
|
try:
|
|
2631
2685
|
import memory as _mem
|
|
2632
2686
|
uncer: list = []
|
|
2633
2687
|
for r in _mem.load_all():
|
|
2634
|
-
if not isinstance(r, dict) or r.get("
|
|
2635
|
-
continue
|
|
2636
|
-
conf = _num(r.get("confidence"), -1)
|
|
2637
|
-
if not (0.4 <= conf < 0.6):
|
|
2688
|
+
if not isinstance(r, dict) or not r.get("superseded_by"):
|
|
2638
2689
|
continue
|
|
2639
2690
|
ts_r = _num(r.get("ts"), 0) or _num(r.get("created"), 0)
|
|
2640
|
-
if now - ts_r >
|
|
2691
|
+
if now - ts_r > 90 * 86400: # 三个月前的旧账不再翻
|
|
2641
2692
|
continue
|
|
2642
|
-
|
|
2643
|
-
if
|
|
2644
|
-
uncer.append({"ts": ts_r, "text": t[:160]})
|
|
2645
|
-
uncer.sort(key=lambda e: e["ts"], reverse=True)
|
|
2646
|
-
existing_u = {e.get("text") for e in sm["uncertainties"]}
|
|
2647
|
-
for e in uncer[:8]:
|
|
2648
|
-
if e["text"] in existing_u:
|
|
2693
|
+
t0 = str(r.get("text") or r.get("summary") or "").strip()
|
|
2694
|
+
if not t0:
|
|
2649
2695
|
continue
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2696
|
+
uncer.append((ts_r, "曾经以为:" + t0[:140]))
|
|
2697
|
+
uncer.sort(key=lambda e: e[0], reverse=True)
|
|
2698
|
+
existing_u = set(sm["uncertainties"])
|
|
2699
|
+
for _ts, txt in uncer[:8]:
|
|
2700
|
+
if txt in existing_u:
|
|
2701
|
+
continue
|
|
2702
|
+
sm["uncertainties"].append(txt) # 纯字符串:_ensure_self_model 只保留 str
|
|
2703
|
+
added["uncertainties"].append(txt)
|
|
2704
|
+
if len(sm["uncertainties"]) > _SELF_MODEL_MAX:
|
|
2705
|
+
del sm["uncertainties"][:-_SELF_MODEL_MAX]
|
|
2653
2706
|
except Exception as e:
|
|
2654
|
-
log_event("persona", f"self_model_autosink
|
|
2707
|
+
log_event("persona", f"self_model_autosink 被取代结论路失败:{e}", level="warn")
|
|
2655
2708
|
|
|
2656
|
-
# —— 路 4
|
|
2657
|
-
#
|
|
2709
|
+
# —— 路 4:反复被召回使用的高价值结论 → strengths(IDEA-10 实装版)——
|
|
2710
|
+
# 原实现要求 importance>=0.8 + access_count>=3 + 带 emotion 字段,
|
|
2711
|
+
# 但实测高重要度记忆 emo 几乎全为 None → 死代码。
|
|
2712
|
+
# 改用真实信号:importance>=0.75 且 access_count>=3——
|
|
2713
|
+
# 被系统反复召回 = 真的在用,这是能力最硬的证据(不靠自夸)。
|
|
2658
2714
|
try:
|
|
2659
2715
|
import memory as _mem
|
|
2660
2716
|
strengths_cand: list = []
|
|
2661
2717
|
for r in _mem.load_all():
|
|
2662
|
-
if not isinstance(r, dict)
|
|
2718
|
+
if not isinstance(r, dict):
|
|
2663
2719
|
continue
|
|
2664
|
-
if
|
|
2720
|
+
if r.get("kind") not in ("insight", "fact"):
|
|
2665
2721
|
continue
|
|
2666
|
-
if
|
|
2722
|
+
if _num(r.get("importance"), 0) < 0.75:
|
|
2667
2723
|
continue
|
|
2668
|
-
|
|
2724
|
+
_acc = int(_num(r.get("access_count"), 0))
|
|
2725
|
+
if _acc < 3:
|
|
2669
2726
|
continue
|
|
2670
|
-
|
|
2671
|
-
if
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2727
|
+
t0 = str(r.get("text") or r.get("summary") or "").strip()
|
|
2728
|
+
if not t0:
|
|
2729
|
+
continue
|
|
2730
|
+
strengths_cand.append((_num(r.get("created"), 0),
|
|
2731
|
+
f"(被召回 {_acc} 次)" + t0[:130]))
|
|
2732
|
+
strengths_cand.sort(key=lambda e: e[0], reverse=True)
|
|
2733
|
+
existing_s = set(sm["strengths"])
|
|
2734
|
+
for _ts, txt in strengths_cand[:8]:
|
|
2735
|
+
if txt in existing_s:
|
|
2736
|
+
continue
|
|
2737
|
+
sm["strengths"].append(txt) # 纯字符串:_ensure_self_model 只保留 str
|
|
2738
|
+
added["strengths"].append(txt)
|
|
2739
|
+
if len(sm["strengths"]) > _SELF_MODEL_MAX:
|
|
2740
|
+
del sm["strengths"][:-_SELF_MODEL_MAX]
|
|
2741
|
+
except Exception as e:
|
|
2742
|
+
log_event("persona", f"self_model_autosink 反复使用路失败:{e}", level="warn")
|
|
2743
|
+
|
|
2744
|
+
# —— 路 5:mistake 类记忆 → limitations 补充源(实装版)——
|
|
2745
|
+
# 原路1只认 correction=True,实测全库仅 1 条 → 短板几乎不积累。
|
|
2746
|
+
# mistake 类(13 条)是"我犯过的错"的一等公民,本该进短板桶。
|
|
2747
|
+
try:
|
|
2748
|
+
import memory as _mem
|
|
2749
|
+
mist = []
|
|
2750
|
+
for r in _mem.load_all():
|
|
2751
|
+
if not isinstance(r, dict) or r.get("kind") != "mistake":
|
|
2752
|
+
continue
|
|
2753
|
+
t0 = str(r.get("text") or "").strip()
|
|
2754
|
+
if t0:
|
|
2755
|
+
mist.append((_num(r.get("created"), 0), t0))
|
|
2756
|
+
mist.sort(key=lambda x: x[0], reverse=True)
|
|
2757
|
+
existing_l = set(sm["limitations"])
|
|
2758
|
+
for _ts, t0 in mist[:8]:
|
|
2759
|
+
if t0 in existing_l:
|
|
2677
2760
|
continue
|
|
2678
|
-
sm["
|
|
2679
|
-
added["
|
|
2680
|
-
|
|
2761
|
+
sm["limitations"].append(t0)
|
|
2762
|
+
added["limitations"].append(t0)
|
|
2763
|
+
if len(sm["limitations"]) > _SELF_MODEL_MAX:
|
|
2764
|
+
del sm["limitations"][:-_SELF_MODEL_MAX]
|
|
2681
2765
|
except Exception as e:
|
|
2682
|
-
log_event("persona", f"self_model_autosink
|
|
2766
|
+
log_event("persona", f"self_model_autosink mistake 路失败:{e}", level="warn")
|
|
2683
2767
|
|
|
2684
2768
|
save_persona(p)
|
|
2685
2769
|
audit_log("ai", "self_model_autosink", "self_model",
|
package/scripts/emotion.py
CHANGED
|
@@ -1086,6 +1086,19 @@ def emotion_arc(days: int = 7) -> dict:
|
|
|
1086
1086
|
# 情绪太激动时杏仁核会压制前额叶——理智值会临时下降,但永远压不掉一半以上。
|
|
1087
1087
|
# * 重要的事(钱/关系/承诺/健康)在任何情绪下都留给用户决定,情绪不替用户拍板。
|
|
1088
1088
|
|
|
1089
|
+
# NAMESPACE-FIX(v5.54):emotion.py 里的 load_persona / mind_state / feel 等名字
|
|
1090
|
+
# 原依赖 brain.py 的星号合并命名空间——单独 import emotion 就 NameError
|
|
1091
|
+
# (实测:persona.daily_drift 调 _emo.feel 时崩 "load_persona is not defined")。
|
|
1092
|
+
# 这里补一个安全的本地绑定:优先用已有合并名,缺失则直接取 persona 模块的实现。
|
|
1093
|
+
try:
|
|
1094
|
+
load_persona # noqa: B018 已由 brain 合并命名空间提供
|
|
1095
|
+
except NameError: # pragma: no cover - 仅在单独 import 时触发
|
|
1096
|
+
try:
|
|
1097
|
+
from persona import load_persona, save_persona # type: ignore
|
|
1098
|
+
except Exception:
|
|
1099
|
+
pass
|
|
1100
|
+
|
|
1101
|
+
|
|
1089
1102
|
def emotion_cfg() -> dict:
|
|
1090
1103
|
"""情感设置(用户随时可改):共情程度 / 抑制的情绪 / 备注。存在人格档案里。"""
|
|
1091
1104
|
p = load_persona()
|
package/scripts/persona.py
CHANGED
|
@@ -270,11 +270,17 @@ def compile_persona() -> dict:
|
|
|
270
270
|
_disk_now = _slurp_json(HOME / "persona.json") if (HOME / "persona.json").exists() else None
|
|
271
271
|
_disk_named = bool((( _disk_now or {}).get("identity") or {}).get("名字"))
|
|
272
272
|
_incoming_named = bool(((p.get("identity") or {}).get("名字") or "").strip())
|
|
273
|
-
|
|
273
|
+
# PERSONA-GUARD v3:只在【会丢数据】时拦(盘上已有实质内容 + 产物为空),
|
|
274
|
+
# 首次创建(无文件/盘上空)必须放行——v2 的无条件拒绝让初始化返回 None,
|
|
275
|
+
# 连锁崩掉 overview 与全部单测(12-04 03:22 实测)。
|
|
276
|
+
_disk_sub = (bool(str((_disk_now.get("identity") or {}).get("名字") or "").strip())
|
|
277
|
+
or bool(_disk_now.get("traits") or {})
|
|
278
|
+
or bool(_disk_now.get("history") or [])) if isinstance(_disk_now, dict) else False
|
|
279
|
+
if _disk_sub and not _incoming_named and not (p.get("traits") or {}):
|
|
274
280
|
log_event("persona",
|
|
275
|
-
"compile_persona
|
|
281
|
+
"compile_persona 拒绝覆盖:盘上已有实质人格而被空态重建覆盖——已拦下。",
|
|
276
282
|
level="error")
|
|
277
|
-
return
|
|
283
|
+
return _disk_now if isinstance(_disk_now, dict) else default_persona()
|
|
278
284
|
atomic_json(HOME / "persona.json", p)
|
|
279
285
|
# SPEED-1 缓存同步失效:compile_persona 直写绕过了 save_persona 的失效点
|
|
280
286
|
global _lp_cache, _lp_cache_mtime, _lp_cache_time
|
|
@@ -327,6 +333,24 @@ def load_persona() -> dict:
|
|
|
327
333
|
else:
|
|
328
334
|
# 只读且档案缺失:给一份内存默认值,不影响读取已有记忆
|
|
329
335
|
p = compile_persona() if not READONLY else default_persona()
|
|
336
|
+
# PERSONA-AUTOHEAL(v5.54):读到空态(无名字无特质)时自动从 lastgood 回滚。
|
|
337
|
+
# 这是最后一道网——即使某条未预见的路径把盘写空,人格也不会真的丢。
|
|
338
|
+
try:
|
|
339
|
+
_empty_now = (not str(((p.get("identity") or {}).get("名字") or "")).strip()
|
|
340
|
+
and not (p.get("traits") or {}))
|
|
341
|
+
_lg = HOME / "persona.lastgood.json"
|
|
342
|
+
if _empty_now and _lg.exists():
|
|
343
|
+
_good = _slurp_json(_lg)
|
|
344
|
+
if isinstance(_good, dict) and str(((_good.get("identity") or {}).get("名字") or "")).strip():
|
|
345
|
+
if isinstance(p.get("state"), dict) and isinstance(_good.get("state"), dict):
|
|
346
|
+
_merged = dict(_good["state"])
|
|
347
|
+
_merged.update({kk: vv for kk, vv in p["state"].items() if vv is not None})
|
|
348
|
+
_good["state"] = _merged
|
|
349
|
+
p = _good
|
|
350
|
+
log_event("persona", "检测到人格空态,已自动从 persona.lastgood.json 回滚", level="warn")
|
|
351
|
+
except Exception:
|
|
352
|
+
pass
|
|
353
|
+
|
|
330
354
|
changed = False
|
|
331
355
|
if "onboarding" not in p:
|
|
332
356
|
p["onboarding"] = default_onboarding()
|
|
@@ -394,6 +418,13 @@ def save_persona(p: dict) -> None:
|
|
|
394
418
|
pass # 守卫自身绝不阻塞正常保存
|
|
395
419
|
with _locked(HOME / "persona.json"):
|
|
396
420
|
atomic_json(HOME / "persona.json", p)
|
|
421
|
+
# PERSONA-AUTOHEAL(v5.54):每次成功保存"有名字"的人格,同步留一份 lastgood。
|
|
422
|
+
# 这样无论哪条路径把人格写空,load_persona 都能自动回滚——不再依赖人工恢复。
|
|
423
|
+
try:
|
|
424
|
+
if str(((p.get("identity") or {}).get("名字") or "")).strip():
|
|
425
|
+
atomic_json(HOME / "persona.lastgood.json", p)
|
|
426
|
+
except Exception:
|
|
427
|
+
pass
|
|
397
428
|
|
|
398
429
|
|
|
399
430
|
def _snapshot_path() -> Path:
|
|
@@ -1469,6 +1500,26 @@ def daily_drift(days: int = 1) -> dict:
|
|
|
1469
1500
|
applied = True
|
|
1470
1501
|
audit_log("ai", "daily_drift", "state.mood_score",
|
|
1471
1502
|
f"{int(cur)}→{new}(近{days}天 net={net})")
|
|
1503
|
+
# —— 心情快照(MOOD-SNAPSHOT v5.53)——
|
|
1504
|
+
# 历史问题:emotion_timeline 只有 1 条——因为 auto_appraise 只在 extract(封存对话)
|
|
1505
|
+
# 时调用,日常 remember/capture 不经过它。补一条**每��实测**的 EMA 快照进
|
|
1506
|
+
# emotions.jsonl(genesis=False,标 source=daily-snapshot):
|
|
1507
|
+
# 不是编造情绪,是把当天真实测得的心情记进流水,让时间线有连续曲线。
|
|
1508
|
+
try:
|
|
1509
|
+
import emotion as _emo
|
|
1510
|
+
_m = _emo.mood_now()
|
|
1511
|
+
if _m.get("active") or _m.get("label") not in (None, "", "平静"):
|
|
1512
|
+
_mood_hist = p.setdefault("state", {}).setdefault("_mood_snap_ts", 0)
|
|
1513
|
+
if now - _num(_mood_hist, 0) >= 20 * 3600: # 20h 内只记一次
|
|
1514
|
+
_emo.feel(_m.get("label") or "平静",
|
|
1515
|
+
intensity=max(0.05, min(0.6, _num(_m.get("intensity"), 0.1))),
|
|
1516
|
+
why=f"每日心情快照:{_m.get('label')}(强度 {_num(_m.get('intensity'), 0):.0%})",
|
|
1517
|
+
about="每日快照", genesis=False)
|
|
1518
|
+
p["state"]["_mood_snap_ts"] = now
|
|
1519
|
+
applied = True
|
|
1520
|
+
except Exception as _e:
|
|
1521
|
+
log_event("persona", f"心情快照写入失败(不影响其他):{_e}", level="warn")
|
|
1522
|
+
|
|
1472
1523
|
# —— 内驱演化(DRIVE-EVOLVE v5.52)——
|
|
1473
1524
|
# 历史问题:mind_tune 只有 CLI 手动路径,从初识后好奇/理智永远不变。
|
|
1474
1525
|
# 这里用【真实信号】驱动(都可追溯到记忆库),每天最多 ±2,带 history 留痕:
|
|
@@ -2625,61 +2676,94 @@ def self_model_autosink() -> dict:
|
|
|
2625
2676
|
sm["autobiography"].sort(key=lambda e: _num(e.get("ts"), 0), reverse=True)
|
|
2626
2677
|
del sm["autobiography"][_SELF_MODEL_MAX:]
|
|
2627
2678
|
|
|
2628
|
-
# —— 路 3
|
|
2629
|
-
# confidence 0.4~0.6
|
|
2679
|
+
# —— 路 3:被取代的旧结论 → uncertainties(IDEA-10 实装版)——
|
|
2680
|
+
# 原实现要求 insight 带 confidence 0.4~0.6 字段,但实测 23 条 insight 里
|
|
2681
|
+
# **0 条有 confidence**(该字段只有教训库用)→ 死代码。
|
|
2682
|
+
# 改用真实存在的信号:superseded_by(被新结论取代的旧记忆)——
|
|
2683
|
+
# "我当时是这么想的,后来发现不成立"正是最诚实的认知修正痕迹。
|
|
2630
2684
|
try:
|
|
2631
2685
|
import memory as _mem
|
|
2632
2686
|
uncer: list = []
|
|
2633
2687
|
for r in _mem.load_all():
|
|
2634
|
-
if not isinstance(r, dict) or r.get("
|
|
2635
|
-
continue
|
|
2636
|
-
conf = _num(r.get("confidence"), -1)
|
|
2637
|
-
if not (0.4 <= conf < 0.6):
|
|
2688
|
+
if not isinstance(r, dict) or not r.get("superseded_by"):
|
|
2638
2689
|
continue
|
|
2639
2690
|
ts_r = _num(r.get("ts"), 0) or _num(r.get("created"), 0)
|
|
2640
|
-
if now - ts_r >
|
|
2691
|
+
if now - ts_r > 90 * 86400: # 三个月前的旧账不再翻
|
|
2641
2692
|
continue
|
|
2642
|
-
|
|
2643
|
-
if
|
|
2644
|
-
uncer.append({"ts": ts_r, "text": t[:160]})
|
|
2645
|
-
uncer.sort(key=lambda e: e["ts"], reverse=True)
|
|
2646
|
-
existing_u = {e.get("text") for e in sm["uncertainties"]}
|
|
2647
|
-
for e in uncer[:8]:
|
|
2648
|
-
if e["text"] in existing_u:
|
|
2693
|
+
t0 = str(r.get("text") or r.get("summary") or "").strip()
|
|
2694
|
+
if not t0:
|
|
2649
2695
|
continue
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2696
|
+
uncer.append((ts_r, "曾经以为:" + t0[:140]))
|
|
2697
|
+
uncer.sort(key=lambda e: e[0], reverse=True)
|
|
2698
|
+
existing_u = set(sm["uncertainties"])
|
|
2699
|
+
for _ts, txt in uncer[:8]:
|
|
2700
|
+
if txt in existing_u:
|
|
2701
|
+
continue
|
|
2702
|
+
sm["uncertainties"].append(txt) # 纯字符串:_ensure_self_model 只保留 str
|
|
2703
|
+
added["uncertainties"].append(txt)
|
|
2704
|
+
if len(sm["uncertainties"]) > _SELF_MODEL_MAX:
|
|
2705
|
+
del sm["uncertainties"][:-_SELF_MODEL_MAX]
|
|
2653
2706
|
except Exception as e:
|
|
2654
|
-
log_event("persona", f"self_model_autosink
|
|
2707
|
+
log_event("persona", f"self_model_autosink 被取代结论路失败:{e}", level="warn")
|
|
2655
2708
|
|
|
2656
|
-
# —— 路 4
|
|
2657
|
-
#
|
|
2709
|
+
# —— 路 4:反复被召回使用的高价值结论 → strengths(IDEA-10 实装版)——
|
|
2710
|
+
# 原实现要求 importance>=0.8 + access_count>=3 + 带 emotion 字段,
|
|
2711
|
+
# 但实测高重要度记忆 emo 几乎全为 None → 死代码。
|
|
2712
|
+
# 改用真实信号:importance>=0.75 且 access_count>=3——
|
|
2713
|
+
# 被系统反复召回 = 真的在用,这是能力最硬的证据(不靠自夸)。
|
|
2658
2714
|
try:
|
|
2659
2715
|
import memory as _mem
|
|
2660
2716
|
strengths_cand: list = []
|
|
2661
2717
|
for r in _mem.load_all():
|
|
2662
|
-
if not isinstance(r, dict)
|
|
2718
|
+
if not isinstance(r, dict):
|
|
2663
2719
|
continue
|
|
2664
|
-
if
|
|
2720
|
+
if r.get("kind") not in ("insight", "fact"):
|
|
2665
2721
|
continue
|
|
2666
|
-
if
|
|
2722
|
+
if _num(r.get("importance"), 0) < 0.75:
|
|
2667
2723
|
continue
|
|
2668
|
-
|
|
2724
|
+
_acc = int(_num(r.get("access_count"), 0))
|
|
2725
|
+
if _acc < 3:
|
|
2669
2726
|
continue
|
|
2670
|
-
|
|
2671
|
-
if
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2727
|
+
t0 = str(r.get("text") or r.get("summary") or "").strip()
|
|
2728
|
+
if not t0:
|
|
2729
|
+
continue
|
|
2730
|
+
strengths_cand.append((_num(r.get("created"), 0),
|
|
2731
|
+
f"(被召回 {_acc} 次)" + t0[:130]))
|
|
2732
|
+
strengths_cand.sort(key=lambda e: e[0], reverse=True)
|
|
2733
|
+
existing_s = set(sm["strengths"])
|
|
2734
|
+
for _ts, txt in strengths_cand[:8]:
|
|
2735
|
+
if txt in existing_s:
|
|
2736
|
+
continue
|
|
2737
|
+
sm["strengths"].append(txt) # 纯字符串:_ensure_self_model 只保留 str
|
|
2738
|
+
added["strengths"].append(txt)
|
|
2739
|
+
if len(sm["strengths"]) > _SELF_MODEL_MAX:
|
|
2740
|
+
del sm["strengths"][:-_SELF_MODEL_MAX]
|
|
2741
|
+
except Exception as e:
|
|
2742
|
+
log_event("persona", f"self_model_autosink 反复使用路失败:{e}", level="warn")
|
|
2743
|
+
|
|
2744
|
+
# —— 路 5:mistake 类记忆 → limitations 补充源(实装版)——
|
|
2745
|
+
# 原路1只认 correction=True,实测全库仅 1 条 → 短板几乎不积累。
|
|
2746
|
+
# mistake 类(13 条)是"我犯过的错"的一等公民,本该进短板桶。
|
|
2747
|
+
try:
|
|
2748
|
+
import memory as _mem
|
|
2749
|
+
mist = []
|
|
2750
|
+
for r in _mem.load_all():
|
|
2751
|
+
if not isinstance(r, dict) or r.get("kind") != "mistake":
|
|
2752
|
+
continue
|
|
2753
|
+
t0 = str(r.get("text") or "").strip()
|
|
2754
|
+
if t0:
|
|
2755
|
+
mist.append((_num(r.get("created"), 0), t0))
|
|
2756
|
+
mist.sort(key=lambda x: x[0], reverse=True)
|
|
2757
|
+
existing_l = set(sm["limitations"])
|
|
2758
|
+
for _ts, t0 in mist[:8]:
|
|
2759
|
+
if t0 in existing_l:
|
|
2677
2760
|
continue
|
|
2678
|
-
sm["
|
|
2679
|
-
added["
|
|
2680
|
-
|
|
2761
|
+
sm["limitations"].append(t0)
|
|
2762
|
+
added["limitations"].append(t0)
|
|
2763
|
+
if len(sm["limitations"]) > _SELF_MODEL_MAX:
|
|
2764
|
+
del sm["limitations"][:-_SELF_MODEL_MAX]
|
|
2681
2765
|
except Exception as e:
|
|
2682
|
-
log_event("persona", f"self_model_autosink
|
|
2766
|
+
log_event("persona", f"self_model_autosink mistake 路失败:{e}", level="warn")
|
|
2683
2767
|
|
|
2684
2768
|
save_persona(p)
|
|
2685
2769
|
audit_log("ai", "self_model_autosink", "self_model",
|