lingshu-skill 5.69.0 → 5.71.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 (44) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/SKILL-lite.md +1 -1
  3. package/SKILL-tiny.md +1 -1
  4. package/SKILL.md +1 -1
  5. package/cordis-plugin/lingshu-cron/plugin.js +36 -14
  6. package/cordis-plugin/lingshu-im/plugin.js +67 -15
  7. package/manifest.json +43 -43
  8. package/package.json +1 -1
  9. package/scripts/assembler.py +8 -2
  10. package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +90 -18
  11. package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +66 -0
  12. package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
  13. package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
  14. package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
  15. package/scripts/astrbot_plugin_lingshu/engine/scripts/assembler.py +8 -2
  16. package/scripts/astrbot_plugin_lingshu/engine/scripts/checkpoint.py +13 -2
  17. package/scripts/astrbot_plugin_lingshu/engine/scripts/desktop_shortcut.py +10 -1
  18. package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +45 -0
  19. package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +13 -2
  20. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +5629 -5575
  21. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth_parts.py +5 -1
  22. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +62 -6
  23. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_cloud.py +47 -1
  24. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +12 -2
  25. package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +10 -4
  26. package/scripts/astrbot_plugin_lingshu/engine/scripts/safety.py +6 -1
  27. package/scripts/astrbot_plugin_lingshu/engine/scripts/session_import.py +6 -2
  28. package/scripts/astrbot_plugin_lingshu/engine/scripts/session_rag.py +68 -21
  29. package/scripts/astrbot_plugin_lingshu/make_checksums.py +8 -4
  30. package/scripts/checkpoint.py +13 -2
  31. package/scripts/desktop_shortcut.py +10 -1
  32. package/scripts/dream.py +45 -0
  33. package/scripts/emotion.py +13 -2
  34. package/scripts/growth.py +5629 -5575
  35. package/scripts/growth_parts.py +5 -1
  36. package/scripts/memory.py +62 -6
  37. package/scripts/panel_cloud.py +47 -1
  38. package/scripts/panel_server.py +12 -2
  39. package/scripts/persona.py +10 -4
  40. package/scripts/run_tests.py +240 -171
  41. package/scripts/safety.py +6 -1
  42. package/scripts/session_import.py +6 -2
  43. package/scripts/session_rag.py +68 -21
  44. package/scripts/update_dsh_copy.ps1 +42 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # 更新日志
2
2
 
