lingshu-skill 5.10.0 → 5.14.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.
Files changed (28) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +69 -3
  3. package/SKILL.md +3 -1
  4. package/assets/panel.html +133 -7
  5. package/docs//345/200/237/351/211/264/345/276/205/345/212/236-DSH/346/217/222/344/273/266/347/224/237/346/200/201.md +224 -0
  6. package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +26 -1
  7. package/package.json +1 -1
  8. package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +12 -12
  9. package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +120 -0
  10. package/scripts/astrbot_plugin_lingshu/engine/README.md +69 -3
  11. package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +3 -1
  12. package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +133 -7
  13. package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +49 -3
  14. package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +7 -0
  15. package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +75 -1
  16. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +5055 -4759
  17. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +305 -16
  18. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +131 -7
  19. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +6 -0
  20. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_update.py +38 -9
  21. package/scripts/cli.py +49 -3
  22. package/scripts/core.py +7 -0
  23. package/scripts/emotion.py +75 -1
  24. package/scripts/growth.py +5055 -4759
  25. package/scripts/memory.py +305 -16
  26. package/scripts/panel_server.py +131 -7
  27. package/scripts/panel_settings.py +6 -0
  28. package/scripts/panel_update.py +38 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,125 @@
1
1
  # 更新日志
2
2
 
