lingshu-skill 5.10.0 → 5.14.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 +120 -0
- package/README.md +69 -3
- package/SKILL.md +3 -1
- package/assets/panel.html +133 -7
- package/docs//345/200/237/351/211/264/345/276/205/345/212/236-DSH/346/217/222/344/273/266/347/224/237/346/200/201.md +224 -0
- package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +26 -1
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +12 -12
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +120 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +69 -3
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +3 -1
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +133 -7
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +49 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +7 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +75 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +5055 -4759
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +305 -16
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +131 -7
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +6 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_update.py +38 -9
- package/scripts/cli.py +49 -3
- package/scripts/core.py +7 -0
- package/scripts/emotion.py +75 -1
- package/scripts/growth.py +5055 -4759
- package/scripts/memory.py +305 -16
- package/scripts/panel_server.py +131 -7
- package/scripts/panel_settings.py +6 -0
- package/scripts/panel_update.py +38 -9
|
@@ -27,24 +27,51 @@ def enabled() -> bool:
|
|
|
27
27
|
return bool(_cfg().get("auto_update"))
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def
|
|
31
|
-
"""
|
|
30
|
+
def _normalize(res: dict) -> dict:
|
|
31
|
+
"""把 growth.update_check 的字段名补成调用方好用的别名,**不改原字段**。
|
|
32
|
+
|
|
33
|
+
历史坑:run() 判断的是 `update_available`,而 update_check 返回的是 `outdated`,
|
|
34
|
+
于是自动更新永远走"已是最新"分支——功能等于没接上。
|
|
35
|
+
"""
|
|
36
|
+
if not isinstance(res, dict):
|
|
37
|
+
return res
|
|
38
|
+
if "update_available" not in res:
|
|
39
|
+
res["update_available"] = bool(res.get("outdated"))
|
|
40
|
+
res.setdefault("current", res.get("installed_version"))
|
|
41
|
+
res.setdefault("latest", res.get("source_version") or res.get("version"))
|
|
42
|
+
return res
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def check(force_pull: bool = False, source: str | None = None) -> dict:
|
|
46
|
+
"""查有没有新版本(只读)。`source` 可强制 "npm" / "git"。"""
|
|
32
47
|
import growth
|
|
33
48
|
try:
|
|
34
|
-
|
|
49
|
+
if source:
|
|
50
|
+
# 强制指定源时先把它解析出来(顺带把"能不能拿到"这件事暴露给调用方)
|
|
51
|
+
src, kind = growth.resolve_source("lingshu", force_pull=force_pull,
|
|
52
|
+
prefer=source)
|
|
53
|
+
res = growth.update_check("lingshu", force_pull=force_pull,
|
|
54
|
+
prefer=source)
|
|
55
|
+
if isinstance(res, dict):
|
|
56
|
+
res["source"] = kind
|
|
57
|
+
res["source_kind"] = kind
|
|
58
|
+
res["target_path"] = str(src)
|
|
59
|
+
return _normalize(res)
|
|
60
|
+
return _normalize(growth.update_check("lingshu", force_pull=force_pull,
|
|
61
|
+
prefer=source))
|
|
35
62
|
except Exception as exc: # noqa: BLE001
|
|
36
63
|
core.log_event("update", f"检查更新失败:{exc}", level="warn")
|
|
37
64
|
return {"ok": False, "error": str(exc)}
|
|
38
65
|
|
|
39
66
|
|
|
40
|
-
def run(force: bool = False) -> dict:
|
|
41
|
-
"""
|
|
67
|
+
def run(force: bool = False, source: str | None = None) -> dict:
|
|
68
|
+
"""执行一次自动更新(含更新前备份)。`source` 可强制 "npm" / "git"。"""
|
|
42
69
|
if core.READONLY:
|
|
43
70
|
return {"ok": False, "reason": "记忆库只读,跳过自动更新"}
|
|
44
71
|
if not force and not enabled():
|
|
45
72
|
return {"ok": False, "skipped": True, "reason": "auto_update 未开启"}
|
|
46
73
|
|
|
47
|
-
chk = check(force_pull=True)
|
|
74
|
+
chk = check(force_pull=True, source=source)
|
|
48
75
|
if not chk or not chk.get("update_available"):
|
|
49
76
|
return {"ok": True, "skipped": True,
|
|
50
77
|
"reason": "已是最新", "current": chk.get("current"),
|
|
@@ -67,15 +94,17 @@ def run(force: bool = False) -> dict:
|
|
|
67
94
|
# ② 原子更新
|
|
68
95
|
try:
|
|
69
96
|
import growth
|
|
70
|
-
src, kind = growth.resolve_source("lingshu", force_pull=False
|
|
97
|
+
src, kind = growth.resolve_source("lingshu", force_pull=False,
|
|
98
|
+
prefer=source)
|
|
71
99
|
res = growth.install_skill("lingshu", force=True, from_dir=str(src))
|
|
72
100
|
except Exception as exc: # noqa: BLE001
|
|
73
101
|
core.log_event("update", f"自动更新失败:{exc}", level="error")
|
|
74
102
|
return {"ok": False, "reason": f"更新失败(已回滚):{exc}", "backup": bak}
|
|
75
103
|
|
|
76
|
-
core.log_event("update", f"
|
|
77
|
-
f"
|
|
104
|
+
core.log_event("update", f"自动更新完成(来源 {chk.get('source') or 'auto'}):"
|
|
105
|
+
f"{chk.get('current')} → {chk.get('latest')};更新前备份 {bak}")
|
|
78
106
|
return {"ok": True, "updated": True, "backup": bak,
|
|
107
|
+
"source": chk.get("source") or "auto",
|
|
79
108
|
"from": chk.get("current"), "to": chk.get("latest"),
|
|
80
109
|
"detail": res if isinstance(res, dict) else str(res),
|
|
81
110
|
"at": int(time.time())}
|
package/scripts/cli.py
CHANGED
|
@@ -1608,6 +1608,9 @@ def _main(argv=None) -> int:
|
|
|
1608
1608
|
p_au.add_argument("--check", action="store_true", help="只检查有没有新版本,不安装")
|
|
1609
1609
|
p_au.add_argument("--force", action="store_true", help="忽略 auto_update 开关强制执行一次")
|
|
1610
1610
|
p_au.add_argument("--json", action="store_true")
|
|
1611
|
+
p_au.add_argument("--source", choices=["auto", "npm", "git"], default="auto",
|
|
1612
|
+
help="下载源:auto(npm 优先,失败退回 Gitee/GitHub)/ npm(只走 npm)/ "
|
|
1613
|
+
"git(只走 Gitee/GitHub)")
|
|
1611
1614
|
|
|
1612
1615
|
# 附录 C P2 收尾:触发 + 落盘 + 回滚
|
|
1613
1616
|
p_ss = sub.add_parser("session-summary",
|
|
@@ -1974,6 +1977,10 @@ def _main(argv=None) -> int:
|
|
|
1974
1977
|
"shape-audit", help="六爻位体检(只读):64 格状态分布 + 当位/得中/有应违规")
|
|
1975
1978
|
p_shape.add_argument("--limit", type=int, default=2000)
|
|
1976
1979
|
p_shape.add_argument("--json", action="store_true")
|
|
1980
|
+
p_show = mem_sub.add_parser(
|
|
1981
|
+
"show", help="按 id 看整条记忆(支持唯一前缀/短号;索引法注入后取正文用这个)")
|
|
1982
|
+
p_show.add_argument("id", help="完整 id、hash 段前缀(8 位)或 m_ 短号")
|
|
1983
|
+
p_show.add_argument("--json", action="store_true")
|
|
1977
1984
|
mem_sub.add_parser("trash-list", help="看软删除台账(purge 删掉的记忆留底,可恢复)")
|
|
1978
1985
|
p_mem_tr = mem_sub.add_parser("trash-restore", help="从软删除台账恢复一条记忆")
|
|
1979
1986
|
p_mem_tr.add_argument("id", help="记忆 id")
|
|
@@ -2655,15 +2662,17 @@ def _main(argv=None) -> int:
|
|
|
2655
2662
|
|
|
2656
2663
|
if args.cmd == "auto-update":
|
|
2657
2664
|
import panel_update as _pu
|
|
2665
|
+
_src = None if args.source == "auto" else args.source
|
|
2658
2666
|
if args.check:
|
|
2659
|
-
res = _pu.check(force_pull=True)
|
|
2667
|
+
res = _pu.check(force_pull=True, source=_src)
|
|
2660
2668
|
if args.json:
|
|
2661
2669
|
print(json.dumps(res, ensure_ascii=False, indent=2))
|
|
2662
2670
|
return 0
|
|
2663
2671
|
print(f"当前 {res.get('current')} / 最新 {res.get('latest')} "
|
|
2672
|
+
f"(来源 {res.get('source') or 'auto'})"
|
|
2664
2673
|
f"→ {'有新版可更新' if res.get('update_available') else '已是最新'}")
|
|
2665
2674
|
return 0
|
|
2666
|
-
res = _pu.run(force=args.force)
|
|
2675
|
+
res = _pu.run(force=args.force, source=_src)
|
|
2667
2676
|
if args.json:
|
|
2668
2677
|
print(json.dumps(res, ensure_ascii=False, indent=2))
|
|
2669
2678
|
return 0 if res.get("ok") else 1
|
|
@@ -2671,7 +2680,8 @@ def _main(argv=None) -> int:
|
|
|
2671
2680
|
print(f"跳过:{res.get('reason')}")
|
|
2672
2681
|
return 0
|
|
2673
2682
|
if res.get("ok"):
|
|
2674
|
-
print(f"
|
|
2683
|
+
print(f"已更新(来源 {res.get('source') or 'auto'}):"
|
|
2684
|
+
f"{res.get('from')} → {res.get('to')};更新前备份 {res.get('backup')}")
|
|
2675
2685
|
return 0
|
|
2676
2686
|
print(f"[错误] {res.get('reason')}", file=sys.stderr)
|
|
2677
2687
|
return 1
|
|
@@ -4366,6 +4376,22 @@ def _main(argv=None) -> int:
|
|
|
4366
4376
|
except Exception as e:
|
|
4367
4377
|
checks.append(("desktop-shortcut", "WARN", f"自检失败:{e}"))
|
|
4368
4378
|
|
|
4379
|
+
# v5.12:把本次体检结果追加到 doctor-history.jsonl——灵枢自己的成长账本,
|
|
4380
|
+
# 面板"体检历史"页签和未来的健康度分数用它。append-only,单条 try/except 吞掉。
|
|
4381
|
+
try:
|
|
4382
|
+
_dr = {
|
|
4383
|
+
"ts": int(time.time()),
|
|
4384
|
+
"fails": sum(1 for _, s, _ in checks if s == "FAIL"),
|
|
4385
|
+
"warns": sum(1 for _, s, _ in checks if s == "WARN"),
|
|
4386
|
+
"passes": sum(1 for _, s, _ in checks if s == "PASS"),
|
|
4387
|
+
"checks": {n: s for n, s, _ in checks},
|
|
4388
|
+
}
|
|
4389
|
+
_dh_path = (globals().get("brain") or sys.modules.get("brain")).HOME / "doctor-history.jsonl"
|
|
4390
|
+
with open(_dh_path, "a", encoding="utf-8") as _fh:
|
|
4391
|
+
_fh.write(json.dumps(_dr, ensure_ascii=False) + "\n")
|
|
4392
|
+
except Exception as _e:
|
|
4393
|
+
brain.log_event("doctor", f"doctor-history 追加失败:{_e}", level="warn")
|
|
4394
|
+
|
|
4369
4395
|
fails = sum(1 for _, s, _ in checks if s == "FAIL")
|
|
4370
4396
|
warns = sum(1 for _, s, _ in checks if s == "WARN")
|
|
4371
4397
|
if args.json:
|
|
@@ -5168,6 +5194,26 @@ def _main(argv=None) -> int:
|
|
|
5168
5194
|
if r["frozen"]:
|
|
5169
5195
|
print(" 冻结后不参与召回/启动注入/做梦合并,用 show 仍可查看;解冻立即恢复。")
|
|
5170
5196
|
return 0
|
|
5197
|
+
# 按 id 取整条记忆(索引法注入后取正文的正路;支持唯一前缀)
|
|
5198
|
+
if mem_cmd == "show":
|
|
5199
|
+
import memory as _mem
|
|
5200
|
+
r = _mem.fetch(args.id)
|
|
5201
|
+
if not r.get("ok"):
|
|
5202
|
+
print(f"[错误] {r.get('reason')}", file=sys.stderr)
|
|
5203
|
+
return 1
|
|
5204
|
+
m = r["memory"]
|
|
5205
|
+
if args.json:
|
|
5206
|
+
print(json.dumps(m, ensure_ascii=False, indent=2))
|
|
5207
|
+
return 0
|
|
5208
|
+
print(f"{m.get('id')} [{m.get('layer')}] {m.get('kind')} "
|
|
5209
|
+
f"★{_num(m.get('importance'), 0.5) * 5:.0f}")
|
|
5210
|
+
if m.get("index"):
|
|
5211
|
+
print(f" 索引:{m['index']}")
|
|
5212
|
+
print(f" {display_text(m)}")
|
|
5213
|
+
if m.get("tags"):
|
|
5214
|
+
print(f" 标签:{'、'.join(m['tags'])}")
|
|
5215
|
+
return 0
|
|
5216
|
+
|
|
5171
5217
|
# 六爻位体检(只读):把六元特征映射到 64 格,用当位/得中/有应判结构
|
|
5172
5218
|
if mem_cmd == "shape-audit":
|
|
5173
5219
|
import shape_audit as _sa
|
package/scripts/core.py
CHANGED
|
@@ -340,6 +340,13 @@ DEFAULT_CONFIG = {
|
|
|
340
340
|
# 面板空闲多少分钟自动退出(0 = 永不)。页面挂着长轮询保活(不受后台定时器节流影响),
|
|
341
341
|
# 关掉网页后连接断开 → 到点自退。默认 1 分钟:关掉尽快回收,不占后台。
|
|
342
342
|
"panel_idle_minutes": 1,
|
|
343
|
+
# 更新下载源:auto=npm 优先(失败退回 Gitee/GitHub)/ npm=只走 npm / git=只走 Gitee/GitHub
|
|
344
|
+
"update_source": "auto",
|
|
345
|
+
# 索引法记忆(P1-1):注入只送"一句索引 + id",正文用 recall 取。
|
|
346
|
+
# auto=水位≥60% 才切(默认,水位低时仍给全文)/ always=一律切 / off=关
|
|
347
|
+
"use_index_memory": "auto",
|
|
348
|
+
# P1-4 Git 分支感知:remember 记下当前分支,召回时跨分支分数 ×0.5(不硬过滤)
|
|
349
|
+
"git_branch_memory": True,
|
|
343
350
|
"auto_update_interval_hours": 24,
|
|
344
351
|
"session_state_cache": False,
|
|
345
352
|
"session_state_ttl": 300,
|
package/scripts/emotion.py
CHANGED
|
@@ -1177,4 +1177,78 @@ def emotion_mirror(user_emotion: str, intensity: float = 0.5, what: str = "") ->
|
|
|
1177
1177
|
ev = feel(_pick_emotion_by_appraisal(_detect_polarity(ue), imp), intensity=imp,
|
|
1178
1178
|
why=f"共情:用户在说「{ue[:40]}」", about="用户", genesis=True)
|
|
1179
1179
|
note = f"顺着用户的感受起了「{ev['emotion']}」({ev['intensity']:.0%})"
|
|
1180
|
-
return {"level": level, "mirrored": ev, "mood": mood_now(), "note": note}
|
|
1180
|
+
return {"level": level, "mirrored": ev, "mood": mood_now(), "note": note}
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
def inner_voice() -> str:
|
|
1184
|
+
"""内心独白:灵枢此刻对自己的简短态度评价(≤30 字,纯模板 + 词表,不调 LLM)。
|
|
1185
|
+
|
|
1186
|
+
设计原则:
|
|
1187
|
+
- 不能太长——侧栏里一行小字,30 字封顶;
|
|
1188
|
+
- 不能太啰嗦——按 storm / suppress / valence / intensity 挑模板,别做复杂拼接;
|
|
1189
|
+
- 不能太准确——模板是"大概的感觉",不是精断,保持拟人感;
|
|
1190
|
+
- 没有情绪记录时返回空字符串(面板据此隐藏,不瞎编)。
|
|
1191
|
+
"""
|
|
1192
|
+
m = mood_now()
|
|
1193
|
+
if not m.get("active"):
|
|
1194
|
+
return ""
|
|
1195
|
+
ra = rationality()
|
|
1196
|
+
storm = bool(m.get("storm")) or bool(ra.get("storm"))
|
|
1197
|
+
suppress = _num(ra.get("suppress"), 0)
|
|
1198
|
+
valence = _num(m.get("valence"), 0)
|
|
1199
|
+
intensity = _num(m.get("intensity"), 0)
|
|
1200
|
+
label = m.get("label", "平静")
|
|
1201
|
+
|
|
1202
|
+
# 优先级 1:情绪上头 → 诚实说"脑子不清楚"
|
|
1203
|
+
if storm:
|
|
1204
|
+
if valence < -0.2:
|
|
1205
|
+
return "情绪有点炸,先别急着下结论"
|
|
1206
|
+
return "有点上头,理智被压住了"
|
|
1207
|
+
|
|
1208
|
+
# 优先级 2:理智被情绪压住 ≥ 20% → 诚实说"被压住了"
|
|
1209
|
+
if suppress >= 20:
|
|
1210
|
+
return f"情绪在捣乱,脑子不太清楚"
|
|
1211
|
+
|
|
1212
|
+
# 优先级 3:按 valence 和 intensity 挑模板
|
|
1213
|
+
if valence >= 0.25 and intensity >= 0.3:
|
|
1214
|
+
if label in ("开心", "愉快", "平和"):
|
|
1215
|
+
return f"心情{label},想多聊一会儿"
|
|
1216
|
+
return "心情不错,可以多说几句"
|
|
1217
|
+
if valence <= -0.25 and intensity >= 0.3:
|
|
1218
|
+
if label in ("失落", "低落", "烦躁", "焦虑"):
|
|
1219
|
+
return f"心情{label},别逼我太快"
|
|
1220
|
+
return "有点低落,想静静"
|
|
1221
|
+
if intensity >= 0.5:
|
|
1222
|
+
return f"此刻是{label},有点强烈"
|
|
1223
|
+
|
|
1224
|
+
# 优先级 4:平静 / 低强度 → 一句话带过
|
|
1225
|
+
if label == "平静" or intensity < 0.1:
|
|
1226
|
+
return "情绪没波动,随时可以聊"
|
|
1227
|
+
|
|
1228
|
+
return f"此刻是{label},还行"
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
def emotion_timeline(limit: int = 50) -> list:
|
|
1232
|
+
"""心情流水:取最近 limit 条 genesis 事件(自动生成的 / 共情的 / 认知评价的),
|
|
1233
|
+
每条带时间、标签、强度、分类、简短原因——面板 emotion 页签的心情时间线用。
|
|
1234
|
+
|
|
1235
|
+
为什么只取 genesis=True:
|
|
1236
|
+
- 用户手动 emotion feel 调出来的不算"流水",是主动触发;
|
|
1237
|
+
- mood_now / mood_ema 内部 feel 出来的也不算 genesis。
|
|
1238
|
+
所以 genesis=True 基本就是"自动生成、反映真实对话 / 共情 / 评价"的那些事件,
|
|
1239
|
+
这才是用户想看的心情变化。
|
|
1240
|
+
"""
|
|
1241
|
+
rows = [r for r in emotion_events(limit=limit * 3) if r.get("genesis")]
|
|
1242
|
+
rows = rows[:limit]
|
|
1243
|
+
return [
|
|
1244
|
+
{
|
|
1245
|
+
"ts": r.get("ts", 0),
|
|
1246
|
+
"time": fmt_time(r.get("ts", 0)) if _num(r.get("ts"), 0) else "",
|
|
1247
|
+
"label": r.get("emotion", ""),
|
|
1248
|
+
"intensity": round(_num(r.get("intensity"), 0), 2),
|
|
1249
|
+
"category": r.get("category", ""),
|
|
1250
|
+
"why": (r.get("why") or "")[:80],
|
|
1251
|
+
"about": r.get("about", ""),
|
|
1252
|
+
}
|
|
1253
|
+
for r in rows
|
|
1254
|
+
]
|