lingshu-skill 5.19.0 → 5.20.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/README.md +24 -1
- package/SKILL.md +2 -1
- package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +4 -0
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +7 -7
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +38 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +24 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +2 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +68 -14
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +147 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +12 -4
- package/scripts/cli.py +68 -14
- package/scripts/growth.py +147 -1
- package/scripts/memory.py +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v5.20(2026-11-26)
|
|
4
|
+
|
|
5
|
+
> 主题:**情绪驱动的记忆权重(P2-3)**——让"让我难受的事"更重、更容易被想起。
|
|
6
|
+
> 依据 `docs/借鉴待办-DSH插件生态.md` P2-3(借鉴「记仇」)。
|
|
7
|
+
|
|
8
|
+
### 新:负面情绪给记忆加权
|
|
9
|
+
|
|
10
|
+
| 环节 | 机制 |
|
|
11
|
+
|---|---|
|
|
12
|
+
| 触发 | 情绪 `valence ≤ -0.3` 且 `intensity ≥ 0.1`(够负面、且有分量) |
|
|
13
|
+
| 加权 | 每次 `importance + 0.06`,**累计封顶 0.30**(不会被反复牵动抬到 1.0) |
|
|
14
|
+
| 召回 | `score × (1 + 影响均值 × 0.3)`——老记忆没有该字段,加成 0,**行为完全不变** |
|
|
15
|
+
| 自动化 | `extract` 封存对话后自动判情绪;判出负面就给**刚封存那批**记忆加权 |
|
|
16
|
+
|
|
17
|
+
**为什么加在 importance 上而不是新开一个打分维度**:importance 已在五元打分里占 0.35,
|
|
18
|
+
往那里加权语义就是"这条对我更重要",干净;再加一维会让评分继续膨胀、更难解释。
|
|
19
|
+
|
|
20
|
+
**口径都写死在代码里并可核对**(`EMO_TOUCH_STEP` / `EMO_TOUCH_MAX` /
|
|
21
|
+
`EMO_TOUCH_NEG_MAX_VALENCE` / `EMO_TOUCH_MIN_INTENSITY` / `EMO_RECALL_BOOST`)。
|
|
22
|
+
配置键 `emotion_memory_weight`(默认开),设置页「情绪与人格」组可关。
|
|
23
|
+
|
|
24
|
+
### 做这项时踩的四个坑(都实证过,都记在这儿)
|
|
25
|
+
|
|
26
|
+
1. **`auto_appraise` 返回的是 dict,不是事件列表**:契约是
|
|
27
|
+
`{emotion, intensity, polarity, hits}`(不写时 `None`),**不含 valence**。
|
|
28
|
+
我一开始当列表用、又去读 `valence`,结果永远不触发。
|
|
29
|
+
顺带发现门槛是 **≥80 字、≥2 个命中词、正负混说不猜**——27 字的测试文本直接被跳过。
|
|
30
|
+
2. **`capture()` 的 `saved` 是"完整记录字典"列表,不是 id 列表**。
|
|
31
|
+
把整条记录当 id 传进去,`str()` 成一大串 → `找不到记忆 {'id': ...}`。
|
|
32
|
+
现在 `touch_by_emotion` 兼容 dict(自动取 id),调用方也显式取 `s["id"]`。
|
|
33
|
+
3. **量纲混用**:我把情绪强度(`abs(v)×i` = 0.9)当成"已用配额"去和上限 0.30 比,
|
|
34
|
+
于是**第一次就判超限**(实际只加了 0.06)。现在拆成两个字段:
|
|
35
|
+
`_touched_by_emotion`(强度列表,供召回加成)与 `_emo_touch_total`(配额,供封顶判断)。
|
|
36
|
+
4. `emotion_events()` 不是可靠入口(要等落盘、且受 genesis 过滤),直接吃返回值即可。
|
|
37
|
+
|
|
38
|
+
验证:`tests/test_p32_emotion_weight.py` **8/8**(负面上调/正与弱不动作/**累计封顶**/
|
|
39
|
+
兼容 dict/加成数学/**召回排序**/extract 端到端/配置与设置页);全套 **88/88**。
|
|
40
|
+
|
|
3
41
|
## v5.19(2026-11-26)
|
|
4
42
|
|
|
5
43
|
> 主题:**全量代码安全审计**——56 个文件 / 35855 行,产出 101 条发现
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
> 当前版本 **v5.
|
|
5
|
+
> 当前版本 **v5.20**(变更见 [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
|
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
- [错卦:召回区分否定](#错卦召回区分否定)
|
|
29
29
|
- [索引法记忆:正文不进上下文](#索引法记忆正文不进上下文)
|
|
30
30
|
- [情绪惯性:不会一句话就换心情](#情绪惯性不会一句话就换心情)
|
|
31
|
+
- [情绪驱动记忆权重:难受过的事更重](#情绪驱动记忆权重难受过的事更重)
|
|
31
32
|
- [成长阶段:它长到哪一步了](#成长阶段它长到哪一步了)
|
|
32
33
|
- [主动搭话:它会自己开口,但很少](#主动搭话它会自己开口但很少)
|
|
33
34
|
- [Git 分支感知:切了分支别拿旧分支的记忆](#git-分支感知切了分支别拿旧分支的记忆)
|
|
@@ -416,6 +417,28 @@ python scripts/brain.py memory show 7f3ca9ac # 短 id 直接取整条记忆
|
|
|
416
417
|
|
|
417
418
|
设置页「情绪与人格」组可逐项开关;`emotion_inertia_enabled=false` 一键回到原生行为。
|
|
418
419
|
|
|
420
|
+
## 情绪驱动记忆权重:难受过的事更重
|
|
421
|
+
|
|
422
|
+
不是所有记忆生而平等。让用户委屈、生气、害怕的事,本来就该记得更牢
|
|
423
|
+
(情绪记忆的巩固强度高于中性记忆)——这条把它做成了可核对的机制:
|
|
424
|
+
|
|
425
|
+
| 环节 | 机制 |
|
|
426
|
+
|---|---|
|
|
427
|
+
| 触发 | 情绪 `valence ≤ -0.3` 且 `intensity ≥ 0.1` |
|
|
428
|
+
| 加权 | 每次 `importance + 0.06`,**累计封顶 0.30** |
|
|
429
|
+
| 召回 | `score × (1 + 影响均值 × 0.3)` |
|
|
430
|
+
| 自动化 | `extract` 封存对话后自动判情绪,判出负面就给刚封存那批记忆加权 |
|
|
431
|
+
|
|
432
|
+
```bash
|
|
433
|
+
# 手动看效果
|
|
434
|
+
python scripts/brain.py memory show <短id> # 看 importance 与 _touched_by_emotion
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**为什么加在 importance 上**:它已在五元打分里占 0.35,往那里加权语义就是"这条对我更重要",
|
|
438
|
+
比新开一个维度干净。老记忆没有该字段 → 加成 0,**行为完全不变**。
|
|
439
|
+
|
|
440
|
+
配置 `emotion_memory_weight`(默认开),设置页「情绪与人格」组可关。
|
|
441
|
+
|
|
419
442
|
## 成长阶段:它长到哪一步了
|
|
420
443
|
|
|
421
444
|
把 doctor / failures / 自审的数据包成一句人话:
|
package/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: lingshu
|
|
3
3
|
title: 灵枢
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.20
|
|
5
5
|
description: 类脑持久记忆、人格与成长系统——跨会话记住事情、长出自己的人格、上下文将满时做梦式整理记忆。用户提到记忆/记住/上次/人格/设定/性格/知识库/笔记/日志/成长/自我进化/工作记忆,或新会话开始需要恢复关系与上下文时使用。纯本地零依赖。
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -380,6 +380,7 @@ python scripts/bench.py [--n 1000|--quick] # 性能基准:隔离临
|
|
|
380
380
|
| 想立刻关 | 面板「设置」页 → **「退出服务」** |
|
|
381
381
|
| 连点两次 | 安全:启动器先探测,**已在跑就只把浏览器叫回来**,不会起第二个 |
|
|
382
382
|
| **桌面快捷方式丢了** | `python scripts/brain.py shortcut --ensure`(幂等:缺了就重建,已有就不动) |
|
|
383
|
+
| 记一条"让我难受的事" | 正常 `remember` 即可;判出负面情绪后 importance 会自动 +0.06(封顶 0.30),召回时也更靠前 |
|
|
383
384
|
| 看情绪/心情 | `python scripts/brain.py emotion now`(标签受惯性保护,`raw_label` 是即时感受) |
|
|
384
385
|
| 看它长到哪一步 | `python scripts/brain.py stage`(蛋/幼体/少年/成年/传奇 + 下一步差什么) |
|
|
385
386
|
| 取一条记忆的正文 | `python scripts/brain.py memory show <短id>`(注入里的 8 位短号直接用,也认完整 id 前缀) |
|
|
@@ -675,6 +675,10 @@ startup 注入的记忆块与 cron 的瞬态提醒**同名**,于是 cron 的 p
|
|
|
675
675
|
- **未修(待排期)**:51 medium + 37 low。优先项:`panel_cloud` 远端 index 解析失败会重建空清单**覆盖整个商店目录**;拓展 zip **不校验 sha256**(面板包却校验);`purge` 归档分支**先删后写台账**;`persona_restore` 不校验结构**可能写空人格**;备份脱敏只清 `panel.cloud` token(**顶层 `gitee_token` 明文进备份**);`panels.delete` 用 `rmtree` 违反只移不删;`safety_net.verify` 的 `allow_shrink` 与行数比对**从未实现**;`guarded_write` 回滚后把 ok 置 True(调用方无法区分成功/失败);`session_import` 工作区隔离靠子串匹配(`--workspace alpha` 会带入 `alpha-secret`)。
|
|
676
676
|
- 回归 `tests/test_p31_audit_fixes.py` 7/7;全套 87/87。另为 `test_p14` 加了 0.3s 沉降窗口(异步副作用线程的 patch 若晚于删除会复活记录),10/10 稳定。
|
|
677
677
|
|
|
678
|
+
113. **【已做 v5.20】P2-3 情绪驱动的记忆权重("记仇")**:`memory.touch_by_emotion()` + `_emo_boost_of()`;触发 `valence ≤ -0.3 且 intensity ≥ 0.1`,每次 importance +0.06、累计封顶 **0.30**;recall `score × (1 + 影响均值 × 0.3)`;`extract` 封存后自动判情绪并对刚封存那批加权。配置 `emotion_memory_weight`(默认开)+ 设置页开关。口径全部写成模块常量可核对。
|
|
679
|
+
- **四个坑(均实证)**:① `auto_appraise` 返回 **dict**(`{emotion,intensity,polarity,hits}`,不含 valence),且门槛是 **≥80 字 / ≥2 命中词 / 正负混说不猜**——27 字文本直接被跳过,我一开始当列表用且读 valence,永远不触发;② `capture()` 的 `saved` 是**完整记录字典**列表而非 id 列表,把 dict 当 id 传 → `找不到记忆 {'id':...}`;③ **量纲混用**:拿情绪强度(0.9)当"已用配额"与上限 0.30 比 → 第一次就判超限(实际只加 0.06),现拆成 `_touched_by_emotion`(强度,供召回加成)与 `_emo_touch_total`(配额,供封顶);④ `emotion_events()` 不是可靠入口(要等落盘、受 genesis 过滤),直接吃返回值。
|
|
680
|
+
- 回归 `tests/test_p32_emotion_weight.py` 8/8;全套 88/88。
|
|
681
|
+
|
|
678
682
|
## 三、已知问题与风险
|
|
679
683
|
|
|
680
684
|
| # | 现象 | 影响 | 处置 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingshu-skill",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.20.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": "
|
|
4
|
+
"engine/CHANGELOG.md": "87b95a22677d4f8768951e6c3dd0fe3a8f13825eda7967613126c2384cce0c3e",
|
|
5
|
+
"engine/README.md": "c609cac924b264aa115fff0679a0824bd4f05fc4a1259499226a230c3fd9e6ad",
|
|
6
6
|
"engine/SKILL-lite.md": "423f97d64042233a5a1678384fba307a91a62ab0ed2e8d01f89e44a926d6e83d",
|
|
7
7
|
"engine/SKILL-tiny.md": "aff71d79e6384c14e8895405bbf178d2b57f679540b12a6afaeba6e39b15116b",
|
|
8
|
-
"engine/SKILL.md": "
|
|
8
|
+
"engine/SKILL.md": "4bcc6dd8d3ddf6dd1e0c671b8a0e52150f920c72553ad1b4a620ac97d8be5979",
|
|
9
9
|
"engine/assets/panel.html": "74b763c4fae3d3be607c85e9ae6b2ef8ce5c13c4294937adcc58d251f78a218d",
|
|
10
10
|
"engine/docs/commands.md": "454b83814c74d8677c1a02754e4da24c73c1abebaa92a1cdcb0aa0b2e1472432",
|
|
11
11
|
"engine/docs/mechanics.md": "e8a6602a434ed5b78cac64a98884f65a6888eb48daa7a1c0be1f6c3984041b34",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"engine/scripts/check_pressure_sync.py": "46d53934f17c7b740d0ec9fdbef9d2653850f6e01e883eedd70ff9a1527e869a",
|
|
20
20
|
"engine/scripts/check_tag.py": "6f0b8209dc2deebb1f9ec90d429e1fad60c040a2ec014a6406d9d3498faafd7f",
|
|
21
21
|
"engine/scripts/checkpoint.py": "3a9292121042692dc872a865b6ee1c1e5f14c054791887e0791f19ccdb9638fb",
|
|
22
|
-
"engine/scripts/cli.py": "
|
|
22
|
+
"engine/scripts/cli.py": "a14d05bbde479db432395852b665c1d06e4c6c052c8b57423ee790dd24ab49e3",
|
|
23
23
|
"engine/scripts/context_ab.py": "3d383f1fc16d328612825bbf731866fa427da0746490d027a0ddb719d210f1cb",
|
|
24
|
-
"engine/scripts/core.py": "
|
|
24
|
+
"engine/scripts/core.py": "7bfde5ece57e7da50599f3257959bf64eb323f2c5c8f0993bffea6677b81ee55",
|
|
25
25
|
"engine/scripts/desktop_shortcut.py": "77ea248bfaaf28e1e4299979d0c0d8c80a055642dde9a40f5e297b2008474091",
|
|
26
26
|
"engine/scripts/dream.py": "c1ba3de2958fb045db7b6962a6dd0fcf70f225bfb4d372dd9c3e8584e4f759ce",
|
|
27
27
|
"engine/scripts/emotion.py": "b56f2516a47ed5adecfe913e7e24957e5f4975fc8379f4097d5fa73dbd5c97d0",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"engine/scripts/mem_lesson.py": "e1520786315f3e41c829909c739e5af3eee89397da7db5026d106710b2b3c118",
|
|
38
38
|
"engine/scripts/mem_score.py": "95dcecba5f4db7c0c16ebc415434e1cb58cc7dd8b8213360b4df36e2a90faf6e",
|
|
39
39
|
"engine/scripts/mem_topic.py": "c22f75c128cdd3b26ff845f1a71608401bc0dc8955f9f0e1988d7f0cd663d0d5",
|
|
40
|
-
"engine/scripts/memory.py": "
|
|
40
|
+
"engine/scripts/memory.py": "96be42c9c87231766086f8f8eeb05642192e31e6512b9cfe95806fd56c78b716",
|
|
41
41
|
"engine/scripts/npm_prepack.py": "d62c491a6f9edfcab2dd465a995e72df879a61b4da26ae0fe76121c8adc77e02",
|
|
42
42
|
"engine/scripts/panel_build.py": "6394c1d74d203093e43b2106d7acca6e0ca9db61ca1cd6cd3a1616053653414b",
|
|
43
43
|
"engine/scripts/panel_cloud.py": "2059ee87ea08acdf84698ce40ebb4eaa4a8497ddc67f2fe01ef112bb0eb6b24f",
|
|
44
44
|
"engine/scripts/panel_data.py": "5788aaee9b4e56e73587c4d0474687cecaa40dd7e507f02c27dd07aa208ba237",
|
|
45
45
|
"engine/scripts/panel_launcher.py": "d54dc3ab7b4a7301651cb797e4003f6b228c45f6842bc70deac91569289f6e83",
|
|
46
46
|
"engine/scripts/panel_server.py": "fec93d9a60d263ac726f6393232cd681d135d98f0faaeb5f8743fe22b3d6d914",
|
|
47
|
-
"engine/scripts/panel_settings.py": "
|
|
47
|
+
"engine/scripts/panel_settings.py": "49714ad058b1fe0cdd495a2e7eeadc3b4554346c92150b1381cdc39f44012b6e",
|
|
48
48
|
"engine/scripts/panel_update.py": "6ff1a0687c05e3ef4ae846058abea4dacf985a3fe6adcdbb4eef1b38e27139b5",
|
|
49
49
|
"engine/scripts/panels.py": "87dfce47693340af7c9bc6010a593256331e32c2e8504a0ac0745cf2ef992fd6",
|
|
50
50
|
"engine/scripts/persona.py": "fb748d2fb7b176d9dd0d7394de69ba4560da7f4205f62256477d3a69dcbdf0f5",
|
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v5.20(2026-11-26)
|
|
4
|
+
|
|
5
|
+
> 主题:**情绪驱动的记忆权重(P2-3)**——让"让我难受的事"更重、更容易被想起。
|
|
6
|
+
> 依据 `docs/借鉴待办-DSH插件生态.md` P2-3(借鉴「记仇」)。
|
|
7
|
+
|
|
8
|
+
### 新:负面情绪给记忆加权
|
|
9
|
+
|
|
10
|
+
| 环节 | 机制 |
|
|
11
|
+
|---|---|
|
|
12
|
+
| 触发 | 情绪 `valence ≤ -0.3` 且 `intensity ≥ 0.1`(够负面、且有分量) |
|
|
13
|
+
| 加权 | 每次 `importance + 0.06`,**累计封顶 0.30**(不会被反复牵动抬到 1.0) |
|
|
14
|
+
| 召回 | `score × (1 + 影响均值 × 0.3)`——老记忆没有该字段,加成 0,**行为完全不变** |
|
|
15
|
+
| 自动化 | `extract` 封存对话后自动判情绪;判出负面就给**刚封存那批**记忆加权 |
|
|
16
|
+
|
|
17
|
+
**为什么加在 importance 上而不是新开一个打分维度**:importance 已在五元打分里占 0.35,
|
|
18
|
+
往那里加权语义就是"这条对我更重要",干净;再加一维会让评分继续膨胀、更难解释。
|
|
19
|
+
|
|
20
|
+
**口径都写死在代码里并可核对**(`EMO_TOUCH_STEP` / `EMO_TOUCH_MAX` /
|
|
21
|
+
`EMO_TOUCH_NEG_MAX_VALENCE` / `EMO_TOUCH_MIN_INTENSITY` / `EMO_RECALL_BOOST`)。
|
|
22
|
+
配置键 `emotion_memory_weight`(默认开),设置页「情绪与人格」组可关。
|
|
23
|
+
|
|
24
|
+
### 做这项时踩的四个坑(都实证过,都记在这儿)
|
|
25
|
+
|
|
26
|
+
1. **`auto_appraise` 返回的是 dict,不是事件列表**:契约是
|
|
27
|
+
`{emotion, intensity, polarity, hits}`(不写时 `None`),**不含 valence**。
|
|
28
|
+
我一开始当列表用、又去读 `valence`,结果永远不触发。
|
|
29
|
+
顺带发现门槛是 **≥80 字、≥2 个命中词、正负混说不猜**——27 字的测试文本直接被跳过。
|
|
30
|
+
2. **`capture()` 的 `saved` 是"完整记录字典"列表,不是 id 列表**。
|
|
31
|
+
把整条记录当 id 传进去,`str()` 成一大串 → `找不到记忆 {'id': ...}`。
|
|
32
|
+
现在 `touch_by_emotion` 兼容 dict(自动取 id),调用方也显式取 `s["id"]`。
|
|
33
|
+
3. **量纲混用**:我把情绪强度(`abs(v)×i` = 0.9)当成"已用配额"去和上限 0.30 比,
|
|
34
|
+
于是**第一次就判超限**(实际只加了 0.06)。现在拆成两个字段:
|
|
35
|
+
`_touched_by_emotion`(强度列表,供召回加成)与 `_emo_touch_total`(配额,供封顶判断)。
|
|
36
|
+
4. `emotion_events()` 不是可靠入口(要等落盘、且受 genesis 过滤),直接吃返回值即可。
|
|
37
|
+
|
|
38
|
+
验证:`tests/test_p32_emotion_weight.py` **8/8**(负面上调/正与弱不动作/**累计封顶**/
|
|
39
|
+
兼容 dict/加成数学/**召回排序**/extract 端到端/配置与设置页);全套 **88/88**。
|
|
40
|
+
|
|
3
41
|
## v5.19(2026-11-26)
|
|
4
42
|
|
|
5
43
|
> 主题:**全量代码安全审计**——56 个文件 / 35855 行,产出 101 条发现
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
> 当前版本 **v5.
|
|
5
|
+
> 当前版本 **v5.20**(变更见 [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
|
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
- [错卦:召回区分否定](#错卦召回区分否定)
|
|
29
29
|
- [索引法记忆:正文不进上下文](#索引法记忆正文不进上下文)
|
|
30
30
|
- [情绪惯性:不会一句话就换心情](#情绪惯性不会一句话就换心情)
|
|
31
|
+
- [情绪驱动记忆权重:难受过的事更重](#情绪驱动记忆权重难受过的事更重)
|
|
31
32
|
- [成长阶段:它长到哪一步了](#成长阶段它长到哪一步了)
|
|
32
33
|
- [主动搭话:它会自己开口,但很少](#主动搭话它会自己开口但很少)
|
|
33
34
|
- [Git 分支感知:切了分支别拿旧分支的记忆](#git-分支感知切了分支别拿旧分支的记忆)
|
|
@@ -416,6 +417,28 @@ python scripts/brain.py memory show 7f3ca9ac # 短 id 直接取整条记忆
|
|
|
416
417
|
|
|
417
418
|
设置页「情绪与人格」组可逐项开关;`emotion_inertia_enabled=false` 一键回到原生行为。
|
|
418
419
|
|
|
420
|
+
## 情绪驱动记忆权重:难受过的事更重
|
|
421
|
+
|
|
422
|
+
不是所有记忆生而平等。让用户委屈、生气、害怕的事,本来就该记得更牢
|
|
423
|
+
(情绪记忆的巩固强度高于中性记忆)——这条把它做成了可核对的机制:
|
|
424
|
+
|
|
425
|
+
| 环节 | 机制 |
|
|
426
|
+
|---|---|
|
|
427
|
+
| 触发 | 情绪 `valence ≤ -0.3` 且 `intensity ≥ 0.1` |
|
|
428
|
+
| 加权 | 每次 `importance + 0.06`,**累计封顶 0.30** |
|
|
429
|
+
| 召回 | `score × (1 + 影响均值 × 0.3)` |
|
|
430
|
+
| 自动化 | `extract` 封存对话后自动判情绪,判出负面就给刚封存那批记忆加权 |
|
|
431
|
+
|
|
432
|
+
```bash
|
|
433
|
+
# 手动看效果
|
|
434
|
+
python scripts/brain.py memory show <短id> # 看 importance 与 _touched_by_emotion
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**为什么加在 importance 上**:它已在五元打分里占 0.35,往那里加权语义就是"这条对我更重要",
|
|
438
|
+
比新开一个维度干净。老记忆没有该字段 → 加成 0,**行为完全不变**。
|
|
439
|
+
|
|
440
|
+
配置 `emotion_memory_weight`(默认开),设置页「情绪与人格」组可关。
|
|
441
|
+
|
|
419
442
|
## 成长阶段:它长到哪一步了
|
|
420
443
|
|
|
421
444
|
把 doctor / failures / 自审的数据包成一句人话:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: lingshu
|
|
3
3
|
title: 灵枢
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.20
|
|
5
5
|
description: 类脑持久记忆、人格与成长系统——跨会话记住事情、长出自己的人格、上下文将满时做梦式整理记忆。用户提到记忆/记住/上次/人格/设定/性格/知识库/笔记/日志/成长/自我进化/工作记忆,或新会话开始需要恢复关系与上下文时使用。纯本地零依赖。
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -380,6 +380,7 @@ python scripts/bench.py [--n 1000|--quick] # 性能基准:隔离临
|
|
|
380
380
|
| 想立刻关 | 面板「设置」页 → **「退出服务」** |
|
|
381
381
|
| 连点两次 | 安全:启动器先探测,**已在跑就只把浏览器叫回来**,不会起第二个 |
|
|
382
382
|
| **桌面快捷方式丢了** | `python scripts/brain.py shortcut --ensure`(幂等:缺了就重建,已有就不动) |
|
|
383
|
+
| 记一条"让我难受的事" | 正常 `remember` 即可;判出负面情绪后 importance 会自动 +0.06(封顶 0.30),召回时也更靠前 |
|
|
383
384
|
| 看情绪/心情 | `python scripts/brain.py emotion now`(标签受惯性保护,`raw_label` 是即时感受) |
|
|
384
385
|
| 看它长到哪一步 | `python scripts/brain.py stage`(蛋/幼体/少年/成年/传奇 + 下一步差什么) |
|
|
385
386
|
| 取一条记忆的正文 | `python scripts/brain.py memory show <短id>`(注入里的 8 位短号直接用,也认完整 id 前缀) |
|
|
@@ -1627,6 +1627,12 @@ def _main(argv=None) -> int:
|
|
|
1627
1627
|
p_tr.add_argument("--json", action="store_true")
|
|
1628
1628
|
|
|
1629
1629
|
# P11 #76 桌面快捷方式「灵枢面板」
|
|
1630
|
+
p_sk_evo = sub.add_parser(
|
|
1631
|
+
"skill-evolve", help="技能自我进化(P2-2):把记忆里的踩坑经验回灌到技能旁的贴士文件")
|
|
1632
|
+
p_sk_evo.add_argument("--days", type=int, default=7)
|
|
1633
|
+
p_sk_evo.add_argument("--dry-run", action="store_true")
|
|
1634
|
+
p_sk_evo.add_argument("--json", action="store_true")
|
|
1635
|
+
|
|
1630
1636
|
p_stage = sub.add_parser("stage", help="灵枢成长阶段(P2-4):蛋/幼体/少年/成年/传奇")
|
|
1631
1637
|
p_stage.add_argument("--json", action="store_true")
|
|
1632
1638
|
|
|
@@ -2351,21 +2357,24 @@ def _main(argv=None) -> int:
|
|
|
2351
2357
|
# v3.55:封存成功后再顺手判一次情绪(纯词表,强度封顶 0.35)。
|
|
2352
2358
|
# 整段兜住:心情没记住是小事,对话没封存才是大事。
|
|
2353
2359
|
try:
|
|
2354
|
-
from emotion import auto_appraise
|
|
2355
|
-
|
|
2356
|
-
#
|
|
2357
|
-
|
|
2360
|
+
from emotion import auto_appraise
|
|
2361
|
+
# 契约:返回 {emotion, intensity, polarity, hits};不写时返回 None
|
|
2362
|
+
# (门槛:≥80 字、≥2 个命中词、正负混说不猜)。**不含 valence**。
|
|
2363
|
+
ev = auto_appraise(text)
|
|
2364
|
+
# P2-3 情绪驱动的记忆权重:判出**负面**时给刚封存那批记忆加权
|
|
2365
|
+
# ("记仇"效应)。valence 用常量 -0.6 明确越过负面阈值;
|
|
2366
|
+
# 正面/中性一律不碰。
|
|
2358
2367
|
try:
|
|
2359
|
-
if
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2368
|
+
if (isinstance(ev, dict)
|
|
2369
|
+
and ev.get("polarity") == "negative"
|
|
2370
|
+
and core.load_config().get("emotion_memory_weight", True)):
|
|
2371
|
+
_i = float(ev.get("intensity") or 0)
|
|
2372
|
+
import memory as _mem_mod
|
|
2373
|
+
# capture() 的 saved 是**记录列表**(不是 id 列表),显式取 id
|
|
2374
|
+
for _it in (res.get("saved") or [])[:20]:
|
|
2375
|
+
_mid = _it.get("id") if isinstance(_it, dict) else _it
|
|
2376
|
+
if _mid:
|
|
2377
|
+
_mem_mod.touch_by_emotion(_mid, -0.6, _i)
|
|
2369
2378
|
except Exception as exc: # noqa: BLE001
|
|
2370
2379
|
log_event("emotion-auto", f"情绪加权失败(封存已成功,可忽略):{exc}",
|
|
2371
2380
|
level="warn")
|
|
@@ -2698,6 +2707,26 @@ def _main(argv=None) -> int:
|
|
|
2698
2707
|
print("没有删除任何东西;要清空请你自己动手。")
|
|
2699
2708
|
return 0 if res["ok"] else 1
|
|
2700
2709
|
|
|
2710
|
+
if args.cmd == "skill-evolve":
|
|
2711
|
+
import growth as _g_evo
|
|
2712
|
+
r = _g_evo.skill_evolve(days=args.days, dry_run=args.dry_run)
|
|
2713
|
+
if args.json:
|
|
2714
|
+
print(json.dumps(r, ensure_ascii=False, indent=2))
|
|
2715
|
+
return 0 if r.get("ok") else 1
|
|
2716
|
+
if not r.get("ok"):
|
|
2717
|
+
print(f"[错误] {r.get('error')}", file=sys.stderr)
|
|
2718
|
+
return 1
|
|
2719
|
+
if not r["skills"]:
|
|
2720
|
+
print("没有标了 `skill:<名字>` 标签的记忆(至少 2 条才会生成贴士)。")
|
|
2721
|
+
return 0
|
|
2722
|
+
for s in r["skills"]:
|
|
2723
|
+
note = s.get("skipped") or f"贴士 {s['tips']} 条,新写入 {s['written']} 条"
|
|
2724
|
+
print(f" {s['name']}:{s['memories']} 条相关记忆 → {note}")
|
|
2725
|
+
if s.get("path"):
|
|
2726
|
+
print(f" {s['path']}")
|
|
2727
|
+
print(f"合计新写入 {r['total_written']} 条" + ("(dry-run,未落盘)" if args.dry_run else ""))
|
|
2728
|
+
return 0
|
|
2729
|
+
|
|
2701
2730
|
if args.cmd == "stage":
|
|
2702
2731
|
import growth as _g
|
|
2703
2732
|
s = _g.stage_state()
|
|
@@ -4226,6 +4255,25 @@ def _main(argv=None) -> int:
|
|
|
4226
4255
|
return ("runtime-liveness", "WARN", ";".join(parts))
|
|
4227
4256
|
return ("runtime-liveness", "PASS", ";".join(parts))
|
|
4228
4257
|
|
|
4258
|
+
def _doctor_skill_evolve() -> tuple:
|
|
4259
|
+
"""P2-2:技能贴士文件是否存在(有经验被回灌过)。只读,无贴士不算错误。"""
|
|
4260
|
+
try:
|
|
4261
|
+
import growth as _g_se
|
|
4262
|
+
dirs = []
|
|
4263
|
+
try:
|
|
4264
|
+
for d in _g_se.SKILLS_DIR.iterdir():
|
|
4265
|
+
if (d / _g_se.TIPS_FILENAME).is_file():
|
|
4266
|
+
dirs.append(d.name)
|
|
4267
|
+
except OSError:
|
|
4268
|
+
return ("skill-evolve", "PASS", "技能库不可读(跳过)")
|
|
4269
|
+
if dirs:
|
|
4270
|
+
return ("skill-evolve", "PASS",
|
|
4271
|
+
f"{len(dirs)} 个技能已有贴士:{('、'.join(dirs[:3]))}")
|
|
4272
|
+
return ("skill-evolve", "PASS",
|
|
4273
|
+
"暂无贴士(记忆里还没有 ≥2 条同一 `skill:` 标签的经历)")
|
|
4274
|
+
except Exception as exc: # noqa: BLE001
|
|
4275
|
+
return ("skill-evolve", "WARN", f"检查失败:{exc}")
|
|
4276
|
+
|
|
4229
4277
|
def _doctor_desktop_shortcut() -> tuple:
|
|
4230
4278
|
"""桌面「灵枢面板」快捷方式还在不在。
|
|
4231
4279
|
|
|
@@ -4486,6 +4534,12 @@ def _main(argv=None) -> int:
|
|
|
4486
4534
|
except Exception as e:
|
|
4487
4535
|
checks.append(("runtime-liveness", "WARN", f"自检失败:{e}"))
|
|
4488
4536
|
|
|
4537
|
+
# 13b. P2-2:技能贴士(自我进化的落点)
|
|
4538
|
+
try:
|
|
4539
|
+
checks.append(_doctor_skill_evolve())
|
|
4540
|
+
except Exception as e:
|
|
4541
|
+
checks.append(("skill-evolve", "WARN", f"自检失败:{e}"))
|
|
4542
|
+
|
|
4489
4543
|
# 14. 桌面快捷方式是否还在(用户可能不小心删了)
|
|
4490
4544
|
try:
|
|
4491
4545
|
checks.append(_doctor_desktop_shortcut())
|
|
@@ -3077,6 +3077,145 @@ def check_skill(name: str | None = None) -> list:
|
|
|
3077
3077
|
# 用户要求"每隔 2-3 天就总结下自己的灵枢技能":这里生成一份自省素材,
|
|
3078
3078
|
# 由 AI 写进成长笔记,并把 last_self_review 记到 config,注入包据此提醒。
|
|
3079
3079
|
|
|
3080
|
+
# ---------------------------------------------------------------- 技能自我进化(P2-2)
|
|
3081
|
+
|
|
3082
|
+
TIPS_FILENAME = ".lingshu-tips.md"
|
|
3083
|
+
SKILL_TAG_PREFIXES = ("skill:", "skill/")
|
|
3084
|
+
TIPS_MIN_MEMORIES = 2 # 同一技能至少几条相关记忆才成"经验"
|
|
3085
|
+
TIPS_MAX_CHARS = 150 # 单条贴士正文上限
|
|
3086
|
+
|
|
3087
|
+
|
|
3088
|
+
def _skill_tags_of(m: dict) -> list:
|
|
3089
|
+
"""一条记忆里标了哪些 skill(`skill:name` / `skill/name` 两种写法都认)。"""
|
|
3090
|
+
out = []
|
|
3091
|
+
for raw in (m.get("tags") or []):
|
|
3092
|
+
s = str(raw).strip()
|
|
3093
|
+
for pref in SKILL_TAG_PREFIXES:
|
|
3094
|
+
if s.lower().startswith(pref):
|
|
3095
|
+
name = s[len(pref):].strip()
|
|
3096
|
+
if name:
|
|
3097
|
+
out.append(name)
|
|
3098
|
+
return out
|
|
3099
|
+
|
|
3100
|
+
|
|
3101
|
+
def _skill_dir_of(name: str) -> Path | None:
|
|
3102
|
+
"""已安装的技能目录;不存在返回 None(绝不新建)。"""
|
|
3103
|
+
try:
|
|
3104
|
+
d = SKILLS_DIR / str(name)
|
|
3105
|
+
if (d / "SKILL.md").is_file():
|
|
3106
|
+
return d
|
|
3107
|
+
except OSError:
|
|
3108
|
+
pass
|
|
3109
|
+
return None
|
|
3110
|
+
|
|
3111
|
+
|
|
3112
|
+
def _tip_line(m: dict) -> str:
|
|
3113
|
+
"""把一条相关记忆压成一句"可能踩的坑"(引用索引原文,不自己编)。"""
|
|
3114
|
+
idx = str(m.get("index") or "").strip()
|
|
3115
|
+
if not idx:
|
|
3116
|
+
try:
|
|
3117
|
+
idx = _make_gist(str(m.get("text") or ""))
|
|
3118
|
+
except Exception: # noqa: BLE001
|
|
3119
|
+
idx = str(m.get("text") or "")[:40]
|
|
3120
|
+
kind = str(m.get("kind") or "")
|
|
3121
|
+
tag = {"mistake": "踩过的坑", "correction": "被纠正过", "emotion": "情绪高点"}.get(kind, "相关记录")
|
|
3122
|
+
line = f"{tag}:{idx}"
|
|
3123
|
+
return line[:TIPS_MAX_CHARS]
|
|
3124
|
+
|
|
3125
|
+
|
|
3126
|
+
def _make_gist(text: str, limit: int = 40) -> str:
|
|
3127
|
+
"""极简取首句(growth 侧没有 memory 的 _make_index,这里就地实现一份)。"""
|
|
3128
|
+
s = " ".join(str(text or "").split())
|
|
3129
|
+
for ch in "。!?!?\n;;,,":
|
|
3130
|
+
i = s.find(ch)
|
|
3131
|
+
if 0 < i <= limit:
|
|
3132
|
+
return s[:i]
|
|
3133
|
+
return s[:limit]
|
|
3134
|
+
|
|
3135
|
+
|
|
3136
|
+
def _tips_append(skill_dir: Path, lines: list, stamp: str) -> int:
|
|
3137
|
+
"""追加贴士,按正文 sha256 去重。返回新写入条数。"""
|
|
3138
|
+
path = skill_dir / TIPS_FILENAME
|
|
3139
|
+
existing = ""
|
|
3140
|
+
if path.is_file():
|
|
3141
|
+
try:
|
|
3142
|
+
existing = path.read_text(encoding="utf-8", errors="replace")
|
|
3143
|
+
except OSError:
|
|
3144
|
+
existing = ""
|
|
3145
|
+
seen = set()
|
|
3146
|
+
for ln in existing.splitlines():
|
|
3147
|
+
ln = ln.strip()
|
|
3148
|
+
if ln.startswith("- "):
|
|
3149
|
+
seen.add(hashlib.sha256(ln[2:].strip().encode("utf-8")).hexdigest()[:12])
|
|
3150
|
+
fresh = []
|
|
3151
|
+
for ln in lines:
|
|
3152
|
+
key = hashlib.sha256(ln.strip().encode("utf-8")).hexdigest()[:12]
|
|
3153
|
+
if key in seen:
|
|
3154
|
+
continue
|
|
3155
|
+
seen.add(key)
|
|
3156
|
+
fresh.append(ln)
|
|
3157
|
+
if not fresh:
|
|
3158
|
+
return 0
|
|
3159
|
+
try:
|
|
3160
|
+
if not existing:
|
|
3161
|
+
head = ("# 灵枢给这个技能的贴士(自动追加,保留历史)\n\n"
|
|
3162
|
+
"> 来源:记忆里标了 `skill:` 标签的真实经历。只引用索引原文,不臆造。\n")
|
|
3163
|
+
path.write_text(head, encoding="utf-8", newline="\n")
|
|
3164
|
+
with open(path, "a", encoding="utf-8", newline="\n") as f:
|
|
3165
|
+
f.write(f"\n## {stamp}\n")
|
|
3166
|
+
for ln in fresh:
|
|
3167
|
+
f.write(f"- {ln}\n")
|
|
3168
|
+
except OSError:
|
|
3169
|
+
return 0
|
|
3170
|
+
return len(fresh)
|
|
3171
|
+
|
|
3172
|
+
|
|
3173
|
+
def skill_evolve(days: int = 7, dry_run: bool = False) -> dict:
|
|
3174
|
+
"""扫描最近记忆里的 `skill:` 标记,给对应技能追加贴士(P2-2)。
|
|
3175
|
+
|
|
3176
|
+
返回 {ok, skills: [{name, memories, tips, written, path}], total_written}。
|
|
3177
|
+
任何异常都不抛出:这是锦上添花的能力,不该让 self-review 挂掉。
|
|
3178
|
+
"""
|
|
3179
|
+
try:
|
|
3180
|
+
import memory as _mem
|
|
3181
|
+
rows = [m for m in _mem.load_all() if isinstance(m, dict) and m.get("id")]
|
|
3182
|
+
except Exception as exc: # noqa: BLE001
|
|
3183
|
+
return {"ok": False, "error": f"读记忆失败:{exc}", "skills": [],
|
|
3184
|
+
"total_written": 0}
|
|
3185
|
+
cutoff = brain.now_ts() - max(1, int(days)) * brain.DAY
|
|
3186
|
+
by_skill: dict[str, list] = {}
|
|
3187
|
+
for m in rows:
|
|
3188
|
+
try:
|
|
3189
|
+
if int(m.get("created") or 0) < cutoff:
|
|
3190
|
+
continue
|
|
3191
|
+
except (TypeError, ValueError):
|
|
3192
|
+
continue
|
|
3193
|
+
for name in _skill_tags_of(m):
|
|
3194
|
+
by_skill.setdefault(name, []).append(m)
|
|
3195
|
+
|
|
3196
|
+
stamp = time.strftime("%Y-%m-%d")
|
|
3197
|
+
out, total = [], 0
|
|
3198
|
+
for name, mems in sorted(by_skill.items()):
|
|
3199
|
+
if len(mems) < TIPS_MIN_MEMORIES:
|
|
3200
|
+
continue
|
|
3201
|
+
d = _skill_dir_of(name)
|
|
3202
|
+
if d is None:
|
|
3203
|
+
out.append({"name": name, "memories": len(mems), "tips": 0,
|
|
3204
|
+
"written": 0, "path": "", "skipped": "技能目录不存在"})
|
|
3205
|
+
continue
|
|
3206
|
+
# 优先 mistake / correction(那才是"坑"),再补其它,最多 5 条
|
|
3207
|
+
ranked = sorted(mems, key=lambda m: (0 if str(m.get("kind")) in ("mistake", "correction") else 1,
|
|
3208
|
+
-_num(m.get("importance"), 0.5)))
|
|
3209
|
+
lines = [_tip_line(m) for m in ranked[:5]]
|
|
3210
|
+
lines = [ln for ln in lines if ln]
|
|
3211
|
+
written = 0 if dry_run else _tips_append(d, lines, stamp)
|
|
3212
|
+
total += written
|
|
3213
|
+
out.append({"name": name, "memories": len(mems), "tips": len(lines),
|
|
3214
|
+
"written": written, "path": str(d / TIPS_FILENAME)})
|
|
3215
|
+
return {"ok": True, "skills": out, "total_written": total,
|
|
3216
|
+
"scanned": len(rows), "days": days, "dry_run": bool(dry_run)}
|
|
3217
|
+
|
|
3218
|
+
|
|
3080
3219
|
def self_review(force: bool = False, days: int = 3) -> dict:
|
|
3081
3220
|
cfg = brain.load_config()
|
|
3082
3221
|
now = brain.now_ts()
|
|
@@ -3138,7 +3277,14 @@ def self_review(force: bool = False, days: int = 3) -> dict:
|
|
|
3138
3277
|
saved = True
|
|
3139
3278
|
except OSError:
|
|
3140
3279
|
saved = False
|
|
3141
|
-
|
|
3280
|
+
# P2-2 技能自我进化:把这一轮的"踩坑经验"回灌到对应技能旁边。
|
|
3281
|
+
# 整段兜住——回灌失败绝不能让自我总结挂掉。
|
|
3282
|
+
try:
|
|
3283
|
+
_evolve = skill_evolve(days=max(2, days))
|
|
3284
|
+
except Exception as _exc: # noqa: BLE001
|
|
3285
|
+
_evolve = {"ok": False, "error": str(_exc), "total_written": 0}
|
|
3286
|
+
return {
|
|
3287
|
+
"skill_evolve": _evolve,"due": True, "last": last, "days": days, "summary": summary, "saved": saved}
|
|
3142
3288
|
|
|
3143
3289
|
|
|
3144
3290
|
def _readonly() -> bool:
|
|
@@ -992,7 +992,8 @@ def boost(memory_id: str) -> dict:
|
|
|
992
992
|
# ---------------------------------------------------------------- 情绪驱动的记忆权重(P2-3)
|
|
993
993
|
# 「记仇」效应:让用户委屈/生气的事更重、更容易被想起。这不是玄学——
|
|
994
994
|
# 情绪记忆的巩固强度本来就高于中性记忆(amygdala 调制,McGaugh 2004)。
|
|
995
|
-
EMO_TOUCH_FIELD = "_touched_by_emotion" #
|
|
995
|
+
EMO_TOUCH_FIELD = "_touched_by_emotion" # 历次情绪**强度**(供 recall 加成)
|
|
996
|
+
EMO_TOTAL_FIELD = "_emo_touch_total" # 累计**已加到 importance 的增量**(配额)
|
|
996
997
|
EMO_TOUCH_STEP = 0.06 # 每次负面情绪给 importance 的增量
|
|
997
998
|
EMO_TOUCH_MAX = 0.30 # 累计增量上限(防一条被反复顶到 1.0)
|
|
998
999
|
EMO_TOUCH_NEG_MAX_VALENCE = -0.3 # 只对 valence < 这个值(够负面)生效
|
|
@@ -1018,6 +1019,10 @@ def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
|
1018
1019
|
return {"ok": True, "changed": False, "reason": "情绪太弱(intensity 低于阈值)"}
|
|
1019
1020
|
if READONLY:
|
|
1020
1021
|
return {"ok": False, "changed": False, "reason": "记忆库只读"}
|
|
1022
|
+
# 调用方可能传完整记录字典(capture() 的 saved 就是记录列表)——宽松取 id,
|
|
1023
|
+
# 别把一个 dict 的 repr 当 id 去查(实测踩过)。
|
|
1024
|
+
if isinstance(memory_id, dict):
|
|
1025
|
+
memory_id = memory_id.get("id")
|
|
1021
1026
|
mid = str(memory_id or "").strip()
|
|
1022
1027
|
if not mid:
|
|
1023
1028
|
return {"ok": False, "changed": False, "reason": "没有 memory_id"}
|
|
@@ -1027,8 +1032,9 @@ def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
|
1027
1032
|
if found is None:
|
|
1028
1033
|
return {"ok": False, "changed": False, "reason": f"找不到记忆 {mid}"}
|
|
1029
1034
|
marks = list(found.get(EMO_TOUCH_FIELD) or [])
|
|
1030
|
-
|
|
1031
|
-
#
|
|
1035
|
+
# 配额看"已加了多少 importance",**不是**看情绪强度——
|
|
1036
|
+
# 两者量纲不同(0.06 vs 0.9),混用会让第一次就判超限(实测踩过)。
|
|
1037
|
+
used = _num(found.get(EMO_TOTAL_FIELD), 0.0)
|
|
1032
1038
|
room = max(0.0, EMO_TOUCH_MAX - used)
|
|
1033
1039
|
delta = min(EMO_TOUCH_STEP, room)
|
|
1034
1040
|
if delta <= 0:
|
|
@@ -1039,6 +1045,7 @@ def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
|
1039
1045
|
# 记下本次影响(限长,避免字段无界增长)
|
|
1040
1046
|
marks.append(round(abs(v) * max(0.0, min(1.0, i)), 3))
|
|
1041
1047
|
found[EMO_TOUCH_FIELD] = marks[-20:]
|
|
1048
|
+
found[EMO_TOTAL_FIELD] = round(used + delta, 3)
|
|
1042
1049
|
save_all(records)
|
|
1043
1050
|
try:
|
|
1044
1051
|
log_event("emotion", f"情绪加权 {mid}:importance {old:.2f} → "
|
|
@@ -1046,7 +1053,8 @@ def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
|
1046
1053
|
except Exception: # noqa: BLE001
|
|
1047
1054
|
pass
|
|
1048
1055
|
return {"ok": True, "changed": True, "importance": found["importance"],
|
|
1049
|
-
"delta": round(delta, 3)
|
|
1056
|
+
"delta": round(delta, 3),
|
|
1057
|
+
"total": found.get(EMO_TOTAL_FIELD, round(delta, 3))}
|
|
1050
1058
|
|
|
1051
1059
|
|
|
1052
1060
|
def _emo_boost_of(m: dict) -> float:
|
package/scripts/cli.py
CHANGED
|
@@ -1627,6 +1627,12 @@ def _main(argv=None) -> int:
|
|
|
1627
1627
|
p_tr.add_argument("--json", action="store_true")
|
|
1628
1628
|
|
|
1629
1629
|
# P11 #76 桌面快捷方式「灵枢面板」
|
|
1630
|
+
p_sk_evo = sub.add_parser(
|
|
1631
|
+
"skill-evolve", help="技能自我进化(P2-2):把记忆里的踩坑经验回灌到技能旁的贴士文件")
|
|
1632
|
+
p_sk_evo.add_argument("--days", type=int, default=7)
|
|
1633
|
+
p_sk_evo.add_argument("--dry-run", action="store_true")
|
|
1634
|
+
p_sk_evo.add_argument("--json", action="store_true")
|
|
1635
|
+
|
|
1630
1636
|
p_stage = sub.add_parser("stage", help="灵枢成长阶段(P2-4):蛋/幼体/少年/成年/传奇")
|
|
1631
1637
|
p_stage.add_argument("--json", action="store_true")
|
|
1632
1638
|
|
|
@@ -2351,21 +2357,24 @@ def _main(argv=None) -> int:
|
|
|
2351
2357
|
# v3.55:封存成功后再顺手判一次情绪(纯词表,强度封顶 0.35)。
|
|
2352
2358
|
# 整段兜住:心情没记住是小事,对话没封存才是大事。
|
|
2353
2359
|
try:
|
|
2354
|
-
from emotion import auto_appraise
|
|
2355
|
-
|
|
2356
|
-
#
|
|
2357
|
-
|
|
2360
|
+
from emotion import auto_appraise
|
|
2361
|
+
# 契约:返回 {emotion, intensity, polarity, hits};不写时返回 None
|
|
2362
|
+
# (门槛:≥80 字、≥2 个命中词、正负混说不猜)。**不含 valence**。
|
|
2363
|
+
ev = auto_appraise(text)
|
|
2364
|
+
# P2-3 情绪驱动的记忆权重:判出**负面**时给刚封存那批记忆加权
|
|
2365
|
+
# ("记仇"效应)。valence 用常量 -0.6 明确越过负面阈值;
|
|
2366
|
+
# 正面/中性一律不碰。
|
|
2358
2367
|
try:
|
|
2359
|
-
if
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2368
|
+
if (isinstance(ev, dict)
|
|
2369
|
+
and ev.get("polarity") == "negative"
|
|
2370
|
+
and core.load_config().get("emotion_memory_weight", True)):
|
|
2371
|
+
_i = float(ev.get("intensity") or 0)
|
|
2372
|
+
import memory as _mem_mod
|
|
2373
|
+
# capture() 的 saved 是**记录列表**(不是 id 列表),显式取 id
|
|
2374
|
+
for _it in (res.get("saved") or [])[:20]:
|
|
2375
|
+
_mid = _it.get("id") if isinstance(_it, dict) else _it
|
|
2376
|
+
if _mid:
|
|
2377
|
+
_mem_mod.touch_by_emotion(_mid, -0.6, _i)
|
|
2369
2378
|
except Exception as exc: # noqa: BLE001
|
|
2370
2379
|
log_event("emotion-auto", f"情绪加权失败(封存已成功,可忽略):{exc}",
|
|
2371
2380
|
level="warn")
|
|
@@ -2698,6 +2707,26 @@ def _main(argv=None) -> int:
|
|
|
2698
2707
|
print("没有删除任何东西;要清空请你自己动手。")
|
|
2699
2708
|
return 0 if res["ok"] else 1
|
|
2700
2709
|
|
|
2710
|
+
if args.cmd == "skill-evolve":
|
|
2711
|
+
import growth as _g_evo
|
|
2712
|
+
r = _g_evo.skill_evolve(days=args.days, dry_run=args.dry_run)
|
|
2713
|
+
if args.json:
|
|
2714
|
+
print(json.dumps(r, ensure_ascii=False, indent=2))
|
|
2715
|
+
return 0 if r.get("ok") else 1
|
|
2716
|
+
if not r.get("ok"):
|
|
2717
|
+
print(f"[错误] {r.get('error')}", file=sys.stderr)
|
|
2718
|
+
return 1
|
|
2719
|
+
if not r["skills"]:
|
|
2720
|
+
print("没有标了 `skill:<名字>` 标签的记忆(至少 2 条才会生成贴士)。")
|
|
2721
|
+
return 0
|
|
2722
|
+
for s in r["skills"]:
|
|
2723
|
+
note = s.get("skipped") or f"贴士 {s['tips']} 条,新写入 {s['written']} 条"
|
|
2724
|
+
print(f" {s['name']}:{s['memories']} 条相关记忆 → {note}")
|
|
2725
|
+
if s.get("path"):
|
|
2726
|
+
print(f" {s['path']}")
|
|
2727
|
+
print(f"合计新写入 {r['total_written']} 条" + ("(dry-run,未落盘)" if args.dry_run else ""))
|
|
2728
|
+
return 0
|
|
2729
|
+
|
|
2701
2730
|
if args.cmd == "stage":
|
|
2702
2731
|
import growth as _g
|
|
2703
2732
|
s = _g.stage_state()
|
|
@@ -4226,6 +4255,25 @@ def _main(argv=None) -> int:
|
|
|
4226
4255
|
return ("runtime-liveness", "WARN", ";".join(parts))
|
|
4227
4256
|
return ("runtime-liveness", "PASS", ";".join(parts))
|
|
4228
4257
|
|
|
4258
|
+
def _doctor_skill_evolve() -> tuple:
|
|
4259
|
+
"""P2-2:技能贴士文件是否存在(有经验被回灌过)。只读,无贴士不算错误。"""
|
|
4260
|
+
try:
|
|
4261
|
+
import growth as _g_se
|
|
4262
|
+
dirs = []
|
|
4263
|
+
try:
|
|
4264
|
+
for d in _g_se.SKILLS_DIR.iterdir():
|
|
4265
|
+
if (d / _g_se.TIPS_FILENAME).is_file():
|
|
4266
|
+
dirs.append(d.name)
|
|
4267
|
+
except OSError:
|
|
4268
|
+
return ("skill-evolve", "PASS", "技能库不可读(跳过)")
|
|
4269
|
+
if dirs:
|
|
4270
|
+
return ("skill-evolve", "PASS",
|
|
4271
|
+
f"{len(dirs)} 个技能已有贴士:{('、'.join(dirs[:3]))}")
|
|
4272
|
+
return ("skill-evolve", "PASS",
|
|
4273
|
+
"暂无贴士(记忆里还没有 ≥2 条同一 `skill:` 标签的经历)")
|
|
4274
|
+
except Exception as exc: # noqa: BLE001
|
|
4275
|
+
return ("skill-evolve", "WARN", f"检查失败:{exc}")
|
|
4276
|
+
|
|
4229
4277
|
def _doctor_desktop_shortcut() -> tuple:
|
|
4230
4278
|
"""桌面「灵枢面板」快捷方式还在不在。
|
|
4231
4279
|
|
|
@@ -4486,6 +4534,12 @@ def _main(argv=None) -> int:
|
|
|
4486
4534
|
except Exception as e:
|
|
4487
4535
|
checks.append(("runtime-liveness", "WARN", f"自检失败:{e}"))
|
|
4488
4536
|
|
|
4537
|
+
# 13b. P2-2:技能贴士(自我进化的落点)
|
|
4538
|
+
try:
|
|
4539
|
+
checks.append(_doctor_skill_evolve())
|
|
4540
|
+
except Exception as e:
|
|
4541
|
+
checks.append(("skill-evolve", "WARN", f"自检失败:{e}"))
|
|
4542
|
+
|
|
4489
4543
|
# 14. 桌面快捷方式是否还在(用户可能不小心删了)
|
|
4490
4544
|
try:
|
|
4491
4545
|
checks.append(_doctor_desktop_shortcut())
|
package/scripts/growth.py
CHANGED
|
@@ -3077,6 +3077,145 @@ def check_skill(name: str | None = None) -> list:
|
|
|
3077
3077
|
# 用户要求"每隔 2-3 天就总结下自己的灵枢技能":这里生成一份自省素材,
|
|
3078
3078
|
# 由 AI 写进成长笔记,并把 last_self_review 记到 config,注入包据此提醒。
|
|
3079
3079
|
|
|
3080
|
+
# ---------------------------------------------------------------- 技能自我进化(P2-2)
|
|
3081
|
+
|
|
3082
|
+
TIPS_FILENAME = ".lingshu-tips.md"
|
|
3083
|
+
SKILL_TAG_PREFIXES = ("skill:", "skill/")
|
|
3084
|
+
TIPS_MIN_MEMORIES = 2 # 同一技能至少几条相关记忆才成"经验"
|
|
3085
|
+
TIPS_MAX_CHARS = 150 # 单条贴士正文上限
|
|
3086
|
+
|
|
3087
|
+
|
|
3088
|
+
def _skill_tags_of(m: dict) -> list:
|
|
3089
|
+
"""一条记忆里标了哪些 skill(`skill:name` / `skill/name` 两种写法都认)。"""
|
|
3090
|
+
out = []
|
|
3091
|
+
for raw in (m.get("tags") or []):
|
|
3092
|
+
s = str(raw).strip()
|
|
3093
|
+
for pref in SKILL_TAG_PREFIXES:
|
|
3094
|
+
if s.lower().startswith(pref):
|
|
3095
|
+
name = s[len(pref):].strip()
|
|
3096
|
+
if name:
|
|
3097
|
+
out.append(name)
|
|
3098
|
+
return out
|
|
3099
|
+
|
|
3100
|
+
|
|
3101
|
+
def _skill_dir_of(name: str) -> Path | None:
|
|
3102
|
+
"""已安装的技能目录;不存在返回 None(绝不新建)。"""
|
|
3103
|
+
try:
|
|
3104
|
+
d = SKILLS_DIR / str(name)
|
|
3105
|
+
if (d / "SKILL.md").is_file():
|
|
3106
|
+
return d
|
|
3107
|
+
except OSError:
|
|
3108
|
+
pass
|
|
3109
|
+
return None
|
|
3110
|
+
|
|
3111
|
+
|
|
3112
|
+
def _tip_line(m: dict) -> str:
|
|
3113
|
+
"""把一条相关记忆压成一句"可能踩的坑"(引用索引原文,不自己编)。"""
|
|
3114
|
+
idx = str(m.get("index") or "").strip()
|
|
3115
|
+
if not idx:
|
|
3116
|
+
try:
|
|
3117
|
+
idx = _make_gist(str(m.get("text") or ""))
|
|
3118
|
+
except Exception: # noqa: BLE001
|
|
3119
|
+
idx = str(m.get("text") or "")[:40]
|
|
3120
|
+
kind = str(m.get("kind") or "")
|
|
3121
|
+
tag = {"mistake": "踩过的坑", "correction": "被纠正过", "emotion": "情绪高点"}.get(kind, "相关记录")
|
|
3122
|
+
line = f"{tag}:{idx}"
|
|
3123
|
+
return line[:TIPS_MAX_CHARS]
|
|
3124
|
+
|
|
3125
|
+
|
|
3126
|
+
def _make_gist(text: str, limit: int = 40) -> str:
|
|
3127
|
+
"""极简取首句(growth 侧没有 memory 的 _make_index,这里就地实现一份)。"""
|
|
3128
|
+
s = " ".join(str(text or "").split())
|
|
3129
|
+
for ch in "。!?!?\n;;,,":
|
|
3130
|
+
i = s.find(ch)
|
|
3131
|
+
if 0 < i <= limit:
|
|
3132
|
+
return s[:i]
|
|
3133
|
+
return s[:limit]
|
|
3134
|
+
|
|
3135
|
+
|
|
3136
|
+
def _tips_append(skill_dir: Path, lines: list, stamp: str) -> int:
|
|
3137
|
+
"""追加贴士,按正文 sha256 去重。返回新写入条数。"""
|
|
3138
|
+
path = skill_dir / TIPS_FILENAME
|
|
3139
|
+
existing = ""
|
|
3140
|
+
if path.is_file():
|
|
3141
|
+
try:
|
|
3142
|
+
existing = path.read_text(encoding="utf-8", errors="replace")
|
|
3143
|
+
except OSError:
|
|
3144
|
+
existing = ""
|
|
3145
|
+
seen = set()
|
|
3146
|
+
for ln in existing.splitlines():
|
|
3147
|
+
ln = ln.strip()
|
|
3148
|
+
if ln.startswith("- "):
|
|
3149
|
+
seen.add(hashlib.sha256(ln[2:].strip().encode("utf-8")).hexdigest()[:12])
|
|
3150
|
+
fresh = []
|
|
3151
|
+
for ln in lines:
|
|
3152
|
+
key = hashlib.sha256(ln.strip().encode("utf-8")).hexdigest()[:12]
|
|
3153
|
+
if key in seen:
|
|
3154
|
+
continue
|
|
3155
|
+
seen.add(key)
|
|
3156
|
+
fresh.append(ln)
|
|
3157
|
+
if not fresh:
|
|
3158
|
+
return 0
|
|
3159
|
+
try:
|
|
3160
|
+
if not existing:
|
|
3161
|
+
head = ("# 灵枢给这个技能的贴士(自动追加,保留历史)\n\n"
|
|
3162
|
+
"> 来源:记忆里标了 `skill:` 标签的真实经历。只引用索引原文,不臆造。\n")
|
|
3163
|
+
path.write_text(head, encoding="utf-8", newline="\n")
|
|
3164
|
+
with open(path, "a", encoding="utf-8", newline="\n") as f:
|
|
3165
|
+
f.write(f"\n## {stamp}\n")
|
|
3166
|
+
for ln in fresh:
|
|
3167
|
+
f.write(f"- {ln}\n")
|
|
3168
|
+
except OSError:
|
|
3169
|
+
return 0
|
|
3170
|
+
return len(fresh)
|
|
3171
|
+
|
|
3172
|
+
|
|
3173
|
+
def skill_evolve(days: int = 7, dry_run: bool = False) -> dict:
|
|
3174
|
+
"""扫描最近记忆里的 `skill:` 标记,给对应技能追加贴士(P2-2)。
|
|
3175
|
+
|
|
3176
|
+
返回 {ok, skills: [{name, memories, tips, written, path}], total_written}。
|
|
3177
|
+
任何异常都不抛出:这是锦上添花的能力,不该让 self-review 挂掉。
|
|
3178
|
+
"""
|
|
3179
|
+
try:
|
|
3180
|
+
import memory as _mem
|
|
3181
|
+
rows = [m for m in _mem.load_all() if isinstance(m, dict) and m.get("id")]
|
|
3182
|
+
except Exception as exc: # noqa: BLE001
|
|
3183
|
+
return {"ok": False, "error": f"读记忆失败:{exc}", "skills": [],
|
|
3184
|
+
"total_written": 0}
|
|
3185
|
+
cutoff = brain.now_ts() - max(1, int(days)) * brain.DAY
|
|
3186
|
+
by_skill: dict[str, list] = {}
|
|
3187
|
+
for m in rows:
|
|
3188
|
+
try:
|
|
3189
|
+
if int(m.get("created") or 0) < cutoff:
|
|
3190
|
+
continue
|
|
3191
|
+
except (TypeError, ValueError):
|
|
3192
|
+
continue
|
|
3193
|
+
for name in _skill_tags_of(m):
|
|
3194
|
+
by_skill.setdefault(name, []).append(m)
|
|
3195
|
+
|
|
3196
|
+
stamp = time.strftime("%Y-%m-%d")
|
|
3197
|
+
out, total = [], 0
|
|
3198
|
+
for name, mems in sorted(by_skill.items()):
|
|
3199
|
+
if len(mems) < TIPS_MIN_MEMORIES:
|
|
3200
|
+
continue
|
|
3201
|
+
d = _skill_dir_of(name)
|
|
3202
|
+
if d is None:
|
|
3203
|
+
out.append({"name": name, "memories": len(mems), "tips": 0,
|
|
3204
|
+
"written": 0, "path": "", "skipped": "技能目录不存在"})
|
|
3205
|
+
continue
|
|
3206
|
+
# 优先 mistake / correction(那才是"坑"),再补其它,最多 5 条
|
|
3207
|
+
ranked = sorted(mems, key=lambda m: (0 if str(m.get("kind")) in ("mistake", "correction") else 1,
|
|
3208
|
+
-_num(m.get("importance"), 0.5)))
|
|
3209
|
+
lines = [_tip_line(m) for m in ranked[:5]]
|
|
3210
|
+
lines = [ln for ln in lines if ln]
|
|
3211
|
+
written = 0 if dry_run else _tips_append(d, lines, stamp)
|
|
3212
|
+
total += written
|
|
3213
|
+
out.append({"name": name, "memories": len(mems), "tips": len(lines),
|
|
3214
|
+
"written": written, "path": str(d / TIPS_FILENAME)})
|
|
3215
|
+
return {"ok": True, "skills": out, "total_written": total,
|
|
3216
|
+
"scanned": len(rows), "days": days, "dry_run": bool(dry_run)}
|
|
3217
|
+
|
|
3218
|
+
|
|
3080
3219
|
def self_review(force: bool = False, days: int = 3) -> dict:
|
|
3081
3220
|
cfg = brain.load_config()
|
|
3082
3221
|
now = brain.now_ts()
|
|
@@ -3138,7 +3277,14 @@ def self_review(force: bool = False, days: int = 3) -> dict:
|
|
|
3138
3277
|
saved = True
|
|
3139
3278
|
except OSError:
|
|
3140
3279
|
saved = False
|
|
3141
|
-
|
|
3280
|
+
# P2-2 技能自我进化:把这一轮的"踩坑经验"回灌到对应技能旁边。
|
|
3281
|
+
# 整段兜住——回灌失败绝不能让自我总结挂掉。
|
|
3282
|
+
try:
|
|
3283
|
+
_evolve = skill_evolve(days=max(2, days))
|
|
3284
|
+
except Exception as _exc: # noqa: BLE001
|
|
3285
|
+
_evolve = {"ok": False, "error": str(_exc), "total_written": 0}
|
|
3286
|
+
return {
|
|
3287
|
+
"skill_evolve": _evolve,"due": True, "last": last, "days": days, "summary": summary, "saved": saved}
|
|
3142
3288
|
|
|
3143
3289
|
|
|
3144
3290
|
def _readonly() -> bool:
|
package/scripts/memory.py
CHANGED
|
@@ -992,7 +992,8 @@ def boost(memory_id: str) -> dict:
|
|
|
992
992
|
# ---------------------------------------------------------------- 情绪驱动的记忆权重(P2-3)
|
|
993
993
|
# 「记仇」效应:让用户委屈/生气的事更重、更容易被想起。这不是玄学——
|
|
994
994
|
# 情绪记忆的巩固强度本来就高于中性记忆(amygdala 调制,McGaugh 2004)。
|
|
995
|
-
EMO_TOUCH_FIELD = "_touched_by_emotion" #
|
|
995
|
+
EMO_TOUCH_FIELD = "_touched_by_emotion" # 历次情绪**强度**(供 recall 加成)
|
|
996
|
+
EMO_TOTAL_FIELD = "_emo_touch_total" # 累计**已加到 importance 的增量**(配额)
|
|
996
997
|
EMO_TOUCH_STEP = 0.06 # 每次负面情绪给 importance 的增量
|
|
997
998
|
EMO_TOUCH_MAX = 0.30 # 累计增量上限(防一条被反复顶到 1.0)
|
|
998
999
|
EMO_TOUCH_NEG_MAX_VALENCE = -0.3 # 只对 valence < 这个值(够负面)生效
|
|
@@ -1018,6 +1019,10 @@ def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
|
1018
1019
|
return {"ok": True, "changed": False, "reason": "情绪太弱(intensity 低于阈值)"}
|
|
1019
1020
|
if READONLY:
|
|
1020
1021
|
return {"ok": False, "changed": False, "reason": "记忆库只读"}
|
|
1022
|
+
# 调用方可能传完整记录字典(capture() 的 saved 就是记录列表)——宽松取 id,
|
|
1023
|
+
# 别把一个 dict 的 repr 当 id 去查(实测踩过)。
|
|
1024
|
+
if isinstance(memory_id, dict):
|
|
1025
|
+
memory_id = memory_id.get("id")
|
|
1021
1026
|
mid = str(memory_id or "").strip()
|
|
1022
1027
|
if not mid:
|
|
1023
1028
|
return {"ok": False, "changed": False, "reason": "没有 memory_id"}
|
|
@@ -1027,8 +1032,9 @@ def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
|
1027
1032
|
if found is None:
|
|
1028
1033
|
return {"ok": False, "changed": False, "reason": f"找不到记忆 {mid}"}
|
|
1029
1034
|
marks = list(found.get(EMO_TOUCH_FIELD) or [])
|
|
1030
|
-
|
|
1031
|
-
#
|
|
1035
|
+
# 配额看"已加了多少 importance",**不是**看情绪强度——
|
|
1036
|
+
# 两者量纲不同(0.06 vs 0.9),混用会让第一次就判超限(实测踩过)。
|
|
1037
|
+
used = _num(found.get(EMO_TOTAL_FIELD), 0.0)
|
|
1032
1038
|
room = max(0.0, EMO_TOUCH_MAX - used)
|
|
1033
1039
|
delta = min(EMO_TOUCH_STEP, room)
|
|
1034
1040
|
if delta <= 0:
|
|
@@ -1039,6 +1045,7 @@ def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
|
1039
1045
|
# 记下本次影响(限长,避免字段无界增长)
|
|
1040
1046
|
marks.append(round(abs(v) * max(0.0, min(1.0, i)), 3))
|
|
1041
1047
|
found[EMO_TOUCH_FIELD] = marks[-20:]
|
|
1048
|
+
found[EMO_TOTAL_FIELD] = round(used + delta, 3)
|
|
1042
1049
|
save_all(records)
|
|
1043
1050
|
try:
|
|
1044
1051
|
log_event("emotion", f"情绪加权 {mid}:importance {old:.2f} → "
|
|
@@ -1046,7 +1053,8 @@ def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
|
1046
1053
|
except Exception: # noqa: BLE001
|
|
1047
1054
|
pass
|
|
1048
1055
|
return {"ok": True, "changed": True, "importance": found["importance"],
|
|
1049
|
-
"delta": round(delta, 3)
|
|
1056
|
+
"delta": round(delta, 3),
|
|
1057
|
+
"total": found.get(EMO_TOTAL_FIELD, round(delta, 3))}
|
|
1050
1058
|
|
|
1051
1059
|
|
|
1052
1060
|
def _emo_boost_of(m: dict) -> float:
|