3
+ ## v5.14(2026-11-25)
4
+
5
+ > 主题:**索引法记忆(P1-1)**——正文不进上下文,记忆段注入量降 **47.5%**。
6
+
7
+ ### 新:每条记忆带一个"一句索引"
8
+
9
+ - `make_record()` 自动生成 `index`(≤26 字,纯规则**不调 LLM**):优先落在**句子/分句边界**,
10
+ 而不是切在半句;顺带剥掉 `user:`/`assistant:` 这类角色前缀(索引里留着只是噪音)。
11
+ - 注入时只送 `- [日期 ★★★]索引(8 位短id)`,正文用 `memory show <短id>` 取。
12
+
13
+ ### 新:`memory show <id>`——按 id 取整条记忆
14
+
15
+ **这补的是一个既有缺口**:以前注入提示写着"正文用 `dereference <id>` 取",但
16
+ `dereference` 只返回 **evidence_ids 指向的证据原文**,普通记忆一律返回 `[]`——照做会拿到空。
17
+ 现在:
18
+ - 新增 `memory.fetch(id)` + `memory show <id>`(支持**唯一前缀**:完整 id / hash 段 8 位 / `m_` 短号);
19
+ - `dereference` 在没有证据指针时**回退返回自身**(标 `_self`),不再返回空;
20
+ - 注入段头提示改成正确的 `memory show <短id>`。
21
+
22
+ ### 新:`use_index_memory` 三档(默认 auto)
23
+
24
+ | 档 | 行为 |
25
+ |---|---|
26
+ | `auto`(默认) | **水位 ≥60% 或已在 lazy/minimal 档**才切索引;水位低时仍给全文——降水位只作用在真正紧张处 |
27
+ | `always` | 一律指针(最省) |
28
+ | `off` | 回到旧行为 |
29
+
30
+ 设置页「注入与预算」组可改。
31
+
32
+ ### 实测(真实库,6 个场景)
33
+
34
+ | 场景 | 记忆段 off | 记忆段 on | 降幅 |
35
+ |---|---|---|---|
36
+ | startup | 769 | 519 | 32.5% |
37
+ | 备份 删除 | 2096 | 1061 | 49.4% |
38
+ | 面板 更新 | 2137 | 1059 | 50.4% |
39
+ | 记忆 注入 | 1576 | 883 | 44.0% |
40
+ | python 解释器 | 2140 | 1025 | 52.1% |
41
+ | 打开 面板 报错 | 2114 | 1141 | 46.0% |
42
+ | **合计** | **10832** | **5688** | **47.5%** |
43
+
44
+ 全包降 26.4%(人设/规则等固定段不随模式变)。**验收线 40% → 达标。**
45
+
46
+ ### 顺带修:小记忆段里提示行是负优化
47
+
48
+ 指针提示行约 45 字符,每条指针省约 25 字符——**少于 3 条指针时净增**。
49
+ 现在 `_pointer_n >= 3` 才加提示(老代码注释里记过这个坑,这次用门槛治掉)。
50
+
51
+ 验证:`tests/test_p25_index_memory.py` 7/7(索引质量/边界/剥前缀、fetch 前缀解析、
52
+ deref 回退、**索引行比全文行短 ≥40%**、auto 档按水位切换、off 档不切、提示门槛)。
53
+
54
+ ## v5.13(2026-11-25)
55
+
56
+ > 主题:**灵枢开始"自己看自己"**——三条借鉴 DSH 插件生态的新能力落地。
57
+ > 参考文档:[借鉴待办-DSH插件生态.md](docs/借鉴待办-DSH插件生态.md)
58
+
59
+ ### 新:内心独白(灵枢自语)
60
+
61
+ - **借鉴**:dsh-agent-personality 的 inner-voice——token 计费旁的人格态度小字。
62
+ - **实现**:`scripts/emotion.py` 新增 `inner_voice()`(≤30 字、纯模板+词表、不调 LLM);`scripts/panel_server.py` overview 接口加 `inner_voice` 字段;面板侧栏 footer 新增"灵枢自语"一行(灰色斜体小字,storm=True → "有点上头"、suppress≥20 → "理智被压住"、否则按 valence+intensity 挑模板)。
63
+ - **无配置项**,默认开;无情绪记录返回空字符串,前端自动隐藏。
64
+
65
+ ### 新:心情时间线(心情流水)
66
+
67
+ - **借鉴**:dsh-feiyu-mood 的心情时间线面板。
68
+ - **实现**:`scripts/emotion.py` 新增 `emotion_timeline()`(取最近 50 条 genesis=True 的情绪事件,每条带时间/标签/强度/分类/why);面板 emotion 页签底部新增"心情流水"区——横向小 chip(按七情配色),hover 显示强度+关于+原因+时间。
69
+ - **为什么只取 genesis=True**:手动 `emotion feel` 算主动触发不算流水;只有自动生成、共情、认知评价才是真实情绪流露。
70
+
71
+ ### 新:体检历史 + 灵枢健康度
72
+
73
+ - **借鉴**:dsh-pet-evolve 的"XP 从真实 agent 信号获取"。
74
+ - **实现**:
75
+ - `scripts/cli.py` doctor 分支全部 checks 跑完后,自动追加一条到 `<HOME>/doctor-history.jsonl`(ts + fails/warns/passes + 13 项逐条状态);
76
+ - `scripts/panel_server.py` 新增 `_doctor_history(days=30)` 按天聚合 PASS/WARN/FAIL 分布、`_health_score()` 按最近 7 天 doctor FAIL×10 + WARN×3 + failures.jsonl 条数×1 从 100 往下扣(下限 0);
77
+ - 面板 diag 页签新增"灵枢体检历史"card——纯 CSS 堆叠 bar chart(每列一条,绿=PASS / 黄=WARN / 红=FAIL,按总跑次比例缩放,tooltip 显示具体数字);侧栏 footer 新增"灵枢健康度 N/100",<60 红、<80 黄。
78
+ - **append-only**:doctor-history.jsonl 只追加、不回写、不压缩,单条 try/except 吞掉——未来可以很容易加"最近 30 天 doctor 成功率"、"哪项 check 最常 FAIL"等衍生指标。
79
+
80
+ ### 杂项
81
+
82
+ - **P0-3 测试文件入库**:`.gitignore` 本来就不拦 `tests/`(第 58 行甚至写"测试脚本进仓库")。v3.55-56 期间的临时决定("测试文件不入库")已撤销——v5.13 起恢复。
83
+
84
+ 验证:全量测试 79/80 通过(1 条 `test_p24_update_npm.py` 是 npm registry 联网偶发、与本次改动无关);五项发布检查全绿;面板构建 329234 B;`emotion.inner_voice()` 直接 import 测试 → storm 分支正确返回"情绪有点炸,先别急着下结论"。
85
+
86
+ ## v5.12(2026-11-24)
87
+
88
+ > 主题:**更新按钮不再"死"**——从仓库跑面板时也能看到 npm 上的新版本。
89
+
90
+ ### 修:dev 模式下更新按钮永远"已是最新"
91
+
92
+ - **原因**:`update_check` 只比「源 vs 已装全局副本」。而面板可以直接从仓库跑(桌面快捷方式指向仓库的 `panel_launcher.py`),此时仓库即源、很多人又没装全局副本 → `installed=False` → **更新按钮永远是死按钮**。
93
+ - **修**:dev 模式(含 dev+未装副本的早退分支)额外查 **npm 最新版**并与之比较:npm 更新就报 `outdated=True`,标题显示「仓库 vX → npm vY」,并透出 `npm` 版本与解包体积(面板弹窗会显示「npm 最新 vX,解包约 N KB」)。
94
+
95
+ ### 修:`5.11` 与 `5.11.0` 被误判成"有更新"
96
+
97
+ - Python 元组比较 `(5, 11, 0) > (5, 11)` 为 **True**,于是仓库 5.11 对 npm 5.11.0 误报有更新。
98
+ - **修**:`_ver_tuple` 与 dev 比较都**补零到定长三段**再比。实测:`5.11 vs 5.11.0 → False`、`5.10 vs 5.11.0 → True`。
99
+
100
+ 验证:`tests/test_p24_update_npm.py` **10/10**(新增版本补零、dev 与 npm 比较两条)。
101
+
102
+ ## v5.11(2026-11-24)
103
+
104
+ > 主题:**更新按钮支持 npm 下载** + 修掉「自动更新永不触发」。
105
+
106
+ ### 新:npm 作为首选下载源
107
+
108
+ - **零依赖实现**(`urllib` + `tarfile`,不需要 npm CLI):查 registry → 下 tarball → **校验 `dist.shasum`(sha1)** → 解包。
109
+ - **安全边界**:只取 `package/` 前缀、**逐条拒绝 `../` 路径穿越**、**跳过符号/硬链接**、包体上限 60 MB。
110
+ - **源优先级**:`dev` → **npm** → Gitee → GitHub → 已装副本。新配置 `update_source`(`auto` 默认 / `npm` / `git`),设置页可改。
111
+ - `resolve_source(..., prefer="npm")`:显式指定时**跳过 dev**,否则开发仓库里永远被 dev 抢先。
112
+ - **面板**:更新弹窗新增「下载源」下拉(跟随设置 / npm 官方包 / Gitee·GitHub,**记住上次选择**)+ 显示「npm 最新 vX,解包约 N KB」;确认框说清走哪条路。
113
+ - **CLI**:`auto-update --source auto|npm|git`。
114
+
115
+ ### 修:自动更新其实一直没生效
116
+
117
+ - `panel_update.run()` 判断 `chk["update_available"]`,而 `growth.update_check()` 返回的字段叫 **`outdated`** —— 于是 CLI / cron 的自动更新**永远**走"已是最新"分支,**从不真正更新**。
118
+ - 修:`panel_update.check()` 做字段归一化(补 `update_available` / `current` / `latest`);CLI 的 `--check` 也从"当前 None / 最新 None"变成显示真实版本。
119
+ - **缓存一致性**:更新缓存记 `source`,切换下载源后旧缓存自动作废。
120
+
121
+ 验证:`tests/test_p24_update_npm.py` 8/8(含**路径穿越拒绝**、符号链接跳过、`prefer=npm` 跳过 dev、**npm 目录必须在 brain.HOME 内**、切源作废缓存);接口实测 `?source=npm` → `source_kind=npm` + npm 版本体积,`auto=1` 0.00 秒离线返回。
122
+
3
123
  ## v5.10(2026-11-24)
