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
@@ -95,7 +95,11 @@ def parse_frontmatter(text: str) -> tuple:
95
95
  以及常见简写(值里含冒号、以 # 开头)。够读 DSH / Claude / Trae 各家的 SKILL.md。
96
96
  """
97
97
  text = text.lstrip("\ufeff")
98
- if not text.startswith("---"):
98
+ # LS-055(v5.71):开界与闭界采用一致的整行判断!
99
+ # 旧写法 startswith("---") 会把 "---not-a-delimiter" 这种**整行**误当开界,
100
+ # 吞掉后面的正文。开界必须也是独立成行的 "---"(行尾只允许空白)。
101
+ _first_line = text.split("\n", 1)[0].rstrip()
102
+ if _first_line != "---":
99
103
  return {}, text
100
104
  # 闭界必须是整行 "---"(行尾可带空白):裸 find("\n---") 会把正文里
101
105
  # "---xxx" 这类行误当边界,导致 head 被提前截断
package/scripts/memory.py CHANGED
@@ -460,11 +460,19 @@ def bulk_memory_action(ids: list, action: str, value=None) -> dict:
460
460
  raise ValueError("没有可用的标签")
461
461
  want = set(ids)
462
462
  updated = 0
463
+ skipped_pinned: list = []
463
464
  with _locked(HOME / "hippocampus.jsonl"):
464
465
  records = load_all()
465
466
  for m in records:
466
467
  if m.get("id") not in want:
467
468
  continue
469
+ # LS-023(v5.71):批量操作遵守置顶保护!
470
+ # 单条 forget / set_memory_review(discard) / apply_dream(forget) 都
471
+ # 硬拒置顶记忆,但批量 discard/delete 原来不看 pinned——面板一次
472
+ # 全选就能把置顶记忆扫进淡忘区。现在口径统一:置顶记忆跳过并如实回报。
473
+ if action in ("discard", "delete") and m.get("pinned") and m.get("layer") != "dust":
474
+ skipped_pinned.append(m["id"])
475
+ continue
468
476
  if action == "confirm":
469
477
  m["review"] = "confirmed"
470
478
  m["review_at"] = now_ts()
@@ -507,6 +515,7 @@ def bulk_memory_action(ids: list, action: str, value=None) -> dict:
507
515
  # v4 #32:批量操作审计(含批量 delete/importance 等)
508
516
  audit_log("panel", f"bulk_{action}", f"{len(ids)}条", f"成功 {updated} 条")
509
517
  return {"updated": updated, "requested": len(ids), "action": action,
518
+ "skipped_pinned": skipped_pinned,
510
519
  "review_counts": review_counts()}
511
520
 
512
521
 
@@ -2465,9 +2474,29 @@ def recall(query: str, k: int = 8, layers: tuple = ("cortex", "hippo"),
2465
2474
  if not str(m.get("agent_id") or "").strip()
2466
2475
  or str(m.get("agent_id")).strip() == aid]
2467
2476
  if include_archive:
2477
+ # LS-019(v5.71):保留缺少 ID 的旧归档记录!
2478
+ # 旧实现 `if m.get("id")` 把无 id 的老归档记录整条丢弃——这些是
2479
+ # 早期版本写入的历史,静默丢失。现在按 load_all 同款做法合成稳定
2480
+ # 内容哈希 id(仅内存内生效,不写回 archive.jsonl)。
2481
+ import hashlib as _hashlib
2482
+ _raw_archive = load_archive()
2483
+ archive = []
2484
+ for m in _raw_archive:
2485
+ if not isinstance(m, dict):
2486
+ continue
2487
+ if not m.get("id"):
2488
+ _m = dict(m)
2489
+ try:
2490
+ _seed = json.dumps({k: _m.get(k) for k in
2491
+ ("text", "kind", "created", "layer", "gist")},
2492
+ ensure_ascii=False, sort_keys=True, default=str)
2493
+ _m["id"] = "m_" + _hashlib.sha1(_seed.encode("utf-8")).hexdigest()[:12]
2494
+ except Exception:
2495
+ _m["id"] = "m_archive_noid"
2496
+ m = _m
2497
+ if _channel_visible(m, channel, group_id, user):
2498
+ archive.append(m)
2468
2499
  # LS-004(v5.58):归档召回同样必须执行 agent_id 隔离。
2469
- archive = [m for m in load_archive() if m.get("id")
2470
- and _channel_visible(m, channel, group_id, user)]
2471
2500
  if agent_id:
2472
2501
  aid = str(agent_id).strip()
2473
2502
  archive = [m for m in archive
@@ -3173,8 +3202,19 @@ def trash_restore(memory_id: str) -> dict:
3173
3202
  except Exception:
3174
3203
  keep.append(line)
3175
3204
  continue
3176
- if row.get("id") == memory_id and target is None:
3177
- target = row # 取最近一条(后写覆盖前写)
3205
+ if row.get("id") == memory_id:
3206
+ # LS-021(v5.71):台账恢复应选取最新版本!
3207
+ # 同一记忆可能被删除多次(删→复存→再删),台账里有多条同 id 记录。
3208
+ # 旧实现取文件里的第一条(可能是最旧版本),恢复回的是过期内容。
3209
+ # 现在按 deleted_at 比较,始终保留时间戳最新的那条。
3210
+ if (target is None
3211
+ or _num(row.get("deleted_at"), 0) > _num(target.get("deleted_at"), 0)):
3212
+ # 之前选中的旧版本行要留在台账里(其他 restore 仍可能需要)
3213
+ if target is not None:
3214
+ keep.append(json.dumps(target, ensure_ascii=False))
3215
+ target = row
3216
+ else:
3217
+ keep.append(line)
3178
3218
  else:
3179
3219
  keep.append(line)
3180
3220
  if target is None:
@@ -3246,7 +3286,13 @@ def purge(memory_id: str, confirm_token: str) -> dict:
3246
3286
  target = next((m for m in archive if m.get("id") == memory_id), None)
3247
3287
  if not target:
3248
3288
  raise ValueError(f"没有这条记忆:{memory_id}")
3249
- archived_at = _num(target.get("archived_at") or target.get("forgotten_at"), 0)
3289
+ # LS-020(v5.71):归档分支同样禁止异常时间戳绕过冷静期
3290
+ _raw_aa = target.get("archived_at") or target.get("forgotten_at")
3291
+ archived_at = _num(_raw_aa, -1)
3292
+ if archived_at <= 0:
3293
+ raise ValueError(
3294
+ f"这条归档记忆的时间戳缺失或无效(archived_at={_raw_aa!r}),"
3295
+ f"无法确认已过 {_PURGE_COOLDOWN_DAYS} 天冷静期,拒绝物理删除。")
3250
3296
  if archived_at > cutoff:
3251
3297
  raise ValueError(
3252
3298
  f"归档记忆需冷静满 {_PURGE_COOLDOWN_DAYS} 天后才能物理删除"
@@ -3267,7 +3313,17 @@ def purge(memory_id: str, confirm_token: str) -> dict:
3267
3313
  raise ValueError(
3268
3314
  f"只有淡忘区(dust)的记忆才能物理删除,当前层:{target.get('layer')}。"
3269
3315
  f"先 `memory forget {memory_id}` 转 dust,满 {_PURGE_COOLDOWN_DAYS} 天后再 purge。")
3270
- forgotten_at = _num(target.get("forgotten_at"), 0)
3316
+ # LS-020(v5.71):禁止异常删除时间戳绕过冷静期!
3317
+ # 旧实现 _num(forgotten_at, 0) 把缺失/坏值当 0 —— 0 恒小于 cutoff,
3318
+ # 冷静期检查形同虚设,脏数据记忆可直接物理删除。现在 fail-closed:
3319
+ # 时间戳缺失或无法解析时拒绝 purge,要求先修正记录。
3320
+ _raw_fa = target.get("forgotten_at")
3321
+ forgotten_at = _num(_raw_fa, -1)
3322
+ if forgotten_at <= 0:
3323
+ raise ValueError(
3324
+ f"这条记忆的淡忘时间戳缺失或无效(forgotten_at={_raw_fa!r}),"
3325
+ f"无法确认已过 {_PURGE_COOLDOWN_DAYS} 天冷静期,拒绝物理删除。"
3326
+ "请先修复该记录的时间戳或用 forget 重新淡忘。")
3271
3327
  if forgotten_at > cutoff:
3272
3328
  raise ValueError(
3273
3329
  f"淡忘记忆需冷静满 {_PURGE_COOLDOWN_DAYS} 天后才能物理删除"
@@ -25,6 +25,7 @@ import base64
25
25
  import hashlib
26
26
  import json
27
27
  import os
28
+ import threading
28
29
  import time
29
30
  import urllib.error
30
31
  import urllib.request
@@ -413,6 +414,11 @@ def cloud_extension_download(ext_id: str) -> dict:
413
414
  raise FileExistsError("该拓展已安装,请先删除 extensions/installed 下同名目录")
414
415
  with zipfile.ZipFile(io.BytesIO(raw)) as z:
415
416
  names = z.namelist()
417
+ # LS-068(v5.71):拒绝空扩展 ZIP 安装成功!
418
+ # 旧实现只查文件数上限——空包(0 个文件)也能"安装成功",装出一个
419
+ # 空目录还显示"已安装"。现在要求至少一个有效文件。
420
+ if not names or all(n.endswith("/") for n in names):
421
+ raise ValueError("拓展包是空的(没有任何文件),拒绝安装")
416
422
  if len(names) > panels.ZIP_MAX_FILES:
417
423
  raise ValueError("拓展包文件数超限")
418
424
  total = sum(i.file_size for i in z.infolist())
@@ -464,7 +470,25 @@ def _safe_name(name: str) -> bool:
464
470
 
465
471
 
466
472
  def cloud_shot(name: str, ext: str) -> bytes:
467
- """取云端截图字节(前端 <img> 直连本机代理端点,避免跨域/混合内容问题)。"""
473
+ """取云端截图字节(前端 <img> 直连本机代理端点,避免跨域/混合内容问题)。
474
+
475
+ LS-062(v5.71):统一截图清单字段与读取参数!
476
+ 清单里 `screenshot` 存的是**完整文件名**(如 "demo.png"),而旧实现要求
477
+ 调用方把 ext 拆成 ".png" 单独传——前端直接把清单字段塞进 ext 参数时,
478
+ 拼出 "shots/demo{demo.png}" 这种不存在的路径。现在兼容两种传法:
479
+ ext 以 "." 开头按扩展名处理;否则视为完整文件名(忽略多余的 name 前缀)。
480
+ """
481
+ ext = str(ext or "").strip()
482
+ if not ext.startswith("."):
483
+ # 传入的是完整文件名(清单 screenshot 字段):剥掉 name 前缀留扩展名
484
+ _fname = ext.lower()
485
+ if _fname == str(name).strip().lower():
486
+ ext = ".png" # 只给了面板名(老清单只有名字):用默认 png
487
+ elif _fname.startswith(str(name).strip().lower()):
488
+ ext = _fname[len(str(name).strip()):]
489
+ if not ext.startswith("."):
490
+ ext = Path(ext).suffix or ".png"
491
+ ext = ext.lower()
468
492
  if ext not in SHOT_WHITELIST:
469
493
  raise ValueError("截图扩展名不支持")
470
494
  c = _cfg()
@@ -615,12 +639,34 @@ def _push_one(kind: str, repo: str, token: str, branch: str, name: str,
615
639
 
616
640
  kind_key 决定子目录与清单键:panels → panels/xxx.zip + index.json.panels,
617
641
  extensions → extensions/xxx.zip + index.json.extensions(同一份 index.json)。
642
+
643
+ LS-067(v5.71):防止云发布并发覆盖共享 index!
644
+ 旧实现的"读旧清单→合并→回写"在两个发布同时跑时会互相覆盖:
645
+ A 读到旧清单、B 读到旧清单、A 写回(带 A 条目)、B 写回(**丢掉 A 条目**)。
646
+ 现在用进程级互斥锁串行化"读-改-写"窗口;锁只保护本机并发,
647
+ 跨机器场景靠回写前二次读取对比 updated 做最后防线。
618
648
  """
649
+ global _PUBLISH_LOCK
619
650
  put = _gitee_put if kind == "gitee" else _github_put
620
651
  get = _gitee_get if kind == "gitee" else _github_get
621
652
  put(repo, f"{kind_key}/{name}.zip", token, branch, zbytes, msg, author)
622
653
  if shot is not None:
623
654
  put(repo, f"shots/{name}{shot_ext}", token, branch, shot, msg, author)
655
+ with _PUBLISH_LOCK:
656
+ _push_index_entry(kind, repo, token, branch, name, entry, msg,
657
+ kind_key=kind_key, author=author)
658
+
659
+
660
+ # LS-067: 云发布共享 index 的读-改-写互斥锁(进程级;个人市场单机足够)
661
+ _PUBLISH_LOCK = threading.Lock()
662
+
663
+
664
+ def _push_index_entry(kind: str, repo: str, token: str, branch: str, name: str,
665
+ entry: dict, msg: str, kind_key: str = "panels",
666
+ author: dict | None = None) -> None:
667
+ """index.json 合并回写(必须在 _PUBLISH_LOCK 内调用)。"""
668
+ put = _gitee_put if kind == "gitee" else _github_put
669
+ get = _gitee_get if kind == "gitee" else _github_get
624
670
  # index.json 合并回写:读旧清单 → 覆盖同名条目 → 写回(并发竞争可接受,个人市场)
625
671
  #
626
672
  # ⚠ fail-closed:**只有"清单确实不存在"才可以新建空清单**。
@@ -2190,9 +2190,18 @@ def _api_skill(self, path, data):
2190
2190
  res = growth.install_skill(_name, force=bool(data.get("force")), from_dir=_from,
2191
2191
  accept_risk=risk_ok)
2192
2192
  self._json({"ok": True, "result": res, "skill": res, "workspace": workspace()})
2193
- elif act == "uninstall":
2193
+ elif act == "uninstall" or act == "delete":
2194
+ # LS-085(v5.71):统一技能操作的 action 协议——delete 是前端实际发送的名字
2194
2195
  res = growth.uninstall_skill(data.get("name", ""), managed_only=True)
2195
2196
  self._json({"ok": True, "skill": res, "workspace": workspace()})
2197
+ elif act == "check":
2198
+ # LS-085: 自检 = 列出技能区 + 全局根目录状态(前端"自检"按钮走这条)
2199
+ res = growth.scan_skills()
2200
+ self._json({"ok": True, "skills": res, "workspace": workspace()})
2201
+ elif act == "show":
2202
+ # LS-085: show = locate(前端查看/编辑入口用它定位技能)
2203
+ res = growth.locate_skill(data.get("name", ""), data.get("root"))
2204
+ self._json({"ok": True, "skill": res})
2196
2205
  elif act == "use":
2197
2206
  res = growth.locate_skill(data.get("name", ""), data.get("root"))
2198
2207
  self._json({"ok": True, "skill": res})
@@ -2203,7 +2212,8 @@ def _api_skill(self, path, data):
2203
2212
  elif act == "root_add":
2204
2213
  res = growth.add_skill_root(data.get("path", ""))
2205
2214
  self._json({"ok": True, "result": res, "workspace": workspace()})
2206
- elif act == "root_remove":
2215
+ elif act == "root_remove" or act == "root_rm":
2216
+ # LS-085: root_rm 是前端实际发送的名字(与 root_remove 同义)
2207
2217
  res = growth.remove_skill_root(data.get("path", ""))
2208
2218
  self._json({"ok": True, "result": res, "workspace": workspace()})
2209
2219
  elif act == "scan":
@@ -350,10 +350,12 @@ def load_persona() -> dict:
350
350
  log_event("persona", "检测到人格空态,已自动从 persona.lastgood.json 回滚", level="warn")
351
351
  # AUTOHEAL-COMMIT(v5.56):立即写回盘,否则下次 load 又读到空态 →
352
352
  # 反复回滚 + 反复告警(实测 5 分钟刷 78 条 warn)。写回失败不影响返回值。
353
- try:
354
- atomic_json(HOME / "persona.json", _good)
355
- except Exception:
356
- pass
353
+ # LS-026(v5.71):人格自愈绝不能在只读模式写盘!
354
+ if not READONLY:
355
+ try:
356
+ atomic_json(HOME / "persona.json", _good)
357
+ except Exception:
358
+ pass
357
359
  except Exception:
358
360
  pass
359
361
 
@@ -426,8 +428,12 @@ def save_persona(p: dict) -> None:
426
428
  atomic_json(HOME / "persona.json", p)
427
429
  # PERSONA-AUTOHEAL(v5.54):每次成功保存"有名字"的人格,同步留一份 lastgood。
428
430
  # 这样无论哪条路径把人格写空,load_persona 都能自动回滚——不再依赖人工恢复。
431
+ # LS-027(v5.71):写回 lastgood 前执行完整结构校验!
432
+ # lastgood 是人格的最后一道网——若把带坏字段的人格快照进去,
433
+ # 空态回滚时会原样恢复坏数据。校验失败绝不留底(宁缺勿错)。
429
434
  try:
430
435
  if str(((p.get("identity") or {}).get("名字") or "")).strip():
436
+ _validate_persona_struct(p, "persona.lastgood.json")
431
437
  atomic_json(HOME / "persona.lastgood.json", p)
432
438
  except Exception:
433
439
  pass