lingshu-skill 5.17.0 → 5.19.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 +123 -0
- package/README.md +48 -1
- package/SKILL.md +2 -1
- package/assets/panel.html +3 -1
- package/cordis-plugin/lingshu-cron/plugin.js +2 -2
- package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +14 -0
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +13 -13
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +123 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +48 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +2 -1
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +3 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/brain.py +60 -46
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +80 -9
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +98 -19
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +1381 -1180
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +26 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +110 -12
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_cloud.py +610 -609
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +12 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +12 -0
- package/scripts/brain.py +60 -46
- package/scripts/cli.py +80 -9
- package/scripts/core.py +98 -19
- package/scripts/emotion.py +1381 -1180
- package/scripts/growth.py +26 -1
- package/scripts/memory.py +110 -12
- package/scripts/panel_cloud.py +610 -609
- package/scripts/panel_server.py +12 -0
- package/scripts/panel_settings.py +12 -0
|
@@ -3524,6 +3524,26 @@ def _tag_coverage() -> float:
|
|
|
3524
3524
|
return good / len(rows)
|
|
3525
3525
|
|
|
3526
3526
|
|
|
3527
|
+
def health_score(passed: int = 0, warned: int = 0, failed: int = 0,
|
|
3528
|
+
failures_7d: int | None = None) -> dict:
|
|
3529
|
+
"""健康度分数(0~100)+ 扣分明细。参数没给就取最近一次体检历史。"""
|
|
3530
|
+
if failures_7d is None:
|
|
3531
|
+
failures_7d = _recent_failures(7)
|
|
3532
|
+
if not (passed or warned or failed):
|
|
3533
|
+
hist = [r for r in doctor_history() if str(r.get("kind") or "doctor") == "doctor"]
|
|
3534
|
+
if hist:
|
|
3535
|
+
last = hist[-1]
|
|
3536
|
+
passed = int(last.get("pass") or 0)
|
|
3537
|
+
warned = int(last.get("warn") or 0)
|
|
3538
|
+
failed = int(last.get("fail") or 0)
|
|
3539
|
+
score = 100 - int(failed) * 10 - int(warned) * 3 - int(failures_7d) // 5
|
|
3540
|
+
score = max(0, min(100, score))
|
|
3541
|
+
return {"score": score, "pass": int(passed), "warn": int(warned),
|
|
3542
|
+
"fail": int(failed), "failures_7d": int(failures_7d),
|
|
3543
|
+
"deduct": {"fail": int(failed) * 10, "warn": int(warned) * 3,
|
|
3544
|
+
"failures": int(failures_7d) // 5}}
|
|
3545
|
+
|
|
3546
|
+
|
|
3527
3547
|
def stage_state() -> dict:
|
|
3528
3548
|
"""算出当前成长阶段 + 依据(面板/CLI 都读它)。"""
|
|
3529
3549
|
hist = doctor_history()
|
|
@@ -3587,9 +3607,14 @@ def stage_state() -> dict:
|
|
|
3587
3607
|
# 跑了不少次却还在"蛋":明说是被 failures 卡住,不是没在记录
|
|
3588
3608
|
if stage == "蛋" and doc_runs >= 5:
|
|
3589
3609
|
label += "·卡在 failures"
|
|
3610
|
+
try:
|
|
3611
|
+
_health = health_score(failures_7d=fails)
|
|
3612
|
+
except Exception: # noqa: BLE001
|
|
3613
|
+
_health = None
|
|
3590
3614
|
return {"stage": stage, "doctor_runs": doc_runs, "self_reviews": self_reviews,
|
|
3591
3615
|
"failures_7d": fails, "coverage": round(cov, 3),
|
|
3592
|
-
"drift_fixed": drift_fixed, "next": need, "label": label
|
|
3616
|
+
"drift_fixed": drift_fixed, "next": need, "label": label,
|
|
3617
|
+
"health": _health}
|
|
3593
3618
|
|
|
3594
3619
|
|
|
3595
3620
|
def release_drift() -> dict:
|
|
@@ -31,6 +31,14 @@ def detect_conflicts(limit: int = 50) -> list:
|
|
|
31
31
|
records = load_all()
|
|
32
32
|
by_entity: dict[str, list] = {}
|
|
33
33
|
for m in records:
|
|
34
|
+
# 做梦聚合条目是派生视图(把一批记忆压成一段摘要),与原记忆天然"一正一反",
|
|
35
|
+
# 那不是矛盾、是同一批数据的两种表示。它们早已被排除在注入/审核之外,
|
|
36
|
+
# 冲突检测这里也要同样跳过,否则会稳定产出一条假 WARN。
|
|
37
|
+
try:
|
|
38
|
+
if _is_dream_aggregate(m.get("text", "")):
|
|
39
|
+
continue
|
|
40
|
+
except Exception: # noqa: BLE001
|
|
41
|
+
pass
|
|
34
42
|
for ent in (m.get("entities") or []):
|
|
35
43
|
by_entity.setdefault(str(ent), []).append(m)
|
|
36
44
|
|
|
@@ -168,6 +176,11 @@ def ai_persona_changes(days: int = 7) -> list:
|
|
|
168
176
|
# 或 to 是"未过门限/未变/撞在边界上"这类说明文字而非实际新值
|
|
169
177
|
if "(" in field:
|
|
170
178
|
continue
|
|
179
|
+
# 运行时状态(state.mood_score / state.energy / state.closeness …)不算"改人格":
|
|
180
|
+
# 它们是每天按记忆情感倾向自动漂移的数值,有独立的 drift/mood 观测渠道。
|
|
181
|
+
# 记进来只会让 audit 永远挂着一条假 WARN,还稀释真正的人格改动。
|
|
182
|
+
if field.startswith("state."):
|
|
183
|
+
continue
|
|
171
184
|
if isinstance(to, str) and ("未过门限" in to or "未变" in to or "边界" in to):
|
|
172
185
|
continue
|
|
173
186
|
# 优先看 source 字段(比 why 可靠);用户自己说的(初识回答、手动编辑、
|
|
@@ -976,6 +989,82 @@ def boost(memory_id: str) -> dict:
|
|
|
976
989
|
"stability": found["stability"], "old_stability": old_s}
|
|
977
990
|
|
|
978
991
|
|
|
992
|
+
# ---------------------------------------------------------------- 情绪驱动的记忆权重(P2-3)
|
|
993
|
+
# 「记仇」效应:让用户委屈/生气的事更重、更容易被想起。这不是玄学——
|
|
994
|
+
# 情绪记忆的巩固强度本来就高于中性记忆(amygdala 调制,McGaugh 2004)。
|
|
995
|
+
EMO_TOUCH_FIELD = "_touched_by_emotion" # 历次情绪影响的权重列表
|
|
996
|
+
EMO_TOUCH_STEP = 0.06 # 每次负面情绪给 importance 的增量
|
|
997
|
+
EMO_TOUCH_MAX = 0.30 # 累计增量上限(防一条被反复顶到 1.0)
|
|
998
|
+
EMO_TOUCH_NEG_MAX_VALENCE = -0.3 # 只对 valence < 这个值(够负面)生效
|
|
999
|
+
EMO_TOUCH_MIN_INTENSITY = 0.1 # 且强度不低于这个(太弱的不管)
|
|
1000
|
+
EMO_RECALL_BOOST = 0.3 # recall 时的加成系数
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
def touch_by_emotion(memory_id: str, valence: float, intensity: float) -> dict:
|
|
1004
|
+
"""一条记忆被"有分量的负面情绪"牵动时,提升它的 importance(P2-3)。
|
|
1005
|
+
|
|
1006
|
+
返回 {"ok", "changed", "importance", "delta"}。非负面 / 太弱 / 找不到一律不动,
|
|
1007
|
+
返回 changed=False 且给 reason——**不静默瞎改**。
|
|
1008
|
+
持锁 + 锁内重读:这是整库覆写路径,锁外做会吞掉并发写入。
|
|
1009
|
+
"""
|
|
1010
|
+
try:
|
|
1011
|
+
v = float(valence)
|
|
1012
|
+
i = float(intensity)
|
|
1013
|
+
except (TypeError, ValueError):
|
|
1014
|
+
return {"ok": False, "changed": False, "reason": "valence/intensity 不是数字"}
|
|
1015
|
+
if v > EMO_TOUCH_NEG_MAX_VALENCE:
|
|
1016
|
+
return {"ok": True, "changed": False, "reason": "不够负面(valence 高于阈值)"}
|
|
1017
|
+
if i < EMO_TOUCH_MIN_INTENSITY:
|
|
1018
|
+
return {"ok": True, "changed": False, "reason": "情绪太弱(intensity 低于阈值)"}
|
|
1019
|
+
if READONLY:
|
|
1020
|
+
return {"ok": False, "changed": False, "reason": "记忆库只读"}
|
|
1021
|
+
mid = str(memory_id or "").strip()
|
|
1022
|
+
if not mid:
|
|
1023
|
+
return {"ok": False, "changed": False, "reason": "没有 memory_id"}
|
|
1024
|
+
with _locked(HOME / "hippocampus.jsonl"):
|
|
1025
|
+
records = load_all()
|
|
1026
|
+
found = next((m for m in records if str(m.get("id") or "") == mid), None)
|
|
1027
|
+
if found is None:
|
|
1028
|
+
return {"ok": False, "changed": False, "reason": f"找不到记忆 {mid}"}
|
|
1029
|
+
marks = list(found.get(EMO_TOUCH_FIELD) or [])
|
|
1030
|
+
used = sum(abs(_num(x, 0)) for x in marks)
|
|
1031
|
+
# 累计增量封顶:同一条被反复牵动也不无限抬 importance
|
|
1032
|
+
room = max(0.0, EMO_TOUCH_MAX - used)
|
|
1033
|
+
delta = min(EMO_TOUCH_STEP, room)
|
|
1034
|
+
if delta <= 0:
|
|
1035
|
+
return {"ok": True, "changed": False,
|
|
1036
|
+
"reason": "情绪权重已到上限", "importance": _num(found.get("importance"), 0.5)}
|
|
1037
|
+
old = _num(found.get("importance"), 0.5)
|
|
1038
|
+
found["importance"] = round(max(0.0, min(1.0, old + delta)), 3)
|
|
1039
|
+
# 记下本次影响(限长,避免字段无界增长)
|
|
1040
|
+
marks.append(round(abs(v) * max(0.0, min(1.0, i)), 3))
|
|
1041
|
+
found[EMO_TOUCH_FIELD] = marks[-20:]
|
|
1042
|
+
save_all(records)
|
|
1043
|
+
try:
|
|
1044
|
+
log_event("emotion", f"情绪加权 {mid}:importance {old:.2f} → "
|
|
1045
|
+
f"{found['importance']:.2f}(valence {v:.2f})")
|
|
1046
|
+
except Exception: # noqa: BLE001
|
|
1047
|
+
pass
|
|
1048
|
+
return {"ok": True, "changed": True, "importance": found["importance"],
|
|
1049
|
+
"delta": round(delta, 3)}
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
def _emo_boost_of(m: dict) -> float:
|
|
1053
|
+
"""recall 用的情绪加成系数:按 `_touched_by_emotion` 均值算。
|
|
1054
|
+
|
|
1055
|
+
没有该字段返回 0(老记忆完全不受影响)。
|
|
1056
|
+
"""
|
|
1057
|
+
marks = m.get(EMO_TOUCH_FIELD)
|
|
1058
|
+
if not isinstance(marks, list) or not marks:
|
|
1059
|
+
return 0.0
|
|
1060
|
+
vals = [_num(x, 0) for x in marks]
|
|
1061
|
+
vals = [v for v in vals if v > 0]
|
|
1062
|
+
if not vals:
|
|
1063
|
+
return 0.0
|
|
1064
|
+
avg = sum(vals) / len(vals)
|
|
1065
|
+
return max(0.0, min(1.0, avg)) * EMO_RECALL_BOOST
|
|
1066
|
+
|
|
1067
|
+
|
|
979
1068
|
def set_frozen(memory_id: str, frozen: bool = True) -> dict:
|
|
980
1069
|
"""#28 冻结 / 解冻单条记忆。
|
|
981
1070
|
|
|
@@ -986,18 +1075,22 @@ def set_frozen(memory_id: str, frozen: bool = True) -> dict:
|
|
|
986
1075
|
raise PermissionError("记忆库当前只读,无法冻结/解冻。")
|
|
987
1076
|
ensure_home()
|
|
988
1077
|
mid = str(memory_id or "").strip()
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
found
|
|
998
|
-
|
|
999
|
-
found
|
|
1000
|
-
|
|
1078
|
+
# 必须持锁:load_all → 改 → save_all 是**整库覆写**,锁外做会把并发写入
|
|
1079
|
+
# (另一进程/线程的 remember、面板请求、cron)新增的记录整片覆盖丢失。
|
|
1080
|
+
# 与 forget / bulk_memory_action / set_memory_review 同口径。
|
|
1081
|
+
with _locked(HOME / "hippocampus.jsonl"):
|
|
1082
|
+
records = load_all()
|
|
1083
|
+
found = next((m for m in records if str(m.get("id") or "") == mid), None)
|
|
1084
|
+
if not found:
|
|
1085
|
+
raise LookupError(f"没找到记忆 {mid}(活跃层与淡忘区都搜过了)。")
|
|
1086
|
+
if bool(found.get("frozen")) == bool(frozen):
|
|
1087
|
+
return {"ok": True, "id": mid, "frozen": bool(frozen), "changed": False}
|
|
1088
|
+
found["frozen"] = bool(frozen)
|
|
1089
|
+
if frozen:
|
|
1090
|
+
found["frozen_at"] = now_ts()
|
|
1091
|
+
else:
|
|
1092
|
+
found.pop("frozen_at", None)
|
|
1093
|
+
save_all(records)
|
|
1001
1094
|
audit_log("user", "freeze" if frozen else "unfreeze", mid, "冻结,不参与召回/注入" if frozen else "解冻")
|
|
1002
1095
|
log_event("memory", f"{'冻结' if frozen else '解冻'}了 {mid}")
|
|
1003
1096
|
return {"ok": True, "id": mid, "frozen": bool(frozen), "changed": True}
|
|
@@ -2252,6 +2345,11 @@ def recall(query: str, k: int = 8, layers: tuple = ("cortex", "hippo"),
|
|
|
2252
2345
|
# 原 age_boost 字段保留在 debug 里,但不再参与乘法压分。
|
|
2253
2346
|
age_days = (now - _num(m.get("created"), now)) / DAY
|
|
2254
2347
|
# (以上保留 age_days 只是给下方 age_boost debug 用,不乘进 score)
|
|
2348
|
+
# P2-3 情绪权重:被"有分量的负面情绪"牵动过的记忆,按影响均值给 importance 加成
|
|
2349
|
+
# (老记忆没有该字段 → 加成 0,行为完全不变)。
|
|
2350
|
+
_emo = _emo_boost_of(m)
|
|
2351
|
+
if _emo > 0:
|
|
2352
|
+
score *= (1.0 + _emo)
|
|
2255
2353
|
# P1-4 分支感知:跨分支记忆降权 50%(不硬过滤——别的分支的结论仍可能有用,
|
|
2256
2354
|
# 只是排在当前分支之后)。两边都有分支才比,任一侧为空就不动。
|
|
2257
2355
|
if _cur_branch:
|