4
124
 
5
125
  > 主题:**面板全量体检**——16 页签 / 86 接口 / 联动全查,修三处,并固化成回归测试。
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
4
4
 
5
- > 当前版本 **v5.10**(变更见 [CHANGELOG.md](CHANGELOG.md))
5
+ > 当前版本 **v5.14**(变更见 [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
 
@@ -26,6 +26,7 @@
26
26
  - [审核闸:AI 产物先过目,AI 自己审](#审核闸ai-产物先过目ai-自己审)
27
27
  - [开工前先查(prior)](#开工前先查prior)
28
28
  - [错卦:召回区分否定](#错卦召回区分否定)
29
+ - [索引法记忆:正文不进上下文](#索引法记忆正文不进上下文)
29
30
  - [六爻位体检(shape-audit)](#六爻位体检shape-audit)
30
31
  - [模糊联想回忆](#模糊联想回忆)
31
32
  - [记忆关联(联想图谱)](#记忆关联联想图谱)
@@ -339,6 +340,49 @@ python scripts/brain.py prior "要做的事 / 要查的问题"
339
340
 
340
341
  ---
341
342
 
343
+ ## 索引法记忆:正文不进上下文
344
+
345
+ 上下文里最贵的是记忆正文。索引法给每条记忆配一句 **≤26 字的索引**——纯规则生成
346
+ (不调模型、不花 token),**落在句子/分句边界**,不会切在半句;顺带剥掉
347
+ `user:`/`assistant:` 这类角色前缀。
348
+
349
+ 注入时只送 `- [日期 ★★★]索引(8 位短id)`,正文按需再取:
350
+
351
+ ```bash
352
+ python scripts/brain.py memory show 7f3ca9ac # 短 id 直接取整条记忆(支持唯一前缀)
353
+ ```
354
+
355
+ | 档(`use_index_memory`) | 行为 |
356
+ |---|---|
357
+ | `auto`(默认) | 水位 **≥60%** 或已在 lazy/minimal 档才切;水位低时仍给全文 |
358
+ | `always` | 一律指针(最省) |
359
+ | `off` | 旧行为 |
360
+
361
+ **实测降幅(真实库 6 个场景,记忆段)**:
362
+
363
+ | 场景 | off | on | 降幅 |
364
+ |---|---|---|---|
365
+ | startup | 769 | 519 | 32.5% |
366
+ | 备份 删除 | 2096 | 1061 | 49.4% |
367
+ | 面板 更新 | 2137 | 1059 | 50.4% |
368
+ | 记忆 注入 | 1576 | 883 | 44.0% |
369
+ | python 解释器 | 2140 | 1025 | 52.1% |
370
+ | 打开 面板 报错 | 2114 | 1141 | 46.0% |
371
+ | **合计** | **10832** | **5688** | **47.5%** |
372
+
373
+ 全包降 26.4%——人设/规则等固定段不随模式变,所以全包降幅必然小于记忆段降幅。
374
+
375
+ **指针行的三种形态**(清楚与省钱兼顾):
376
+
377
+ - 指针 **≥3 条** → 段头加一次提示(讲清 `memory show` 怎么用),行内用紧凑形 `(7f3ca9ac)`
378
+ - 指针 **1~2 条** → 不加提示,行内自解释 `(id:7f3ca9ac,memory show 取)`
379
+ ——只有一两条时,几十字符的提示说不动收益,清楚更重要
380
+ - 没有指针 → 不涉及
381
+
382
+ > 顺带补了个**既有缺口**:注入提示以前让模型用 `dereference <id>` 取正文,但
383
+ > `dereference` 只返回 **evidence_ids 指向的证据原文**,普通记忆一律返回空——照做拿不到东西。
384
+ > 现在 `dereference` 在无证据指针时**回退返回自身**,并且新增了正路 `memory show <短id>`。
385
+
342
386
  ## 六爻位体检(shape-audit)
343
387
 
344
388
  借《易经》的**64 格状态空间**做数据健康度体检——**纯只读**。
@@ -794,7 +838,7 @@ python scripts/brain.py doctor # 看 desktop-shortcut 一项是否
794
838
  **默认关**(自动改自己的代码风险高,必须显式开启):`config.auto_update` + 面板「设置」页开关。
795
839
 
796
840
  ```bash
797
- python scripts/brain.py auto-update [--check] [--force]
841
+ python scripts/brain.py auto-update [--check] [--force] [--source auto|npm|git]
798
842
  ```
799
843
 
800
844
  执行顺序是**死的**,任一步失败都不留半新半旧:
@@ -802,10 +846,32 @@ python scripts/brain.py auto-update [--check] [--force]
802
846
  ```
803
847
  ① 查有没有新版(没有就跳过)
804
848
  ② 先备份记忆库 —— 备份失败就中止(宁可旧代码,不能丢记忆)
805
- ③ growth.apply_update 原子替换(SHA256 校验 / 全量备份 / 回滚兜底)
849
+ ③ 下载源解析 → 原子替换(SHA256 校验 / 全量备份 / 回滚兜底)
806
850
  ④ 写审计日志
807
851
  ```
808
852
 
853
+ ### 下载源:npm 优先,Gitee/GitHub 兜底
854
+
855
+ 面板「检查更新」弹窗里可以选**下载源**,也可以改设置页的「更新下载源」:
856
+
857
+ | 源 | 说明 |
858
+ |---|---|
859
+ | **npm**(默认优先) | 官方发布渠道 `npm i lingshu-skill`。CDN 快、有版本号、有 **shasum(sha1)可校验**;比 Gitee/GitHub 的 zip 下载稳(后者受匿名限额与网络波动影响) |
860
+ | **Gitee / GitHub** | 仓库 zip 兜底。npm 不可用时自动回退 |
861
+ | **跟随设置** | 默认 `update_source=auto`:先 npm,失败再 Gitee/GitHub |
862
+
863
+ **零依赖实现**:`urllib` 取 registry 元数据 → 下 tarball → 校验 sha1 → `tarfile` 解包(只取 `package/` 前缀、**逐条拒绝 `../` 路径穿越与符号链接**)。不需要装 npm CLI。
864
+
865
+ **切换源即作废缓存**:检查结果缓存里记了来源,把 `update_source` 从 git 改成 npm 后,
866
+ 旧的 git 结论不会冒充"已是最新"。
867
+
868
+ ### 修掉一个"功能等于没接上"的 bug
869
+
870
+ `panel_update.run()` 判断的是 `chk["update_available"]`,而 `growth.update_check()` 返回的字段叫
871
+ **`outdated`** —— 于是 CLI / cron 的自动更新**永远**走"已是最新"分支,从不真正更新。
872
+ 现在 `panel_update.check()` 做字段归一化(补 `update_available` / `current` / `latest`),
873
+ 并在 `tests/test_p24_update_npm.py` 里钉死。
874
+
809
875
  ## 多群/多会话:通道三元组(v2.34)
810
876
 
811
877
  当灵枢同时服务多个群聊 / 多个会话时,记忆默认混在一起会串台。v2.34 引入**通道三元组**(channel / group_id / user)做记忆隔离与跨群共享:
package/SKILL.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: lingshu
3
3
  title: 灵枢
4
- version: 5.10
4
+ version: 5.14
5
5
  description: 类脑持久记忆、人格与成长系统——跨会话记住事情、长出自己的人格、上下文将满时做梦式整理记忆。用户提到记忆/记住/上次/人格/设定/性格/知识库/笔记/日志/成长/自我进化/工作记忆,或新会话开始需要恢复关系与上下文时使用。纯本地零依赖。
6
6
  ---
7
7
 
@@ -380,6 +380,8 @@ python scripts/bench.py [--n 1000|--quick] # 性能基准:隔离临
380
380
  | 想立刻关 | 面板「设置」页 → **「退出服务」** |
381
381
  | 连点两次 | 安全:启动器先探测,**已在跑就只把浏览器叫回来**,不会起第二个 |
382
382
  | **桌面快捷方式丢了** | `python scripts/brain.py shortcut --ensure`(幂等:缺了就重建,已有就不动) |
383
+ | 取一条记忆的正文 | `python scripts/brain.py memory show <短id>`(注入里的 8 位短号直接用,也认完整 id 前缀) |
384
+ | 更新灵枢本体 | 面板「检查更新」弹窗(可选下载源:**npm 官方包** / Gitee·GitHub / 跟随设置),或 `python scripts/brain.py auto-update --source npm`;`update_source` 默认 auto=npm 优先 |
383
385
 
384
386
  **用户说"面板打不开了 / 桌面那个图标没了"时**,直接跑上面那条 `shortcut --ensure`,
385
387
  再 `python scripts/brain.py doctor` 看 `desktop-shortcut` 一项是否转 PASS。
package/assets/panel.html CHANGED
@@ -679,6 +679,11 @@
679
679
  <button class="btn" id="btn-emo-feel">记下</button>
680
680
  </div>
681
681
  <div class="sub" id="emo-arc" style="margin-top:12px"></div>
682
+ <!-- v5.12 心情时间线:每轮自动生成的情绪事件流水(genesis=True) -->
683
+ <div style="margin-top:10px">
684
+ <div class="sub" style="margin-bottom:4px">心情流水(最近 50 条自动记录,hover 看强度)</div>
685
+ <div id="emo-timeline" style="display:flex;flex-wrap:wrap;gap:6px;max-height:180px;overflow-y:auto;padding:6px 4px;border:1px dashed rgba(200,200,200,.25);border-radius:6px"></div>
686
+ </div>
682
687
  </div>
683
688
  <div class="card">
684
689
  <h2>六欲</h2>
@@ -951,6 +956,13 @@
951
956
  <div id="diag-body" style="margin-top:10px"><div class="empty">加载中…</div></div>
952
957
  </div>
953
958
 
959
+ <!-- v5.12 体检历史:灵枢自己的成长账本(doctor 每跑一次追加一条,按天聚合) -->
960
+ <div class="card" style="margin-bottom:14px">
961
+ <h2 style="margin-bottom:4px">灵枢体检历史(近 30 天)</h2>
962
+ <div class="sub">doctor 每跑一次就存一条,按天汇总 PASS / WARN / FAIL。红柱越高越糟;绿柱越高越好。</div>
963
+ <div id="doctor-history" style="margin-top:10px"></div>
964
+ </div>
965
+
954
966
  <!-- 数据目录(查看 / 迁移) -->
955
967
  <div class="card" style="margin-bottom:14px">
956
968
  <div class="row" style="flex-wrap:wrap">
@@ -1170,6 +1182,16 @@ const progress = topProgress();
1170
1182
  <button class="btn hidden" id="upd-dsh-force" style="background:#b03030">强制更新 DSH 副本</button>
1171
1183
  </div>
1172
1184
  </div>
1185
+ <div class="row" id="upd-src-row" style="margin-top:14px;align-items:center;gap:10px;display:none">
1186
+ <span class="sub" style="margin:0">下载源</span>
1187
+ <select id="upd-source" style="padding:5px 9px;border-radius:8px;border:1px solid var(--line);
1188
+ background:var(--surface);color:var(--text)">
1189
+ <option value="auto">跟随设置(npm 优先)</option>
1190
+ <option value="npm">npm 官方包</option>
1191
+ <option value="git">Gitee / GitHub</option>
1192
+ </select>
1193
+ <span class="sub" id="upd-npm-info" style="margin:0"></span>
1194
+ </div>
1173
1195
  <div class="row" style="margin-top:16px">
1174
1196
  <button class="ghost" id="upd-close">关闭</button>
1175
1197
  <button class="btn hidden" id="upd-apply">立即更新</button>
@@ -1402,6 +1424,10 @@ function renderOverview(){
1402
1424
  + (ov.source && ov.source.version ? `<br><br><b>代码版本</b><br>v${esc(ov.source.version)}<br><span style="font-size:10px">${esc(ov.source.script_dir || "")}</span>` : "")
1403
1425
  + `<br><br><b>模型档位</b><br>${esc(tierLabel(ov.model_tier))}`
1404
1426
  + `<br><br><b>会话模式</b><br>${esc(modeLabel(ov.mode))} <a href="javascript:void 0" data-mode-cycle style="color:var(--amber)">切换</a>`
1427
+ // v5.12 内心独白:灵枢此刻对自己的简短态度评价(纯模板,LLM-free)
1428
+ + (ov.inner_voice ? `<br><br><b style="font-style:italic;color:var(--sub)">灵枢自语</b><br><span style="font-style:italic;color:var(--sub);font-size:11px;opacity:.85">${esc(ov.inner_voice)}</span>` : "")
1429
+ // v5.12 灵枢健康度:0-100,按最近 7 天 doctor FAIL/WARN + failures.jsonl 条数加权扣分
1430
+ + (typeof ov.health_score === "number" ? `<br><br><b>灵枢健康度</b><br>${ov.health_score} / 100${ov.health_score < 60 ? ` <b style="color:var(--red)">偏低</b>` : ov.health_score < 80 ? ` <b style="color:var(--amber)">一般</b>` : ""}` : "")
1405
1431
  + (rcTotal ? `<br><br><b style="color:#e66450">待审核 ${rcTotal} 项</b><br>记忆 ${rc.memories || 0} · 知识 ${rc.knowledge || 0} · 人格 ${rc.persona || 0}` : "")
1406
1432
  + ((ov.persona_drift && ov.persona_drift.alert) ? `<br><br><b style="color:#e66450">人格漂移偏大</b><br><a href="#" data-goto="persona" style="color:var(--amber)">去人格页查看/回滚 →</a>` : "")
1407
1433
  + (ov.readonly ? `<br><b style="color:var(--red)">只读模式</b>` : "")
@@ -1601,6 +1627,52 @@ function renderMood(){
1601
1627
  : `<div class="empty">没有正在起作用的情绪</div>`;
1602
1628
  }
1603
1629
  renderDesires(ov);
1630
+ // v5.12 心情时间线:每轮自动生成的情绪事件流水
1631
+ const tlEl = $("emo-timeline");
1632
+ if (tlEl) {
1633
+ const tl = ov.emotion_timeline || [];
1634
+ if (!tl.length) {
1635
+ tlEl.innerHTML = `<span class="sub" style="opacity:.6">还没有自动情绪记录——通常 extract / 共情 / 认知评价会自动产生</span>`;
1636
+ } else {
1637
+ tlEl.innerHTML = tl.map(r => {
1638
+ const color = moodColor({ category: r.category, intensity: r.intensity });
1639
+ const title = `${r.label} · 强度 ${Math.round((r.intensity || 0) * 100)}%${r.about ? " · 关于 " + r.about : ""}${r.why ? " — " + r.why : ""} · ${r.time}`;
1640
+ return `<span class="chip" style="background:${color};border-color:${color};color:#fff;cursor:help" title="${esc(title)}">${esc(r.label)}</span>`;
1641
+ }).join("");
1642
+ }
1643
+ }
1644
+ }
1645
+
1646
+ // v5.12 体检历史(doctor-history.jsonl):按天聚合的 PASS/WARN/FAIL 分布,纯 CSS 堆叠条
1647
+ function renderDoctorHistory(){
1648
+ const el = $("doctor-history"); if (!el) return;
1649
+ const ov = S.ov; if (!ov) { el.innerHTML = `<div class="empty">切到「概览」再回来看(数据在 overview 接口里)</div>`; return; }
1650
+ const hist = ov.doctor_history || [];
1651
+ if (!hist.length) {
1652
+ el.innerHTML = `<div class="empty">还没跑过 doctor(跑一次「python scripts/brain.py doctor」之后会自动追加一条)</div>`;
1653
+ return;
1654
+ }
1655
+ const maxTotal = Math.max(...hist.map(d => d.total));
1656
+ el.innerHTML = `<div style="display:flex;align-items:flex-end;gap:6px;height:80px;margin-top:6px;padding:0 4px">`
1657
+ + hist.map(d => {
1658
+ const h = Math.max(2, Math.round((d.total / maxTotal) * 70));
1659
+ const fh = Math.round((d.fails / maxTotal) * 70);
1660
+ const wh = Math.round((d.warns / maxTotal) * 70);
1661
+ const ph = h - fh - wh;
1662
+ const tooltip = `${d.date} · PASS ${d.passes} / WARN ${d.warns} / FAIL ${d.fails}`;
1663
+ return `<div style="flex:1;min-width:18px;display:flex;flex-direction:column-reverse;height:${h}px;gap:1px" title="${esc(tooltip)}">`
1664
+ + `<div style="flex:${ph};background:rgba(120,180,120,.85);min-height:0;border-radius:2px 2px 0 0"></div>`
1665
+ + (d.warns ? `<div style="height:${wh}px;background:rgba(220,180,80,.85);min-height:1px;border-radius:1px"></div>` : "")
1666
+ + (d.fails ? `<div style="height:${fh}px;background:rgba(210,100,90,.85);min-height:1px;border-radius:1px"></div>` : "")
1667
+ + `</div>`;
1668
+ }).join("")
1669
+ + `</div>`
1670
+ + `<div style="display:flex;gap:6px;font-size:10px;color:var(--sub);margin-top:4px">`
1671
+ + `<span style="color:rgba(120,180,120,.85)">■</span>PASS `
1672
+ + `<span style="color:rgba(220,180,80,.85)">■</span>WARN `
1673
+ + `<span style="color:rgba(210,100,90,.85)">■</span>FAIL `
1674
+ + `<span style="margin-left:auto">共 ${hist.length} 天 · ${hist.reduce((s,d)=>s+d.total,0)} 次</span>`
1675
+ + `</div>`;
1604
1676
  }
1605
1677
 
1606
1678
  function renderDesires(ov){
@@ -3188,7 +3260,7 @@ function switchTab(tab){
3188
3260
  if (tab === "logs") loadLogs();
3189
3261
  // 诊断页有两张随时间变化的卡:体检结果 + 数据目录位置,进页面时一起刷(以前只刷体检,
3190
3262
  // 数据目录卡靠一段 class 判断写错的 MutationObserver,永远停在「加载中…」)
3191
- if (tab === "diag") { loadDiagnostics(); loadHomeInfo(); }
3263
+ if (tab === "diag") { loadDiagnostics(); loadHomeInfo(); renderDoctorHistory(); }
3192
3264
  if (tab === "persona") { loadSnapshots(); loadPersonaSuggest(); } // 切到人格页时顺手刷快照列表与画像归纳建议
3193
3265
  // 概览/心情/梦 三页的数据都在 overview 里(心情与六欲是按时间衰减的活数值)。
3194
3266
  // 以前只靠 30 秒轮询 + document.hidden 跳过,切过去可能看到最多 30 秒前的旧值。
@@ -4796,7 +4868,9 @@ async function checkUpdate(auto){
4796
4868
  dot.style.display = "inline-block";
4797
4869
  // auto 模式只点亮红点不弹窗:自动检查的本意是"不打扰",弹窗会打断用户手头操作
4798
4870
  if (auto) return;
4799
- const srcLabel = r.source_kind === "dev" ? "来源:本地开发仓库"
4871
+ const srcLabel = r.source_kind === "npm" || r.source === "npm"
4872
+ ? "来源:npm 官方包" + (r.npm && r.npm.version ? "(v" + r.npm.version + ")" : "")
4873
+ : r.source_kind === "dev" ? "来源:本地开发仓库"
4800
4874
  : r.source_kind === "remote" ? "来源:Gitee 远程"
4801
4875
  : r.source === "gitee" ? "来源:Gitee 远程"
4802
4876
  : r.source === "github" ? "来源:GitHub 远程"
@@ -4860,6 +4934,42 @@ async function checkUpdate(auto){
4860
4934
  }
4861
4935
  function showUpdModal(title, detail, canApply){
4862
4936
  $("upd-title").textContent = title;
4937
+ // 有更新时才显示"下载源"选择:npm 官方包 vs Gitee/GitHub,各有所长
4938
+ const srcRow = $("upd-src-row");
4939
+ if (srcRow) srcRow.style.display = canApply ? "flex" : "none";
4940
+ // 记住上次选的下载源:用户特意选了 npm/git,下次不该又跳回"跟随设置"
4941
+ const sel = $("upd-source");
4942
+ if (sel && !sel.dataset.inited) {
4943
+ sel.dataset.inited = "1";
4944
+ try {
4945
+ const last = localStorage.getItem("ls-upd-source");
4946
+ if (last) sel.value = last;
4947
+ } catch (_) {}
4948
+ // 2026-11-25:切换下载源时重新查一次 update_check——换源就换说明,
4949
+ // 之前的 changelog / 版本号都是上一个源的,看了会误导用户。
4950
+ sel.addEventListener("change", () => {
4951
+ try { localStorage.setItem("ls-upd-source", sel.value); } catch (_) {}
4952
+ checkUpdate(false);
4953
+ });
4954
+ }
4955
+ const npmInfo = $("upd-npm-info");
4956
+ if (npmInfo) {
4957
+ const nm = updLastCheck && updLastCheck.npm;
4958
+ const ne = updLastCheck && updLastCheck.npm_error;
4959
+ if (nm && nm.version) {
4960
+ const kb = nm.unpacked ? ",解包约 " + Math.round(Number(nm.unpacked) / 1024) + " KB" : "";
4961
+ npmInfo.textContent = "npm 最新 v" + nm.version + kb + (nm.cached ? "(缓存)" : "");
4962
+ npmInfo.style.color = "";
4963
+ } else if (ne) {
4964
+ // 2026-11-25:dev 模式下 npm 版本查询失败(限流/网络/短暂挂掉),
4965
+ // 直接透传原因给用户——让他知道"npm 不是没有新版,是我暂时查不到"。
4966
+ npmInfo.textContent = "npm 版本查询失败:" + ne;
4967
+ npmInfo.style.color = "var(--red-text)";
4968
+ } else {
4969
+ npmInfo.textContent = "";
4970
+ npmInfo.style.color = "";
4971
+ }
4972
+ }
4863
4973
  $("upd-detail").innerHTML = String(detail).replace(/\n/g, "<br>");
4864
4974
  $("upd-detail").parentElement.style.maxHeight = "60vh"; // 更新说明可能很长,限高
4865
4975
  $("upd-detail").parentElement.style.overflowY = "auto";
@@ -4967,13 +5077,26 @@ $("upd-apply").addEventListener("click", async () => {
4967
5077
  updApplyBusy = true;
4968
5078
  try {
4969
5079
  // 更新前确认:明确标注来源类型与目标路径,杜绝"有更新但点了无响应"的疑虑
4970
- const kindTxt = updLastCheck.source_kind === "dev" ? "从本地开发仓库同步"
5080
+ // 用户在弹窗里选的下载源(auto=跟随设置)。显式选了就覆盖检查时的来源说明。
5081
+ const pickedSrc = ($("upd-source") && $("upd-source").value) || "auto";
5082
+ const kindTxt = pickedSrc === "npm" ? "从 npm 官方包更新"
5083
+ : pickedSrc === "git" ? "从 Gitee / GitHub 更新"
5084
+ : updLastCheck.source_kind === "npm" ? "从 npm 官方包更新(跟随设置)"
5085
+ : updLastCheck.source_kind === "dev" ? "从本地开发仓库同步"
4971
5086
  : updLastCheck.source_kind === "remote" || updLastCheck.source_kind === "gitee"
4972
5087
  || updLastCheck.source_kind === "github" ? "从远程仓库(Gitee/GitHub)更新"
4973
5088
  : "从已安装本地版本同步";
4974
5089
  const targetTxt = updLastCheck.target_path ? "\n\n目标路径:" + updLastCheck.target_path : "";
5090
+ // 2026-11-25:选了 npm 源但 npm 版本查询失败——可能是限流、网络抖动、npm 短暂挂掉。
5091
+ // 让用户明确知道"我查不到 npm 上是什么版本,但仍会强制从 npm 拉取",
5092
+ // 避免"查不到新版所以没点"或"点了更新发现版本号比预期旧"的困惑。
5093
+ let npmWarn = "";
5094
+ if ((pickedSrc === "npm" || pickedSrc === "auto") && updLastCheck.npm_error) {
5095
+ npmWarn = "\n\n⚠ 注意:npm 版本查询暂时失败(" + esc(updLastCheck.npm_error)
5096
+ + "),将直接拉取 npm 官方包最新版本。";
5097
+ }
4975
5098
  if (!confirm("确认更新灵枢本体到 " + (updLastCheck.source_version || updLastCheck.version ? "v" + (updLastCheck.source_version || updLastCheck.version) + " " : "")
4976
- + "?\n\n方式:" + kindTxt + targetTxt
5099
+ + "?\n\n方式:" + kindTxt + targetTxt + npmWarn
4977
5100
  + "\n\n(更新采用原子化部署:先备份再替换,失败自动回滚,记忆数据不受影响)")) return;
4978
5101
  btn.disabled = true;
4979
5102
  btn.classList.add("loading");
@@ -4985,7 +5108,8 @@ $("upd-apply").addEventListener("click", async () => {
4985
5108
  let r;
4986
5109
  try {
4987
5110
  r = await post("/api/skill", {action: "install", name: "lingshu",
4988
- force: true, yes: updRiskAccepted ? true : undefined},
5111
+ force: true, source: pickedSrc === "auto" ? undefined : pickedSrc,
5112
+ yes: updRiskAccepted ? true : undefined},
4989
5113
  {signal: AbortSignal.timeout(APPLY_TIMEOUT)});
4990
5114
  } catch (netErr) {
4991
5115
  // 网络层失败(超时/断连):给一次自动重试的机会——远程源拉取对匿名风控
@@ -4994,7 +5118,8 @@ $("upd-apply").addEventListener("click", async () => {
4994
5118
  "\n\n可能是网络抖动或匿名限流。要自动重试一次吗?(点取消放弃本次更新)")) throw netErr;
4995
5119
  btn.textContent = "重试中…";
4996
5120
  r = await post("/api/skill", {action: "install", name: "lingshu",
4997
- force: true, yes: updRiskAccepted ? true : undefined},
5121
+ force: true, source: pickedSrc === "auto" ? undefined : pickedSrc,
5122
+ yes: updRiskAccepted ? true : undefined},
4998
5123
  {signal: AbortSignal.timeout(APPLY_TIMEOUT)});
4999
5124
  }
5000
5125
  const st = r.result && r.result.state;
@@ -5012,7 +5137,8 @@ $("upd-apply").addEventListener("click", async () => {
5012
5137
  if (st === "failed" || r.ok === false) throw new Error((r.result && r.result.error) || "更新失败");
5013
5138
  progress.set(100);
5014
5139
  updRiskAccepted = false; // 下次更新重新走一遍风险告知
5015
- toast("灵枢本体已更新——重启面板(关掉再开)后新版本才生效");
5140
+ const doneSrc = (r.result && r.result.source) || pickedSrc;
5141
+ toast("灵枢本体已更新(来源 " + doneSrc + ")——重启面板(关掉再开)后新版本才生效");
5016
5142
  $("upd-modal").classList.add("hidden");
5017
5143
  const dot2 = $("upd-dot"); if (dot2) dot2.style.display = "none";
5018
5144
  await loadWS();