lingshu-skill 5.14.0 → 5.18.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 +175 -0
- package/README.md +107 -1
- package/SKILL.md +3 -1
- package/assets/panel.html +13 -0
- package/cordis-plugin/lingshu-cron/plugin.js +59 -0
- package/docs/panel-api.md +106 -13
- package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +29 -0
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +13 -12
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +175 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +107 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +3 -1
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +13 -0
- package/scripts/astrbot_plugin_lingshu/engine/docs/panel-api.md +106 -13
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +60 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +54 -8
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +1381 -1180
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +5232 -5055
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +7 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +24 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +15 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/speak_up.py +186 -0
- package/scripts/cli.py +60 -0
- package/scripts/core.py +54 -8
- package/scripts/emotion.py +1381 -1180
- package/scripts/growth.py +5232 -5055
- package/scripts/memory.py +7 -0
- package/scripts/panel_server.py +24 -0
- package/scripts/panel_settings.py +15 -0
- package/scripts/speak_up.py +186 -0
|
@@ -1589,6 +1589,19 @@ def _main(argv=None) -> int:
|
|
|
1589
1589
|
p_tr.add_argument("--json", action="store_true")
|
|
1590
1590
|
|
|
1591
1591
|
# P11 #76 桌面快捷方式「灵枢面板」
|
|
1592
|
+
p_stage = sub.add_parser("stage", help="灵枢成长阶段(P2-4):蛋/幼体/少年/成年/传奇")
|
|
1593
|
+
p_stage.add_argument("--json", action="store_true")
|
|
1594
|
+
|
|
1595
|
+
p_su = sub.add_parser(
|
|
1596
|
+
"speak-up",
|
|
1597
|
+
help="主动搭话(P1-3):按概率决定灵枢要不要自己说一句(纯模板、不进模型)")
|
|
1598
|
+
p_su.add_argument("--statement", default="",
|
|
1599
|
+
help="这一轮用户的输入(用于判定是不是在提问;提问就不搭话)")
|
|
1600
|
+
p_su.add_argument("--statement-file", default="",
|
|
1601
|
+
help="从文件读这一轮用户输入(插件用:避免把文本拼进命令行)")
|
|
1602
|
+
p_su.add_argument("--force", action="store_true", help="跳过概率与冷却(验收/调试用)")
|
|
1603
|
+
p_su.add_argument("--json", action="store_true")
|
|
1604
|
+
|
|
1592
1605
|
p_tc = sub.add_parser(
|
|
1593
1606
|
"token-calib",
|
|
1594
1607
|
help="水位估算标定(盈不足/双假设法):看样本与拟合值,并与插件写入值对账")
|
|
@@ -2627,6 +2640,46 @@ def _main(argv=None) -> int:
|
|
|
2627
2640
|
print("没有删除任何东西;要清空请你自己动手。")
|
|
2628
2641
|
return 0 if res["ok"] else 1
|
|
2629
2642
|
|
|
2643
|
+
if args.cmd == "stage":
|
|
2644
|
+
import growth as _g
|
|
2645
|
+
s = _g.stage_state()
|
|
2646
|
+
if args.json:
|
|
2647
|
+
print(json.dumps(s, ensure_ascii=False, indent=2))
|
|
2648
|
+
return 0
|
|
2649
|
+
print(f"灵枢健康度:{s['label']}")
|
|
2650
|
+
print(f" 自审 {s['self_reviews']} 次 · 标签/实体覆盖 {s['coverage'] * 100:.0f}%"
|
|
2651
|
+
f" · 漂移修复过《{'是' if s['drift_fixed'] else '否'}》".replace("《", "").replace("》", ""))
|
|
2652
|
+
if s["next"]:
|
|
2653
|
+
print(" 下一步:" + ";".join(s["next"]))
|
|
2654
|
+
return 0
|
|
2655
|
+
|
|
2656
|
+
if args.cmd == "speak-up":
|
|
2657
|
+
import speak_up as _su
|
|
2658
|
+
_stmt = getattr(args, "statement", "") or ""
|
|
2659
|
+
_sf = getattr(args, "statement_file", "") or ""
|
|
2660
|
+
if _sf:
|
|
2661
|
+
try:
|
|
2662
|
+
_stmt = Path(_sf).read_text(encoding="utf-8", errors="replace")
|
|
2663
|
+
except OSError as exc:
|
|
2664
|
+
print(f"[错误] 读不了 --statement-file:{exc}", file=sys.stderr)
|
|
2665
|
+
return 1
|
|
2666
|
+
finally:
|
|
2667
|
+
# 临时文件用完即删(插件创建的,不该留在磁盘上)
|
|
2668
|
+
try:
|
|
2669
|
+
Path(_sf).unlink()
|
|
2670
|
+
except OSError:
|
|
2671
|
+
pass
|
|
2672
|
+
r = _su.maybe(_stmt,
|
|
2673
|
+
force=bool(getattr(args, "force", False)))
|
|
2674
|
+
if args.json:
|
|
2675
|
+
print(json.dumps(r, ensure_ascii=False))
|
|
2676
|
+
return 0
|
|
2677
|
+
if r.get("triggered"):
|
|
2678
|
+
print(r["text"])
|
|
2679
|
+
return 0
|
|
2680
|
+
print(f"(不搭话:{r.get('reason')})")
|
|
2681
|
+
return 0
|
|
2682
|
+
|
|
2630
2683
|
if args.cmd == "token-calib":
|
|
2631
2684
|
import token_calib as _tcal
|
|
2632
2685
|
rep = _tcal.refit(write=args.refit)
|
|
@@ -4394,6 +4447,13 @@ def _main(argv=None) -> int:
|
|
|
4394
4447
|
|
|
4395
4448
|
fails = sum(1 for _, s, _ in checks if s == "FAIL")
|
|
4396
4449
|
warns = sum(1 for _, s, _ in checks if s == "WARN")
|
|
4450
|
+
# P2-4:每次体检追加一条历史(成长阶段的"doctor 次数"就来自这里)
|
|
4451
|
+
try:
|
|
4452
|
+
import growth as _g_stage
|
|
4453
|
+
_g_stage.record_doctor_run(len(checks) - fails - warns, warns, fails,
|
|
4454
|
+
kind="doctor")
|
|
4455
|
+
except Exception: # noqa: BLE001
|
|
4456
|
+
pass
|
|
4397
4457
|
if args.json:
|
|
4398
4458
|
print(json.dumps({"checks": [{"name": n, "status": s, "detail": dt} for n, s, dt in checks],
|
|
4399
4459
|
"summary": {"pass": len(checks) - fails - warns,
|
|
@@ -347,6 +347,18 @@ DEFAULT_CONFIG = {
|
|
|
347
347
|
"use_index_memory": "auto",
|
|
348
348
|
# P1-4 Git 分支感知:remember 记下当前分支,召回时跨分支分数 ×0.5(不硬过滤)
|
|
349
349
|
"git_branch_memory": True,
|
|
350
|
+
# —— 情绪惯性(拟人化):让情绪"上来快、下去慢",不因单句话横跳 ——
|
|
351
|
+
"emotion_inertia_enabled": True, # 总开关;关掉则下面三项全部失效
|
|
352
|
+
"emotion_negative_slow": True, # 负面情绪衰减更慢("坏事记得久")
|
|
353
|
+
"emotion_negative_decay_factor": 0.8, # 负面衰减速率 = 0.8 倍 → 半衰期 ×1.25
|
|
354
|
+
"emotion_cooldown_enabled": True, # 强情绪后同组增益减半,防"越说越气"
|
|
355
|
+
"emotion_cooldown_events": 3, # 冷却窗口 = 之后 N 个情绪事件
|
|
356
|
+
"emotion_label_gate_enabled": True, # 标签要 ≥2 条情绪事件支撑才切换
|
|
357
|
+
"emotion_transition_threshold": 0.25, # 且 |Δvalence| 至少这么大
|
|
358
|
+
# P1-3 主动搭话:每轮结束按概率决定灵枢要不要自己说一句(纯模板、不进模型)。
|
|
359
|
+
# 0 = 关闭;还会受"不是提问 / 理智 >30 / 冷却 15 分钟"三道闸约束。
|
|
360
|
+
"speak_up_prob": 0.10,
|
|
361
|
+
"speak_up_cooldown_min": 15,
|
|
350
362
|
"auto_update_interval_hours": 24,
|
|
351
363
|
"session_state_cache": False,
|
|
352
364
|
"session_state_ttl": 300,
|
|
@@ -1633,7 +1645,29 @@ def _locked(path: Path, timeout: float = 10.0):
|
|
|
1633
1645
|
acquired = True
|
|
1634
1646
|
break
|
|
1635
1647
|
except FileExistsError:
|
|
1636
|
-
#
|
|
1648
|
+
# ① 孤儿锁快通道:锁里写的是**本进程 pid**,但本进程没有持有它
|
|
1649
|
+
# (_held() 已为 False 才会走到这里)→ 这是我们自己遗留的锁,立刻接管。
|
|
1650
|
+
# 否则会等满 timeout 才失败,实测能把同进程的 remember 循环卡死。
|
|
1651
|
+
try:
|
|
1652
|
+
_owner = _lock_owner(lock)
|
|
1653
|
+
_age = time.time() - lock.stat().st_mtime
|
|
1654
|
+
# 通道 A:本进程遗留的孤儿锁(含"空锁文件"——O_CREAT 与写 pid
|
|
1655
|
+
# 之间有窗口,活着的进程不会把锁空着超过宽限期)。
|
|
1656
|
+
_owner_self = (_owner == os.getpid()) or (_owner is None)
|
|
1657
|
+
# 通道 B:**持锁进程已死**。与时间无关(只要过了宽限),
|
|
1658
|
+
# 否则会撞上"STALE_LOCK_SECONDS(30) > timeout(10)"的死角:
|
|
1659
|
+
# 一次崩溃留下的锁会让后续写入连续超时,永远等不到 30 秒。
|
|
1660
|
+
_owner_dead = (_owner is not None and _owner != os.getpid()
|
|
1661
|
+
and not _pid_alive(_owner))
|
|
1662
|
+
if _age > ORPHAN_LOCK_GRACE and (_owner_self or _owner_dead):
|
|
1663
|
+
try:
|
|
1664
|
+
lock.unlink()
|
|
1665
|
+
except OSError:
|
|
1666
|
+
pass
|
|
1667
|
+
continue
|
|
1668
|
+
except OSError:
|
|
1669
|
+
pass
|
|
1670
|
+
# ② 陈旧锁(持锁进程已死):久到不可能是正常写盘(正常持锁 <2s)才接管。
|
|
1637
1671
|
# 阈值别设太小:dream 整理记忆时持锁会久一点,抢早了就是两个进程同时写。
|
|
1638
1672
|
try:
|
|
1639
1673
|
if time.time() - lock.stat().st_mtime > STALE_LOCK_SECONDS:
|
|
@@ -1671,17 +1705,24 @@ def _locked(path: Path, timeout: float = 10.0):
|
|
|
1671
1705
|
if _lock_owner(lock) == os.getpid():
|
|
1672
1706
|
_owns = True # 锁文件里确实记着自己是持有者
|
|
1673
1707
|
if _owns:
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1708
|
+
# 重试几次:Windows 上偶发共享冲突会让 unlink 抛 OSError。
|
|
1709
|
+
# 删不掉就等于留下孤儿锁,而 _HELD_LOCKS 已清 → 下次自己写会 10 秒超时。
|
|
1710
|
+
for _attempt in range(5):
|
|
1711
|
+
try:
|
|
1712
|
+
lock.unlink()
|
|
1713
|
+
break
|
|
1714
|
+
except FileNotFoundError:
|
|
1715
|
+
break # 刚被别的流程删掉:无需处理
|
|
1716
|
+
except OSError:
|
|
1717
|
+
time.sleep(0.02 * (_attempt + 1))
|
|
1680
1718
|
else:
|
|
1681
1719
|
log_event("lock", f"释放跳过:锁 {path.name} 不归本进程(pid 不符或读不到持有者)", path=path.name)
|
|
1682
1720
|
|
|
1683
1721
|
|
|
1684
1722
|
STALE_LOCK_SECONDS = 30.0
|
|
1723
|
+
# 孤儿锁宽限:锁文件写着本进程 pid 却不持有它时,等这么久才接管——
|
|
1724
|
+
# 给"刚创建、还没登记"的瞬间留窗口,又不至于让自锁死拖满 timeout。
|
|
1725
|
+
ORPHAN_LOCK_GRACE = 1.0
|
|
1685
1726
|
|
|
1686
1727
|
|
|
1687
1728
|
def _pid_alive(pid: int) -> bool:
|
|
@@ -1696,7 +1737,12 @@ def _pid_alive(pid: int) -> bool:
|
|
|
1696
1737
|
kernel32 = ctypes.windll.kernel32
|
|
1697
1738
|
h = kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, False, pid)
|
|
1698
1739
|
if not h:
|
|
1699
|
-
#
|
|
1740
|
+
# 关键区分:**进程不存在**(ERROR_INVALID_PARAMETER=87)必须判死,
|
|
1741
|
+
# 否则崩溃留下的锁永远不算陈旧,后续写入会连续超时。
|
|
1742
|
+
# 只有"权限不足/跨会话"(ERROR_ACCESS_DENIED=5 等)才保守判活。
|
|
1743
|
+
err = kernel32.GetLastError()
|
|
1744
|
+
if err == 87: # ERROR_INVALID_PARAMETER:没有这个进程
|
|
1745
|
+
return False
|
|
1700
1746
|
return True
|
|
1701
1747
|
code = ctypes.c_ulong()
|
|
1702
1748
|
ok = kernel32.GetExitCodeProcess(h, ctypes.byref(code))
|