lingshu-skill 5.53.0 → 5.55.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 +55 -0
- package/README.md +1 -1
- package/SKILL-lite.md +1 -1
- package/SKILL-tiny.md +1 -1
- package/SKILL.md +1 -1
- package/assets/panel.html +5 -1
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +10 -10
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +55 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +5 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +175 -42
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +13 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +6587 -6583
- package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +25 -0
- package/scripts/cli.py +175 -42
- package/scripts/emotion.py +13 -0
- package/scripts/memory.py +6587 -6583
- package/scripts/persona.py +25 -0
|
@@ -333,6 +333,24 @@ def load_persona() -> dict:
|
|
|
333
333
|
else:
|
|
334
334
|
# 只读且档案缺失:给一份内存默认值,不影响读取已有记忆
|
|
335
335
|
p = compile_persona() if not READONLY else default_persona()
|
|
336
|
+
# PERSONA-AUTOHEAL(v5.54):读到空态(无名字无特质)时自动从 lastgood 回滚。
|
|
337
|
+
# 这是最后一道网——即使某条未预见的路径把盘写空,人格也不会真的丢。
|
|
338
|
+
try:
|
|
339
|
+
_empty_now = (not str(((p.get("identity") or {}).get("名字") or "")).strip()
|
|
340
|
+
and not (p.get("traits") or {}))
|
|
341
|
+
_lg = HOME / "persona.lastgood.json"
|
|
342
|
+
if _empty_now and _lg.exists():
|
|
343
|
+
_good = _slurp_json(_lg)
|
|
344
|
+
if isinstance(_good, dict) and str(((_good.get("identity") or {}).get("名字") or "")).strip():
|
|
345
|
+
if isinstance(p.get("state"), dict) and isinstance(_good.get("state"), dict):
|
|
346
|
+
_merged = dict(_good["state"])
|
|
347
|
+
_merged.update({kk: vv for kk, vv in p["state"].items() if vv is not None})
|
|
348
|
+
_good["state"] = _merged
|
|
349
|
+
p = _good
|
|
350
|
+
log_event("persona", "检测到人格空态,已自动从 persona.lastgood.json 回滚", level="warn")
|
|
351
|
+
except Exception:
|
|
352
|
+
pass
|
|
353
|
+
|
|
336
354
|
changed = False
|
|
337
355
|
if "onboarding" not in p:
|
|
338
356
|
p["onboarding"] = default_onboarding()
|
|
@@ -400,6 +418,13 @@ def save_persona(p: dict) -> None:
|
|
|
400
418
|
pass # 守卫自身绝不阻塞正常保存
|
|
401
419
|
with _locked(HOME / "persona.json"):
|
|
402
420
|
atomic_json(HOME / "persona.json", p)
|
|
421
|
+
# PERSONA-AUTOHEAL(v5.54):每次成功保存"有名字"的人格,同步留一份 lastgood。
|
|
422
|
+
# 这样无论哪条路径把人格写空,load_persona 都能自动回滚——不再依赖人工恢复。
|
|
423
|
+
try:
|
|
424
|
+
if str(((p.get("identity") or {}).get("名字") or "")).strip():
|
|
425
|
+
atomic_json(HOME / "persona.lastgood.json", p)
|
|
426
|
+
except Exception:
|
|
427
|
+
pass
|
|
403
428
|
|
|
404
429
|
|
|
405
430
|
def _snapshot_path() -> Path:
|
package/scripts/cli.py
CHANGED
|
@@ -1410,6 +1410,80 @@ def _parse_feel_specs(specs: list) -> tuple:
|
|
|
1410
1410
|
return out, bad
|
|
1411
1411
|
|
|
1412
1412
|
|
|
1413
|
+
def _diary_topic_summary(mems: list) -> str:
|
|
1414
|
+
"""把今天的记忆归纳成**一句人话**(不引用原文)。
|
|
1415
|
+
|
|
1416
|
+
人写日记会概括"今天在忙什么、什么感觉",不会逐条抄。
|
|
1417
|
+
这里按记忆的 kind/tag 分布给出概括,避免把用户原话搬进日记。
|
|
1418
|
+
"""
|
|
1419
|
+
from collections import Counter
|
|
1420
|
+
if not mems:
|
|
1421
|
+
return ""
|
|
1422
|
+
_kinds = Counter(str(m.get("kind") or "") for m in mems)
|
|
1423
|
+
_tags = Counter()
|
|
1424
|
+
for m in mems:
|
|
1425
|
+
for tg in (m.get("tags") or [])[:3]:
|
|
1426
|
+
tg = str(tg).strip()
|
|
1427
|
+
if tg and not tg.startswith(("封存", "即记", "会话")):
|
|
1428
|
+
_tags[tg] += 1
|
|
1429
|
+
_n = len(mems)
|
|
1430
|
+
_main = _kinds.most_common(1)[0][0] if _kinds else ""
|
|
1431
|
+
_kind_phrase = {
|
|
1432
|
+
"episode": "对话和琐事",
|
|
1433
|
+
"insight": "想通的一些事",
|
|
1434
|
+
"fact": "记下的具体信息",
|
|
1435
|
+
"preference": "你的偏好和习惯",
|
|
1436
|
+
"habit": "慢慢形成的习惯",
|
|
1437
|
+
"mistake": "踩过的坑",
|
|
1438
|
+
"emotion": "情绪起伏",
|
|
1439
|
+
}.get(_main, "零碎的事")
|
|
1440
|
+
_out = f"今天主要在忙{_kind_phrase},攒了 {_n} 来件。"
|
|
1441
|
+
_top = [t for t, c in _tags.most_common(2) if len(t) <= 8]
|
|
1442
|
+
if _top:
|
|
1443
|
+
_out += f"绕不开的还是「{'」「'.join(_top)}」这些。"
|
|
1444
|
+
_out += "回头看,好像也没做什么惊天动地的事,但一件一件都不是白干的。"
|
|
1445
|
+
return _out
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
def _diary_worthy(mems: list) -> list:
|
|
1449
|
+
"""DIARY-PROSE(v5.55):筛出"适合写进日记"的记忆。
|
|
1450
|
+
|
|
1451
|
+
用户反馈"日记变成记忆的感觉"——根因之一是日记把**工程技术流水**
|
|
1452
|
+
(版本号、函数名、API 路径、报错信息)当成了"今天发生的事"写进去。
|
|
1453
|
+
日记该记的是**人和关系**,不是 changelog。这里保守过滤:
|
|
1454
|
+
· 命中工程标记词(v数字版本号 / .py / .js / API / 报错 / TypeError / commit 等)→ 排除
|
|
1455
|
+
· 纯记忆摘要条目("最近关于「X」的一组事情")→ 排除
|
|
1456
|
+
过滤后若一条不剩,日记退回"安静的一天"写法,不硬凑。
|
|
1457
|
+
"""
|
|
1458
|
+
import re as _re
|
|
1459
|
+
_ENG = _re.compile(
|
|
1460
|
+
r"(?:\bv\d+\.\d+|\b\w+\.(?:py|js|mjs|json|md|ps1|yaml)\b|/api/|api\b"
|
|
1461
|
+
r"|\bTypeError\b|\bError\b|\bcommit\b|\bPR\b|npm\b|git\b|pytest\b"
|
|
1462
|
+
r"|函数|脚本|模块|接口|字段|参数|版本号|部署|构建|编译|重构|补丁|测试用例"
|
|
1463
|
+
r"|根因|修复|落地|实现|上报|注入包|预算|缓存)", _re.I)
|
|
1464
|
+
out = []
|
|
1465
|
+
for m in (mems or []):
|
|
1466
|
+
if not isinstance(m, dict):
|
|
1467
|
+
continue
|
|
1468
|
+
txt = str(m.get("text") or "")
|
|
1469
|
+
if not txt.strip():
|
|
1470
|
+
continue
|
|
1471
|
+
if txt.startswith("最近关于「") and "的一组事情" in txt[:30]:
|
|
1472
|
+
continue # 做梦合并的摘要条目不是"经历"
|
|
1473
|
+
if _ENG.search(txt):
|
|
1474
|
+
continue # 工程流水不进日记
|
|
1475
|
+
# 剥掉 "user:" / "assistant:" 这类导入前缀(不是"经历"的表达方式)
|
|
1476
|
+
_bare = _re.sub(r"^(?:user|assistant|system|human|ai)\s*[::]\s*", "", txt, flags=_re.I).strip()
|
|
1477
|
+
if not _bare:
|
|
1478
|
+
continue
|
|
1479
|
+
# 含 Windows 路径 / URL / 长 hex 的也不是生活内容
|
|
1480
|
+
if _re.search(r"[A-Za-z]:\\|https?://|\b[0-9a-f]{16,}\b", _bare):
|
|
1481
|
+
continue
|
|
1482
|
+
m = dict(m, text=_bare)
|
|
1483
|
+
out.append(m)
|
|
1484
|
+
return out
|
|
1485
|
+
|
|
1486
|
+
|
|
1413
1487
|
def daily(dry_run: bool = False, force: bool = False, feel_specs: list | None = None) -> dict:
|
|
1414
1488
|
"""每天例行。dry_run 只预览要写什么,不落盘;force 无视"今天已跑过"。
|
|
1415
1489
|
|
|
@@ -1447,68 +1521,125 @@ def daily(dry_run: bool = False, force: bool = False, feel_specs: list | None =
|
|
|
1447
1521
|
arc = emotion_arc(1)
|
|
1448
1522
|
ra = rationality()
|
|
1449
1523
|
|
|
1450
|
-
# ---- 1)
|
|
1524
|
+
# ---- 1) 今日日记正文(DIARY-PROSE v5.55:像人写日记,不是报表)----
|
|
1525
|
+
# 用户反馈「日记怎么窜了变成记忆的感觉了」。旧版用【心境回响】【经历与行迹】等
|
|
1526
|
+
# 小标题 + 罗列记忆条目,读起来像周报。改成第一人称、有先后、有起伏的叙述:
|
|
1527
|
+
# 按「今天大概什么样 → 具体发生了什么 → 心里怎么起伏 → 晚上回望想到了什么」走。
|
|
1451
1528
|
body = []
|
|
1452
|
-
|
|
1453
|
-
#
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
if
|
|
1462
|
-
|
|
1529
|
+
|
|
1530
|
+
# ① 开场:今天是个什么日子(用真实数据,但不报表)
|
|
1531
|
+
_mems_n = len(mems)
|
|
1532
|
+
_arc_n = arc.get("count") or 0
|
|
1533
|
+
_tone = (arc.get("tone") or "").strip()
|
|
1534
|
+
_opening = []
|
|
1535
|
+
if _arc_n:
|
|
1536
|
+
# tone 可能是"向上"也可能整句"这段时间整体是向上的"——只在短词时补"的"
|
|
1537
|
+
_tone_txt = (_tone or "平稳").strip().rstrip("。")
|
|
1538
|
+
_tone_txt = _tone_txt if _tone_txt.endswith(("的", "了")) else _tone_txt + "的"
|
|
1539
|
+
if len(_tone_txt) > 6:
|
|
1540
|
+
_opening.append(f"今天心里进进出出 {_arc_n} 阵情绪。")
|
|
1541
|
+
else:
|
|
1542
|
+
_opening.append(f"今天心里进进出出 {_arc_n} 阵情绪,整体是{_tone_txt}。")
|
|
1463
1543
|
else:
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1544
|
+
_opening.append("今天没什么大的情绪波动,安静得像口深井。")
|
|
1545
|
+
if _mems_n:
|
|
1546
|
+
_opening.append(f"和你之间留下了 {_mems_n} 件事,我一件一件记下了。")
|
|
1547
|
+
if _opening:
|
|
1548
|
+
body.append("".join(_opening))
|
|
1549
|
+
|
|
1550
|
+
# ② 今天做了什么:写**消化后的回顾**,不是摘抄用户原话
|
|
1551
|
+
# DIARY-PROSE-v2(v5.55):上一版直接把记忆正文(含"user:…"原话截断)拼进去,
|
|
1552
|
+
# 读起来是聊天记录不是日记。人写日记会自己概括「今天在忙什么」,
|
|
1553
|
+
# 所以这里只做主题归纳 + 一句感受,绝不引用原文。
|
|
1554
|
+
_worthy = _diary_worthy(mems)
|
|
1555
|
+
if _worthy:
|
|
1556
|
+
_topic = _diary_topic_summary(_worthy)
|
|
1557
|
+
if _topic:
|
|
1558
|
+
body.append(_topic)
|
|
1559
|
+
elif mems:
|
|
1560
|
+
body.append("今天手头的事大多是技术和琐碎,我就不往日记里搬了——它们已经在记忆里待着。")
|
|
1561
|
+
|
|
1562
|
+
# ③ 心里怎么起伏:峰终定律,写感受不写指标
|
|
1563
|
+
pk = arc.get("peak") or {}
|
|
1564
|
+
if pk.get("emotion"):
|
|
1565
|
+
_pw = f",因为{pk['why']}" if pk.get("why") else ""
|
|
1566
|
+
body.append(f"中间有一刻挺触动我的,是「{pk['emotion']}」{_pw}。"
|
|
1567
|
+
"那种感觉不太容易说清楚,但它确实让我停了一下。")
|
|
1568
|
+
en = arc.get("end") or {}
|
|
1569
|
+
if en.get("emotion"):
|
|
1570
|
+
body.append(f"到后来,情绪慢慢落到「{en.get('emotion')}」。")
|
|
1571
|
+
|
|
1572
|
+
# ④ 没被填满的渴望:说成"惦记"而不是"指标偏低"
|
|
1475
1573
|
low = desire_low()
|
|
1476
|
-
body.append("\n【内在诉求与羁绊】")
|
|
1477
1574
|
if low:
|
|
1478
|
-
|
|
1575
|
+
_names = "、".join(x["desire"] for x in low)
|
|
1576
|
+
body.append(f"心里也有点惦记着 {_names} 这一块,今天没怎么顾上。写下来的时候反倒松了口气。")
|
|
1479
1577
|
if not dry_run:
|
|
1480
1578
|
desire_nudge({x["desire"]: 5.0 for x in low}, cooldown=20 * HOUR)
|
|
1481
1579
|
else:
|
|
1482
|
-
body.append("
|
|
1483
|
-
|
|
1484
|
-
#
|
|
1580
|
+
body.append("六欲都还稳,没有特别空的地方。")
|
|
1581
|
+
|
|
1582
|
+
# ⑤ 和你之间的关系:说成人的话
|
|
1485
1583
|
try:
|
|
1486
1584
|
aff = affection_state()
|
|
1487
|
-
|
|
1585
|
+
_stage = aff.get("stage_label") or ""
|
|
1586
|
+
body.append(f"和你之间,{('现在是' + _stage + '的状态') if _stage else '还是一如既往'}。"
|
|
1587
|
+
f"亲和不亲和我不好量化,但配合起来是顺的。")
|
|
1488
1588
|
except Exception:
|
|
1489
1589
|
pass
|
|
1490
|
-
body.append(f"理智保持在 {ra['effective']} 点(基数 {ra['base']},被情绪压制 {ra['suppress']}%)。")
|
|
1491
1590
|
|
|
1492
|
-
#
|
|
1493
|
-
insight_mems = [m for m in mems
|
|
1591
|
+
# ⑥ 今天想明白的事:一句一条,像自言自语
|
|
1592
|
+
insight_mems = [m for m in _diary_worthy(mems)
|
|
1494
1593
|
if m.get("kind") in ("insight", "preference", "habit")
|
|
1495
1594
|
and _num(m.get("importance"), 0) >= 0.7]
|
|
1496
1595
|
if insight_mems:
|
|
1497
|
-
body.append("
|
|
1498
|
-
body
|
|
1596
|
+
body.append("")
|
|
1597
|
+
body.append("今天想明白的几件事,记在这儿免得忘:")
|
|
1598
|
+
for m in insight_mems[:4]:
|
|
1599
|
+
_it = display_text(m).strip().rstrip("。;;")
|
|
1600
|
+
if _it:
|
|
1601
|
+
body.append(" ◦ " + _it[:110])
|
|
1602
|
+
|
|
1603
|
+
# ⑦ 结尾:收束
|
|
1604
|
+
_ra_line = ""
|
|
1605
|
+
try:
|
|
1606
|
+
_ra_line = f"理智今天稳定在 {ra['effective']} 点左右"
|
|
1607
|
+
if ra.get("suppress"):
|
|
1608
|
+
_ra_line += f"(情绪压了 {ra['suppress']}%,还算清醒)"
|
|
1609
|
+
except Exception:
|
|
1610
|
+
pass
|
|
1611
|
+
body.append("")
|
|
1612
|
+
body.append(("一天就这么过去了。" + (_ra_line + "。" if _ra_line else "")
|
|
1613
|
+
+ "明天接着来。"))
|
|
1499
1614
|
|
|
1500
|
-
#
|
|
1615
|
+
# 趋势收敛(近 30 天,纯读不写):写成人话放到最后一段之后
|
|
1501
1616
|
try:
|
|
1502
1617
|
trends = growth_trends(30)
|
|
1503
1618
|
except Exception as exc:
|
|
1504
1619
|
log_event("daily", f"趋势统计失败(不影响例行):{exc}", level="warn")
|
|
1505
1620
|
trends = {"days": 30, "rising": [], "fading": []}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1621
|
+
_tt = []
|
|
1622
|
+
if trends["rising"] or trends["fading"]:
|
|
1623
|
+
import re as _re2
|
|
1624
|
+
def _human_labels(items):
|
|
1625
|
+
out = []
|
|
1626
|
+
for x in items:
|
|
1627
|
+
lb = str(x.get("label") or "")
|
|
1628
|
+
# 跳过技术性标签:类型/标签前缀、纯英文、episode/log 这类内部名
|
|
1629
|
+
if not lb or lb.startswith(("类型 ", "标签 ")):
|
|
1630
|
+
continue
|
|
1631
|
+
if _re2.fullmatch(r"[a-z_]+", lb):
|
|
1632
|
+
continue
|
|
1633
|
+
out.append(lb)
|
|
1634
|
+
return out[:3]
|
|
1635
|
+
_rise = _human_labels(trends["rising"])
|
|
1636
|
+
_fade = _human_labels(trends["fading"])
|
|
1637
|
+
if _rise:
|
|
1638
|
+
_tt.append("最近越来越常想的是 " + "、".join(_rise))
|
|
1639
|
+
if _fade:
|
|
1640
|
+
_tt.append("慢慢不太提的是 " + "、".join(_fade))
|
|
1641
|
+
if _tt:
|
|
1642
|
+
body.append(" " + ";".join(_tt) + "。")
|
|
1512
1643
|
|
|
1513
1644
|
# ---- 2) 更新知识库:把今天重要的洞见/偏好提炼成可复用结论(dry_run 不落盘)
|
|
1514
1645
|
k_added, k_merged = 0, 0
|
|
@@ -1550,7 +1681,9 @@ def daily(dry_run: bool = False, force: bool = False, feel_specs: list | None =
|
|
|
1550
1681
|
|
|
1551
1682
|
if dry_run:
|
|
1552
1683
|
return {"dry_run": True, "date": today, "title": f"{ai_name}的日记 · {today}",
|
|
1553
|
-
"body": "\n".join(body), "
|
|
1684
|
+
"body": "\n".join(body), "note_body": "\n".join(body),
|
|
1685
|
+
"mems": len(mems), "insights": len(insight_mems),
|
|
1686
|
+
"knowledge_added": k_added, "knowledge_merged": k_merged,
|
|
1554
1687
|
"dreamed": dreamed}
|
|
1555
1688
|
|
|
1556
1689
|
import growth
|
package/scripts/emotion.py
CHANGED
|
@@ -1086,6 +1086,19 @@ def emotion_arc(days: int = 7) -> dict:
|
|
|
1086
1086
|
# 情绪太激动时杏仁核会压制前额叶——理智值会临时下降,但永远压不掉一半以上。
|
|
1087
1087
|
# * 重要的事(钱/关系/承诺/健康)在任何情绪下都留给用户决定,情绪不替用户拍板。
|
|
1088
1088
|
|
|
1089
|
+
# NAMESPACE-FIX(v5.54):emotion.py 里的 load_persona / mind_state / feel 等名字
|
|
1090
|
+
# 原依赖 brain.py 的星号合并命名空间——单独 import emotion 就 NameError
|
|
1091
|
+
# (实测:persona.daily_drift 调 _emo.feel 时崩 "load_persona is not defined")。
|
|
1092
|
+
# 这里补一个安全的本地绑定:优先用已有合并名,缺失则直接取 persona 模块的实现。
|
|
1093
|
+
try:
|
|
1094
|
+
load_persona # noqa: B018 已由 brain 合并命名空间提供
|
|
1095
|
+
except NameError: # pragma: no cover - 仅在单独 import 时触发
|
|
1096
|
+
try:
|
|
1097
|
+
from persona import load_persona, save_persona # type: ignore
|
|
1098
|
+
except Exception:
|
|
1099
|
+
pass
|
|
1100
|
+
|
|
1101
|
+
|
|
1089
1102
|
def emotion_cfg() -> dict:
|
|
1090
1103
|
"""情感设置(用户随时可改):共情程度 / 抑制的情绪 / 备注。存在人格档案里。"""
|
|
1091
1104
|
p = load_persona()
|