3
+ ## v5.71(2026-12-05)
4
+
5
+ ### 🎉 150 项审计最终批:全量缺口大收官!
6
+
7
+ 本批一次性闭环最后 29 项待办,150 项审计**全部完成**:
8
+
9
+ **记忆与人格(高危)**:
10
+ 1. **LS-001**:`safety.py` 修复 POSIX 危险路径子目录绕过——系统目录前缀分隔符跟随平台(`/` vs `\`)。
11
+ 2. **LS-019**:`memory.py` 归档召回保留缺少 id 的旧记录,按内容哈希合成稳定 id。
12
+ 3. **LS-020**:`memory.py` purge 冷静期检查 fail-closed——时间戳缺失/无效拒绝物理删除。
13
+ 4. **LS-021**:`memory.py` trash_restore 按 deleted_at 选取最新版本台账记录。
14
+ 5. **LS-023**:`memory.py` 批量 discard/delete 遵守置顶保护,跳过并回报。
15
+ 6. **LS-026**:`persona.py` 人格自愈回滚在只读模式不写盘。
16
+ 7. **LS-027**:`persona.py` 写 lastgood 前执行完整结构校验。
17
+ 8. **LS-028**:`emotion.py` 补齐独立导入依赖(mind_state/default_onboarding)。
18
+ 9. **LS-030**:`dream.py` 旧 pending 存在时合并新簇,避免新簇永久丢失。
19
+ 10. **LS-032**:`dream.py` 禁止 aggregate 标志绕过审核——正文必须等于源原文拼接。
20
+
21
+ **会话与摄取**:
22
+ 11. **LS-046**:`session_rag.py` 脏时间戳单条隔离,不再回滚整批。
23
+ 12. **LS-047**:`session_rag.py` search/stats 只读连接,不自动建库建表。
24
+ 13. **LS-054**:`checkpoint.py` 同一脏工作区不重复 remember。
25
+ 14. **LS-055**:`growth_parts.py` frontmatter 开界独立成行判断。
26
+ 15. **LS-056**:`assembler.py` 钳制输出预留在 [0, budget]。
27
+ 16. **LS-057**:`session_import.py` 先设置 sys.path 再 import brain。
28
+
29
+ **面板与云端**:
30
+ 17. **LS-062**:`panel_cloud.py` cloud_shot 兼容完整文件名与扩展名两种传法。
31
+ 18. **LS-067**:`panel_cloud.py` 发布读-改-写共享索引加互斥锁。
32
+ 19. **LS-068**:`panel_cloud.py` 拒绝空扩展 ZIP 安装。
33
+ 20. **LS-085**:`panel_server.py` 技能操作协议对齐(check/show/delete/root_rm 别名)。
34
+ 21. **LS-122**:`make_checksums.py` 显式发布清单优先于下划线启发式,`_conf_schema.json` 纳入校验。
35
+
36
+ **Cordis 插件**:
37
+ 22. **LS-097**:cron extract 成功只清理已提交前缀,保留运行期间新增文本。
38
+ 23. **LS-098**:cron 高水位自救每档位只执行一次(先检查消费状态再跑)。
39
+ 24. **LS-105**:IM 后续工具步骤保留召回块,不提前删除。
40
+ 25. **LS-106**:IM 会话重绑定后按身份指纹替换旧提示。
41
+ 26. **LS-107**:IM capture 节流先原子占用再写回,防并发绕过间隔。
42
+ 27. **LS-108**:IM `where.exe` 探测 PATH 真实 python.exe,修复 .cmd 启动。
43
+ 28. **LS-110**:cron 水位动作 busy 时不消费档位,下轮可重试。
44
+ 29. **LS-115**:`test_app_context.py` __main__ 移到末尾,plan_turns 测试可执行。
45
+
46
+ ---
47
+
48
+ ## v5.70(2026-12-05)
49
+
50
+ ### 🏗️ 150 项审计第十四批:发布流水线与测试门禁组大收官
51
+
52
+ 1. **LS-129(高·GitHub Release 校验)**:`release.yml` 发布前校验标签与代码版本一致(SKILL.md/package.json 三方对账),并运行核心测试作为门禁;旧标签不再无条件覆盖 latest。
53
+ 2. **LS-131(高·目录替换原子回滚)**:`growth.py` 的 `_atomic_replace_dir` 移除全部"先删目标"路径——非原子复制走独立 staging 先复制、成功后才替换,任何故障不留空树或混合树。
54
+ 3. **LS-135(中·快捷方式路径修正)**:`growth.py` 从安装目录(SKILL.md 父目录)拼接 panel_server.py 路径,快捷方式真正指向刚装好的目标副本。
55
+ 4. **LS-139(高·PowerShell 坏包失败)**:`update_dsh_copy.ps1` 的 `Get-CopyVersion` 解析错误抛致命错误(非零退出),不再返回 "?" 伪装成功。
56
+ 5. **LS-140(高·PowerShell 事务回滚)**:`update_dsh_copy.ps1` 复制前整目录备份,失败时整体回滚到备份状态,不留混合副本。
57
+ 6. **LS-141(中·预同步退出码)**:`run_tests.py` 的 engine 预同步非零退出时整体中止测试(返回 2),不再"打提示继续跑"。
58
+ 7. **LS-142(高·超时杀进程树)**:`run_tests.py` 超时后用 taskkill/T / killpg 终止整个子进程树,不留孤儿进程占用端口。
59
+ 8. **LS-143(中·.mjs 纳入统一测试)**:`run_tests.py` 追加 node --test 执行所有 test_*.mjs,JS 门禁与 Python 测试同链。
60
+ 9. **LS-144(中·缺 Node 明确 SKIP)**:无 node 可执行文件时 .mjs 测试明确标记 SKIP(计入失败),不再静默通过。
61
+ 10. **LS-145(中·桌面快捷方式隔离)**:`desktop_shortcut.py` 支持 `LINGSHU_TEST_DESKTOP_DIR` 环境变量重定向;`run_tests.py` 为所有测试进程设置临时桌面目录。
62
+ 11. **LS-147(中·stale manifest 不跳过)**:`test_selfupdate_egg.py` 清单过期时自动重新生成,仍过期则明确 FAIL,不再静默 SKIP。
63
+ 12. **LS-148(中·npm 更新测试断言)**:`test_p24_update_npm.py` 替换恒真断言——同版本/旧版本/新版本分别断言确定结果。
64
+ 13. **LS-149(中·插件冒烟核心失败必须 FAIL)**:`test_plugin_smoke.py` 从允许状态移除"核心调用失败",解释器/权限故障直接阻断。
65
+ 14. **LS-150(中·长轮询仅接受真实响应)**:`test_p21_panel_lifecycle.py` 连接拒绝/重置/DNS 全部判 FAIL,只有真实端点响应或读超时才通过。
66
+
67
+ ---
68
+
3
69
  ## v5.69(2026-12-05)
4
70
 
5
71
  ### 🛡️ 150 项审计第十三批:Cordis IM 安全与面板设置组大收官
package/SKILL-lite.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: lingshu-lite
3
3
  title: 灵枢-lite
4
- version: 5.69
4
+ version: 5.71
5
5
  description: 灵枢记忆系统的精简版说明书,给 3B 以下本地小模型或第一次用的人。只保留最有用的核心:分层记忆(含冷热自动归档)、模糊回忆、工作记忆、人格初识;砍掉高风险自动能力(自动做梦合并、自动情绪评估、自动提炼知识库)——小模型做这些容易把幻觉固化落盘。当用户提到"记住这个""你还记得吗""你记得什么""上下文快满了"且宿主是小模型时使用。
6
6
  ---
7
7
 
package/SKILL-tiny.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: lingshu-tiny
3
3
  title: 灵枢-tiny
4
- version: 5.69
4
+ version: 5.71
5
5
  description: 灵枢记忆系统的最小试用版说明书。只剩三件事:startup 带回上次的记忆、remember 记下值得记的、recall 想不起来时捞回来。给第一次接触灵枢的人或最小模型:先跑通这三条拿到真实收益,再决定要不要升级完整版。当用户提到"记住这个""你还记得吗"且你不想背整套机制时使用。
6
6
  ---
7
7
 
package/SKILL.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: lingshu
3
3
  title: 灵枢
4
- version: 5.69
4
+ version: 5.71
5
5
  description: 类脑持久记忆/人格/成长。跨会话记住事情、长出人格、上下文将满时做梦整理。用户提记忆/记住/上次/人格/设定/性格/知识库/笔记/日志/成长/自我进化/工作记忆,或新会话需恢复关系上下文时用。纯本地零依赖。
6
6
  ---
7
7
 
@@ -786,6 +786,7 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
786
786
  const prev = Number(st.max) || 0
787
787
  if (level <= prev) return null // 档位只推进一次(首次跨 75/90 各做一次)
788
788
  let noticeText = null
789
+ let delivered = true // LS-110: 本档动作是否成功投递(busy 等临时状态不算消费)
789
790
  // 75%:该做梦了。直接从低位跳到 90% 时也补做这一档(prev < 75)。
790
791
  // 复用 turn-stopping 那条任务名 'dream':全局同一时刻只许一份 dream 在跑
791
792
  // (与轮次驱动的 dream 撞车时返回 busy,如实记 executed=false)。
@@ -794,6 +795,10 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
794
795
  if (consent && wcfg.shadow === false) {
795
796
  const fired = fire({ id: 'dream', argv: ['dream', '--auto'] })
796
797
  recordWaterAuto(75, 'dream --auto', fired, fired ? 'executed' : 'busy')
798
+ // LS-110(v5.71):水位动作失败时允许后续重试!
799
+ // busy(dream 已在跑)只是暂时的——若此刻消费掉档位,这 75% 的
800
+ // dream 就永远不会再补做。只有成功投递才推进档位。
801
+ delivered = fired
797
802
  } else {
798
803
  // 影子模式或没给同意:只记"本来会做什么",不动手
799
804
  recordWaterAuto(75, 'dream --auto', false, consent ? 'shadow' : 'no-consent')
@@ -804,7 +809,10 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
804
809
  recordWaterAuto(90, 'capture', false, 'no-verbatim')
805
810
  noticeText = escapeSuggestion(pct, source)
806
811
  }
807
- waterAutoState.set(agent, { max: level })
812
+ // LS-110: 仅成功投递后消费档位;busy 等临时状态解除后下一轮可重试
813
+ if (delivered) {
814
+ waterAutoState.set(agent, { max: level })
815
+ }
808
816
  return noticeText
809
817
  }
810
818
 
@@ -843,8 +851,18 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
843
851
  }
844
852
  } catch {} // 顶层兜底
845
853
  finally {
846
- if (ok) convo.set(agent, { text: '', seen: buf?.seen }) // 清空缓冲,但保留游标(防止重复攒旧消息)
847
- else if (text.length > 200_000) {
854
+ // LS-097(v5.71):extract 成功只清理**已提交前缀**!
855
+ // 旧实现把整个缓冲清空——子进程运行期间(可达数秒)新攒进来的对话
856
+ // 会被一并清掉(数据丢失)。现在按快照长度截掉已提交部分,
857
+ // 保留 extract 运行期间新增的文本和游标。
858
+ if (ok) {
859
+ const cur = convo.get(agent) || { text: '', seen: [] }
860
+ const committed = (buf?.text || '')
861
+ const curText = cur.text || ''
862
+ // 快照仍是当前缓冲的前缀 → 截掉前缀;否则(已被截断兜底改写)保守清空
863
+ const rest = curText.startsWith(committed) ? curText.slice(committed.length) : ''
864
+ convo.set(agent, { text: rest, seen: buf?.seen })
865
+ } else if (text.length > 200_000) {
848
866
  // 兜底防爆内存:截断保留头部 100k 而非全丢,并至少告警一次(#64)
849
867
  // ★ 必须用 ctx.logger(审计 plugin.js:766):模块作用域里没有裸 `logger`
850
868
  // (只有 ctx.logger 和本地 warn(),而后者是 once-only——这里丢的是数据,
@@ -1405,19 +1423,23 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
1405
1423
  // diagnose 只报告),绝不自动 capture(拿不到原文)也绝不 purge(物理删除)。
1406
1424
  const th = pressureThresholds()
1407
1425
  if (pct >= th.force_at) {
1426
+ // LS-098(v5.71):高水位自救每个档位只执行一次!
1427
+ // 旧实现先 await runForceActions 再检查 forceAt 消费状态——
1428
+ // 连续 99% 时每个 pre-step 都会重复启动子进程(auto-archive 风暴)。
1429
+ // 现在先检查档位消费状态,已执行过就只提示不再跑。
1430
+ if (st.forceAt === true) {
1431
+ return decision
1432
+ }
1408
1433
  const did = await runForceActions(pythonExe, brainPy)
1409
- if (st.forceAt !== true) {
1410
- st.forceAt = true
1411
- waterState.set(agent, st)
1412
- return {
1413
- ...decision,
1414
- messages: [...decision.messages, notice(
1415
- `【灵枢·水位 ${pct}%】已到强制自救线(${th.force_at}%),已自动执行无破坏性压缩:${did || '无可用动作'}。`
1416
- + `现在只做三件事之一:① 让用户确认封存 capture;② 结束本轮话题;③ 继续也得先说明风险。不要再开新话题。`,
1417
- )],
1418
- }
1434
+ st.forceAt = true
1435
+ waterState.set(agent, st)
1436
+ return {
1437
+ ...decision,
1438
+ messages: [...decision.messages, notice(
1439
+ `【灵枢·水位 ${pct}%】已到强制自救线(${th.force_at}%),已自动执行无破坏性压缩:${did || '无可用动作'}。`
1440
+ + `现在只做三件事之一:① 让用户确认封存 capture;② 结束本轮话题;③ 继续也得先说明风险。不要再开新话题。`,
1441
+ )],
1419
1442
  }
1420
- return decision
1421
1443
  }
1422
1444
  if (pct >= th.hard_at && st.hardAt !== true) {
1423
1445
  st.hardAt = true
@@ -25,7 +25,7 @@
25
25
  // 数据安全:只读记忆库 + 仅在用户显式 capture-on 后写回本人原话;不改宿主
26
26
  // 人格、不改 dsh-im 配置、不写入任何非本插件命名空间的状态。
27
27
 
28
- import { spawn } from 'node:child_process'
28
+ import { spawn, execFileSync } from 'node:child_process'
29
29
  import { existsSync, readFileSync, statSync } from 'node:fs'
30
30
  import { homedir } from 'node:os'
31
31
  import { dirname, join } from 'node:path'
@@ -159,6 +159,23 @@ function findPythonExe(configured) {
159
159
  for (const p of candidates) {
160
160
  if (existsSync(p)) return p
161
161
  }
162
+ // LS-108(v5.71):修复 Windows .cmd Python 启动方式!
163
+ // 旧实现候选全落空时返回 null,runBrain 退化成 spawn('python', ...)——
164
+ // Node 18+ 出于安全禁止 spawn 直接执行 .cmd/.bat(EINVAL),conda/Store
165
+ // 的 python 都经过 .cmd shim,导致召回和写回**静默返回 null**。
166
+ // 现在用 `where python` 同步探测 PATH 里真实的 python.exe/优先 exe。
167
+ if (process.platform === 'win32') {
168
+ try {
169
+ const out = execFileSync('where.exe', ['python'], { encoding: 'utf8', timeout: 3000 })
170
+ const lines = String(out || '').split(/\r?\n/).map((s) => s.trim()).filter(Boolean)
171
+ // 优先真实 .exe(排除 Store 的 python.exe stub 不太好区分,但至少拿到真实路径)
172
+ const exe = lines.find((s) => s.toLowerCase().endsWith('.exe'))
173
+ if (exe && existsSync(exe)) return exe
174
+ // 只有 .cmd/.bat:返回它(runBrain 的数组 spawn 路径 + 元字符校验已防护)
175
+ const cmd = lines.find((s) => /\.(cmd|bat)$/i.test(s))
176
+ if (cmd && existsSync(cmd)) return cmd
177
+ } catch { /* where 失败就走原 null 路径 */ }
178
+ }
162
179
  return null
163
180
  }
164
181
 
@@ -342,6 +359,7 @@ export function apply(ctx, config) {
342
359
  const lastInjected = new Map() // agent -> 上一条已处理的用户消息 id
343
360
  const seenBySession = new Map() // sessionId -> Set(已注入记忆 id)
344
361
  const captureSeen = new Map() // agent -> 最近已写回的消息 id(防同轮重复)
362
+ const lastIdentityFp = new Map() // LS-106: agent -> 上次注入身份指纹(channel\u0000user),重绑定时替换旧提示
345
363
  const lastCapture = new Map() // `${channel}\u0000${group}\u0000${user}` -> 毫秒时间戳
346
364
  const consentCache = new Map() // user -> { mt, ok }(按 mtime 失效,授权后下一条即生效)
347
365
 
@@ -498,8 +516,16 @@ export function apply(ctx, config) {
498
516
  const key = `${id.channel}\u0000${id.group}\u0000${id.user}`
499
517
  const now = Date.now()
500
518
  if (now - (lastCapture.get(key) || 0) < cfg.captureInterval * 1000) return
519
+ // LS-107(v5.71):为 capture 节流增加在飞标记!
520
+ // 旧实现在 await ensureBrainPy() 之前只读不占——两条快速连续消息
521
+ // 都能通过节流检查,并发绕过 captureInterval 重复写回。
522
+ // 现在进入写回前先原子占用节流键:失败路径回退到"半周期后重试"。
523
+ lastCapture.set(key, now)
501
524
  const brainPy = await ensureBrainPy()
502
- if (!brainPy) return
525
+ if (!brainPy) {
526
+ lastCapture.delete(key) // 释放占用,下条消息可重试
527
+ return
528
+ }
503
529
  // 聊天原话是用户亲述 → source=user(冲突时按用户原话取代)。
504
530
  const argv = [
505
531
  'channel', 'remember', '聊天原话:' + text.slice(0, cfg.maxText),
@@ -514,7 +540,7 @@ export function apply(ctx, config) {
514
540
  const out = await runBrain(findPythonExe(cfg.python), cfg.python, brainPy, argv,
515
541
  cfg.timeoutMs, cfg.memoryHome)
516
542
  if (out === null) {
517
- // 失败退避:半个周期后再试,别把一个周期全丢掉
543
+ // 失败退避:半个周期后再试,别把一个周期全丢掉(释放占用 + 缩短下次窗口)
518
544
  lastCapture.set(key, now - cfg.captureInterval * 1000 + Math.min(30, cfg.captureInterval) * 1000)
519
545
  return
520
546
  }
@@ -570,14 +596,6 @@ export function apply(ctx, config) {
570
596
 
571
597
  let messages = Array.isArray(decision.messages) ? decision.messages : []
572
598
  const original = decision.messages
573
- // 清理上一轮自己注入的召回块(身份块留着,工具步骤还要用)。这样无论
574
- // cron 包裹在本插件外层还是内层,结果都一致,且召回块只保留最新一份。
575
- if (messages.some((m) => m?.source?.name === INJECT_SOURCE && messageText(m).includes(MARK_RECALL))) {
576
- messages = messages.filter((m) => !(m?.source?.name === INJECT_SOURCE && messageText(m).includes(MARK_RECALL)))
577
- }
578
- // 清掉了旧召回块但本步不需要再注入时,也要把清理结果交回去。
579
- const pruned = messages !== original
580
- const finish = () => (pruned ? { ...decision, messages } : decision)
581
599
  // 找最新的用户消息(跳过本插件/cron 注入的、跳过 assistant/工具结果)。
582
600
  let newest = null
583
601
  for (let i = messages.length - 1; i >= 0; i--) {
@@ -589,8 +607,25 @@ export function apply(ctx, config) {
589
607
  break
590
608
  }
591
609
  if (!newest) return finish()
592
-
593
610
  const msgKey = String(newest.m.id ?? createHash('sha1').update(newest.text).digest('hex'))
611
+ const sameUserTurn = (lastInjected.get(agent) === msgKey)
612
+ // LS-105(v5.71):后续工具步骤保留或重建 IM 召回块!
613
+ // 旧实现无条件清理旧召回块 + 同一 msgKey 提前返回——工具调用后的
614
+ // 最终回答步骤看不到记忆。同一轮次(msgKey 相同)时保留旧召回块原样返回。
615
+ if (sameUserTurn) {
616
+ const stillHasRecall = messages.some(
617
+ (m) => m?.source?.name === INJECT_SOURCE && messageText(m).includes(MARK_RECALL))
618
+ return decision // 同一轮次:消息原样放行,召回/身份块都在
619
+ }
620
+ // 新一轮用户消息:清理上一轮自己注入的召回块(身份块留着,工具步骤还要用)。
621
+ if (messages.some((m) => m?.source?.name === INJECT_SOURCE && messageText(m).includes(MARK_RECALL))) {
622
+ messages = messages.filter((m) => !(m?.source?.name === INJECT_SOURCE && messageText(m).includes(MARK_RECALL)))
623
+ }
624
+ // 清掉了旧召回块但本步不需要再注入时,也要把清理结果交回去。
625
+ let pruned = messages !== original
626
+ const finish = () => (pruned ? { ...decision, messages } : decision)
627
+ if (!newest) return finish()
628
+
594
629
  const sessionId = sessionIdOf(agent) || msgKey
595
630
 
596
631
  // ---- 自动写回:只写用户原话,先授权后落盘;fire-and-forget 不阻塞回合
@@ -606,14 +641,31 @@ export function apply(ctx, config) {
606
641
  }
607
642
  }
608
643
 
609
- // ---- 注入:同一用户消息只处理一次(工具调用的后续步骤不重复)
610
- if (lastInjected.get(agent) === msgKey) return finish()
644
+ // ---- 注入:标记本轮已处理(工具调用的后续步骤走上面的 sameUserTurn 保留路径)
611
645
  lastInjected.set(agent, msgKey)
612
646
 
613
647
  let hint = ''
648
+ let _fp = ''
614
649
  if (cfg.identityHint) {
615
650
  const has = messages.some((m) => m?.source?.name === INJECT_SOURCE && messageText(m).includes(MARK_IDENTITY))
616
- if (!has) hint = identityLine(id)
651
+ // LS-106(v5.71):会话重绑定后刷新身份提示!
652
+ // 旧实现只看"有没有身份块"——同一会话换人(重绑定到新 sender)时,
653
+ // 旧用户的身份提示仍在,新 sender 沿用旧用户提示(张冠李戴)。
654
+ // 现在记录上次注入的身份指纹(channel+user),不一致时替换旧块。
655
+ _fp = `${id.channel}\u0000${id.user}`
656
+ if (has) {
657
+ if (lastIdentityFp.get(agent) === _fp) {
658
+ // 同一身份且块还在:不再重复注入
659
+ } else {
660
+ // 身份变了:替换旧的(清理后由下面的 text 重新注入)
661
+ messages = messages.filter((m) => !(m?.source?.name === INJECT_SOURCE && messageText(m).includes(MARK_IDENTITY)))
662
+ pruned = true
663
+ hint = identityLine(id)
664
+ }
665
+ } else {
666
+ hint = identityLine(id)
667
+ }
668
+ lastIdentityFp.set(agent, _fp)
617
669
  }
618
670
 
619
671
  let recall = ''
package/manifest.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
- "version": "5.69",
2
+ "version": "5.71",
3
3
  "files": {
4
4
  "CHANGELOG.md": {
5
- "sha256": "b6262eb1435a7bac003cd0403e1e16baee293170585119ed5803124e2459a49b",
6
- "size": 437749
5
+ "sha256": "ded9e237679c18e7f27677695653af9c7ae77a8432f5daa6732c851c8650b047",
6
+ "size": 443157
7
7
  },
8
8
  "README.md": {
9
9
  "sha256": "5ab87b76dc757e6edd6ef1d760e9a979e55df48b2b8c2b76552747fabb7b1026",
10
10
  "size": 114306
11
11
  },
12
12
  "SKILL-lite.md": {
13
- "sha256": "d2728fc7fd7f5f8e15e7d50302144aa07b95ebd5323eafcc42f6b4340daa4e96",
13
+ "sha256": "e9089dedfdc2be585bb14f3a7389deb8a3efdffef8749c0ab64091b5cb0f36f7",
14
14
  "size": 4440
15
15
  },
16
16
  "SKILL-tiny.md": {
17
- "sha256": "a3c73b3452e1f25c78fb71cad496f56b89559af5ac9ce036f88723b17c9ef69c",
17
+ "sha256": "348ba485b96767a422d057f6597393a4b457e68717da3fc8ceb19e0e7d06e0f4",
18
18
  "size": 1913
19
19
  },
20
20
  "SKILL.md": {
21
- "sha256": "4663a5d3bd3e369a8dee909b9303f2a9a853b9a2c7e8e0d2723d9a171ea93e4d",
21
+ "sha256": "52bee9e349c1298d19a0b0c91dfb6bb8c36425fd4dbc27e5f08c61c66e0f034f",
22
22
  "size": 25366
23
23
  },
24
24
  "assets/lingshu-icon-preview.png": {
@@ -50,16 +50,16 @@
50
50
  "size": 2205
51
51
  },
52
52
  "cordis-plugin/lingshu-cron/plugin.js": {
53
- "sha256": "b2bb77653562423dd01eeb872283eee1e0dcaf7a999c7be81b334189b9a0b2d8",
54
- "size": 76447
53
+ "sha256": "6e89f6de3ccc4d51159625ced64bfe5ff052ca099019f2ce91745a1ffeb0e38a",
54
+ "size": 77955
55
55
  },
56
56
  "cordis-plugin/lingshu-guard/plugin.js": {
57
57
  "sha256": "c86066adb5726331099b7513ac7cc7eb078d271b0f71454b900b716303b0fd65",
58
58
  "size": 23970
59
59
  },
60
60
  "cordis-plugin/lingshu-im/plugin.js": {
61
- "sha256": "6e36d0a1d0c0d961d581a24dfbfca89d1ae8cfe8a893fdcbbe97a33c1b231817",
62
- "size": 27567
61
+ "sha256": "f66c955fd0ba785123c600c86e4908e44611a592da1dc6a1fe684c6c53ad2ce7",
62
+ "size": 30790
63
63
  },
64
64
  "cordis-plugin/lingshu-startup/README.md": {
65
65
  "sha256": "e62016afb05dd910cd1b99fd547b1b5eead2afea43e0b90b96df2d2782c0b386",
@@ -138,7 +138,7 @@
138
138
  "size": 6007
139
139
  },
140
140
  "package.json": {
141
- "sha256": "2e0bf71cfb949e9cc9a000f8950d9610489f255d2bdf31788f33fade558efdda",
141
+ "sha256": "67c6c0e38c4b26b54fc5e3f7057e1d41c7794d55d7ed255d7c02ef8275eb8734",
142
142
  "size": 1503
143
143
  },
144
144
  "scripts/anchor_retention.py": {
@@ -150,8 +150,8 @@
150
150
  "size": 43970
151
151
  },
152
152
  "scripts/assembler.py": {
153
- "sha256": "084e1b0157feda76539f0acd57f813edc4fa4df65c7d418912ef874174622db6",
154
- "size": 8392
153
+ "sha256": "60bbb5ebe238d54f9f4bdecbbf0e24cfa9793102b6f1f734e796560786482205",
154
+ "size": 8774
155
155
  },
156
156
  "scripts/behavior_baseline.py": {
157
157
  "sha256": "7f488663082f301426c98f291a31860dd159a6097eba6ff225e4912f1b222272",
@@ -186,8 +186,8 @@
186
186
  "size": 14445
187
187
  },
188
188
  "scripts/checkpoint.py": {
189
- "sha256": "4757e4783dde68757ccf89a3d0d28e704038d365e20e455a09a8d0485b43255d",
190
- "size": 10000
189
+ "sha256": "9963cac0dffbb5fbaedbde9db40323abd19fc8c53250955f3b9119371144b31a",
190
+ "size": 10619
191
191
  },
192
192
  "scripts/cli.py": {
193
193
  "sha256": "e68709f183eae3cb407732f52df91fd65d22f4327b101a8bbc26df93c2a7b69f",
@@ -210,16 +210,16 @@
210
210
  "size": 4531
211
211
  },
212
212
  "scripts/desktop_shortcut.py": {
213
- "sha256": "77ea248bfaaf28e1e4299979d0c0d8c80a055642dde9a40f5e297b2008474091",
214
- "size": 7726
213
+ "sha256": "975b76d49c9d6b3220f7d45327e801a5d8c74aff39eae2e3fbdf86b38c7994cc",
214
+ "size": 8071
215
215
  },
216
216
  "scripts/dream.py": {
217
- "sha256": "da6bfcab38104b9248059fe70cb3544b2521fd66fe6ad44f3af4b780b06b550e",
218
- "size": 61061
217
+ "sha256": "0d3f2fe45890b401b1dc541bf42e34aeb3153f12471ffa0a8b94b1681759002a",
218
+ "size": 64166
219
219
  },
220
220
  "scripts/emotion.py": {
221
- "sha256": "e038024dfced6b497b7cc673474b2b4948323cae09b0a6df15498af1c9002daa",
222
- "size": 77402
221
+ "sha256": "e0b4451e05e99dd651c79b9d927191d963824012e7b03aba933d92e111368965",
222
+ "size": 77858
223
223
  },
224
224
  "scripts/failures.py": {
225
225
  "sha256": "3a16234a1871f62e3ba7b7b743110b4044fb7b715b4d0e924b8ebf1cf0be50d0",
@@ -234,12 +234,12 @@
234
234
  "size": 7846
235
235
  },
236
236
  "scripts/growth.py": {
237
- "sha256": "6646f08075a8dd4a8db7298fc0d3db44818f12767263f42666ea130ecaba4831",
238
- "size": 262434
237
+ "sha256": "e6324cdbda4d4f459b1bf367d52a91b772f1a72cc46cb17a83993e1630fb91a3",
238
+ "size": 264326
239
239
  },
240
240
  "scripts/growth_parts.py": {
241
- "sha256": "d8f8d1808d4097630e7a0425d1ad9bc8f3826c11a64625304e25336f2a8aa592",
242
- "size": 11125
241
+ "sha256": "84321f429394aaf1295e445e46ef2f09ab6881e66c47d16cb789eff86279b572",
242
+ "size": 11435
243
243
  },
244
244
  "scripts/hooks/pre-commit": {
245
245
  "sha256": "14dafabbfd698f7e510411b144ec624affe41023113b1ffd0f1aa8f3e623a275",
@@ -298,8 +298,8 @@
298
298
  "size": 7912
299
299
  },
300
300
  "scripts/memory.py": {
301
- "sha256": "e144e28a2c62cc756bc853dc436633f00314badf7ebe88de9e0e9cae77f90426",
302
- "size": 335178
301
+ "sha256": "eae2e89140b8543fd5c53c3b4504961a0b9769ff779091148d7c3b2df795267e",
302
+ "size": 338627
303
303
  },
304
304
  "scripts/memory_extras.py": {
305
305
  "sha256": "4adb61400c5224c90aa54f059267f795c6348a251d93cd173d79fff157d57d90",
@@ -318,8 +318,8 @@
318
318
  "size": 6684
319
319
  },
320
320
  "scripts/panel_cloud.py": {
321
- "sha256": "a35155e968b90f5d51e86ffafb14c96a9e6cbb1f20152b9831cb95767d72ce09",
322
- "size": 30102
321
+ "sha256": "bb0762f93efd0cdbb0db7f4541935a39c77579f6c1c7c974afa5094c8f0399f6",
322
+ "size": 32697
323
323
  },
324
324
  "scripts/panel_data.py": {
325
325
  "sha256": "189eadcba9139fc934fc22fcd62911828b28fe3a4a189c8c0598043d227ea37b",
@@ -334,8 +334,8 @@
334
334
  "size": 12360
335
335
  },
336
336
  "scripts/panel_server.py": {
337
- "sha256": "420292bf8f37a653f277b89f90f4f4744e9506c3062db2299a15aeca7040d3b1",
338
- "size": 160631
337
+ "sha256": "3e34c3461994f57d61d0bdcd6d81a575e03d18591f618f8d2e445a2618465ba3",
338
+ "size": 161326
339
339
  },
340
340
  "scripts/panel_settings.py": {
341
341
  "sha256": "1d33fc5bf46ee64e3d1b052ecfa1b998a5da55a58e55807182a7214f8594b15b",
@@ -358,8 +358,8 @@
358
358
  "size": 27795
359
359
  },
360
360
  "scripts/persona.py": {
361
- "sha256": "a0bd3ad7856c7d24a377fc2d23df9c5ee5f9f4bf6533d9cc485e6734b843dd36",
362
- "size": 134076
361
+ "sha256": "bc09d5bf148590e370a38fb78aaef84b6521818b536728efb3123a716f0b3916",
362
+ "size": 134548
363
363
  },
364
364
  "scripts/prepublish_tests.py": {
365
365
  "sha256": "8d116de1edd3ab57584a6a2749598cf127e918383da67e50118601e5a3970c2a",
@@ -378,24 +378,24 @@
378
378
  "size": 7009
379
379
  },
380
380
  "scripts/run_tests.py": {
381
- "sha256": "9f1cbfb2f1bf6eea9722e0027a99546dd2150390746d4f8cc5c5c6a37f049ff4",
382
- "size": 7595
381
+ "sha256": "0188e1bc6079b3444db6b7a2be2ad4db922172aad5f30dcdaadbe0a5a16f226f",
382
+ "size": 11690
383
383
  },
384
384
  "scripts/safety.py": {
385
- "sha256": "01ff42b7dac0eeac45c4a1e8cee97a21d8f0de55067213a61efbb95073186638",
386
- "size": 15947
385
+ "sha256": "1ae280f1f03feecf8b735b6305b136b5809d138c168e22e1d9fa5495b77fb145",
386
+ "size": 16331
387
387
  },
388
388
  "scripts/safety_net.py": {
389
389
  "sha256": "678d9286c83530e5196f4e46ef195d7e4686fe7f9bcbff0af57ff1b97827376e",
390
390
  "size": 16206
391
391
  },
392
392
  "scripts/session_import.py": {
393
- "sha256": "4b9c0e88d11b5cee900a65a4abe31b888eefa15a99f1883cb9ea74f65ffbc770",
394
- "size": 33312
393
+ "sha256": "61ddf40707e0b11d9c958040f2024d1fc7c4dc45eb798ed0a4befcce38713bbe",
394
+ "size": 33621
395
395
  },
396
396
  "scripts/session_rag.py": {
397
- "sha256": "ac79eab81fc4a423417c811c8f3737b461ab48e68a76da2fb9c71521d5826e1f",
398
- "size": 10214
397
+ "sha256": "60fe617e3ca9863d9f77957421ce81de91a533452618d3dbb84a81cf1826df5e",
398
+ "size": 12250
399
399
  },
400
400
  "scripts/session_summary.py": {
401
401
  "sha256": "290d6cff75c68461f03bcad8d691793fb9c79612d4c44b3da22679fab021a149",
@@ -442,8 +442,8 @@
442
442
  "size": 3792
443
443
  },
444
444
  "scripts/update_dsh_copy.ps1": {
445
- "sha256": "34787ce5fe6736a385e6e7bd167a52086774dc4bc3c64a18559a3fba0ad9447a",
446
- "size": 5290
445
+ "sha256": "46b66911e517c88c954931bcebd7c71a5def2443e797d57c61cd8b3db30a251d",
446
+ "size": 7315
447
447
  },
448
448
  "scripts/watchdog.py": {
449
449
  "sha256": "93a8a5385523aa8de0e25f75bd9c08cec2be045190f6247990d80da8d75800b5",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lingshu-skill",
3
- "version": "5.69.0",
3
+ "version": "5.71.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",
@@ -61,10 +61,16 @@ def plan(parts: dict, budget: int = 40000, *, ratios: dict | None = None,
61
61
  budget = max(1, int(budget))
62
62
  ratios = {**DEFAULT_RATIOS, **(ratios or {})}
63
63
  # 输出预留:min(max_tokens, 25% 窗口),与附录 C 的 outputHeadroomMaxPct 一致
64
+ # LS-056(v5.71):钳制输出预留和可用上下文范围!
65
+ # 旧写法不设防——output_reserve 传负数时 reserve<0 → usable > 总预算;
66
+ # 传 >1 时 reserve 吃掉全部窗口。现在 reserve 强制钳在 [0, budget]。
67
+ _or = float(output_reserve) if output_reserve is not None else 0.25
68
+ _or = max(0.0, min(1.0, _or))
64
69
  if max_output_tokens:
65
- reserve = min(int(max_output_tokens), int(budget * output_reserve))
70
+ reserve = min(int(max_output_tokens), int(budget * _or))
66
71
  else:
67
- reserve = int(budget * output_reserve)
72
+ reserve = int(budget * _or)
73
+ reserve = max(0, min(budget, reserve))
68
74
  usable = max(1, budget - reserve)
69
75
 
70
76
  texts = {name: str(parts.get(name) or "") for name in SECTIONS}