lingshu-skill 5.54.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/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) 今日日记正文��JRN-01 升级为第一人称自省心流叙事)
1524
+ # ---- 1) 今日日记正文(DIARY-PROSE v5.55:像人写日记,不是报表)----
1525
+ # 用户反馈「日记怎么窜了变成记忆的感觉了」。旧版用【心境回响】【经历与行迹】等
1526
+ # 小标题 + 罗列记忆条目,读起来像周报。改成第一人称、有先后、有起伏的叙述:
1527
+ # 按「今天大概什么样 → 具体发生了什么 → 心里怎么起伏 → 晚上回望想到了什么」走。
1451
1528
  body = []
1452
-
1453
- # 篇首心境与见闻故事线
1454
- if arc["count"]:
1455
- top_txt = "、".join("{}×{}".format(x["emotion"], x["times"]) for x in arc["top"])
1456
- body.append(f"【心境回响】回顾这一天,心里的主色调是「{arc['tone']}」。情绪起伏共 {arc['count']} 次,其中出现最多的是 {top_txt}。")
1457
- pk, en = arc.get("peak") or {}, arc.get("end") or {}
1458
- if pk.get("emotion"):
1459
- pw = f"——事由:{pk['why']}" if pk.get("why") else ""
1460
- body.append(f"· 触动最深的一刻:当时内心泛起了强烈的「{pk['emotion']}」(强度 {float(pk.get('intensity', 0)):.0%}){pw}。")
1461
- if en.get("emotion"):
1462
- body.append(f"· 夜阑收官心境:随着对话告一段落,情绪慢慢落定在「{en['emotion']}」。")
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
- body.append("【心境回响】今天整体波澜不惊,情绪处在平静的蓄能期,没有产生剧烈的波动。")
1465
-
1466
- # 今日与用户的互动事件沉淀
1467
- body.append(f"\n【经历与行迹】今天与你并肩留下了 {len(mems)} 条记忆印记。")
1468
- if mems:
1469
- # 挑选今日重要度高、有代表性的经历
1470
- sample_mems = sorted(mems, key=lambda m: _num(m.get("importance"), 0.5), reverse=True)[:4]
1471
- for sm in sample_mems:
1472
- body.append(f"· {display_text(sm)[:90]}")
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
- body.append("察觉到心里有些没被填满的渴望:" + "、".join(f"{x['desire']}(当前低至 {x['level']:.0f})" for x in low) + "。但写下这些本身就是一次觉察,心中的波澜正在慢慢抚平。")
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
- body.append(f"当前的感情底色为:亲和度 {aff.get('affinity', 60):.0f},信任度 {aff.get('trust', 65):.0f}({aff.get('summary', '')})。")
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("\n【今日顿悟与沉淀】今天让我反复琢磨、值得记下的想法:")
1498
- body += [f"- {display_text(m)}" for m in insight_mems[:5]]
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
- # ---- 五-H:趋势收敛(近 30 天标签/类型走向,纯读不写)----
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
- if trends["rising"]:
1507
- body.append("这阵子在变强的倾向:" + "、".join(
1508
- f"{x['label']}({x['old']}→{x['new']})" for x in trends["rising"]) + "。")
1509
- if trends["fading"]:
1510
- body.append("这阵子在淡化的倾向:" + "、".join(
1511
- f"{x['label']}({x['old']}→{x['new']})" for x in trends["fading"]) + "。")
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), "mems": len(mems), "insights": len(insight_mems),
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