lingshu-skill 5.42.0 → 5.43.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.
@@ -341,6 +341,24 @@ def load_persona() -> dict:
341
341
 
342
342
 
343
343
  def save_persona(p: dict) -> None:
344
+ # 空人格写盘守卫(2026-12-03 两次清空事故加固):
345
+ # 盘上已有完整人格(有名字)时,拒绝用 identity+traits 双空的默认态覆盖——
346
+ # 除非是 init --force 的显式重置(调用方传 _allow_empty=True 绕过)。
347
+ # 竞态窗口(测试进程写空态、后台做梦并发 save)由此被彻底堵死。
348
+ try:
349
+ _path = HOME / "persona.json"
350
+ if _path.exists():
351
+ _disk = _slurp_json(_path) or {}
352
+ _disk_named = bool(((_disk.get("identity") or {}).get("名字") or "").strip())
353
+ _incoming_named = bool(((p.get("identity") or {}).get("名字") or "").strip())
354
+ if _disk_named and not _incoming_named and not p.get("_allow_empty"):
355
+ log_event("persona",
356
+ "拒绝保存:盘上人格有名字而待写入人格为空态——疑似竞态覆盖,已拦下。"
357
+ "若确要重置请用 brain.py init --force(自带备份)。",
358
+ level="error")
359
+ return
360
+ except Exception:
361
+ pass # 守卫自身绝不阻塞正常保存
344
362
  with _locked(HOME / "persona.json"):
345
363
  atomic_json(HOME / "persona.json", p)
346
364