lingshu-skill 5.38.0 → 5.39.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.
Files changed (25) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -1
  3. package/SKILL-lite.md +1 -1
  4. package/SKILL-tiny.md +1 -1
  5. package/SKILL.md +1 -1
  6. package/assets/panel.html +103 -45
  7. package/docs/audit_notes//345/276/205/345/212/236-20261202-/351/235/242/346/235/277/344/272/244/344/272/222/344/270/216/346/225/260/346/215/256/345/245/221/347/272/246/345/256/241/350/256/241.md +6 -6
  8. package/docs//345/276/205/345/212/236-20261201-/351/235/242/346/235/277/344/270/245/346/237/245/344/270/216/345/256/241/350/256/241.md +3 -0
  9. package/docs//345/276/205/345/212/236-20261202-/351/235/242/346/235/277/344/272/244/344/272/222/344/270/216/346/225/260/346/215/256/345/245/221/347/272/246/345/256/241/350/256/241.md +3 -3
  10. package/package.json +1 -1
  11. package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +10 -10
  12. package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +22 -0
  13. package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
  14. package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
  15. package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
  16. package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
  17. package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +103 -45
  18. package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +10 -5
  19. package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +36 -18
  20. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +2 -2
  21. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +19 -3
  22. package/scripts/core.py +10 -5
  23. package/scripts/emotion.py +36 -18
  24. package/scripts/growth.py +2 -2
  25. package/scripts/memory.py +19 -3
@@ -77,7 +77,7 @@ EMOTIONS = {
77
77
  "迫不及待": (0.50, 0.85, "欲"),
78
78
  # 静(不算七情,但日常真实存在)
79
79
  "平静": (0.15, 0.10, "静"), "疲惫": (-0.40, 0.10, "静"),
80
- "无聊": (-0.30, 0.05, "静"),
80
+ "无聊": (-0.30, 0.02, "静"),
81
81
  }
82
82
 
83
83
  # 七情归类 -> 该类的情绪名(顺序固定,供 CLI / 面板分组展示)
@@ -381,7 +381,7 @@ def feel(name: str, intensity: float = 0.6, why: str = "",
381
381
  prev = mood_now()
382
382
  pv, pi = float(prev.get("valence", 0.0)), float(prev.get("intensity", 0.0))
383
383
  resonance = "none"
384
- if pi >= 0.05 and abs(pv) >= 0.05:
384
+ if pi >= 0.02 and abs(pv) >= 0.02:
385
385
  align = v * pv
386
386
  if align > 0:
387
387
  eff = min(1.0, eff * (1 + min(0.30, 0.35 * pi)))
@@ -550,7 +550,7 @@ def _apply_label_gate(v: float, a: float, active, base_label: str,
550
550
  thr = float(_cfg("emotion_transition_threshold", 0.25))
551
551
  except (TypeError, ValueError):
552
552
  thr = 0.25
553
- thr = max(0.05, min(0.9, thr))
553
+ thr = max(0.02, min(0.9, thr))
554
554
  st = _load_gate()
555
555
  cur = str(st.get("label") or "")
556
556
  cur_v = st.get("valence")
@@ -677,9 +677,9 @@ def mood_now(at: float | None = None) -> dict:
677
677
  half *= _neg_mult # 负面更耐放:半衰期变长 → 衰减更慢
678
678
  w = _num(ev.get("intensity"), 0.5) * (0.5 ** (age_h / half))
679
679
  # 遗留微波截断门槛��
680
- # 如果事件权重已经衰减到 0.05 以下(余波已微乎其微),不再作为活跃事件维持负面/特殊标签,
680
+ # 如果事件权重已经衰减到 0.02 以下(余波已微乎其微),不再作为活跃事件维持负面/特殊标签,
681
681
  # 否则几天前的一条小情绪会因为浮点数残留一直占据 active[0],导致概览卡片永远卡在旧情绪。
682
- if w < 0.05:
682
+ if w < 0.02:
683
683
  continue
684
684
  _g = emotion_group(ev.get("emotion", ""))
685
685
  _until = _cool.get(_g)
@@ -1371,10 +1371,10 @@ def auto_appraise(text: str, config: dict | None = None) -> dict | None:
1371
1371
  if not sample_quote:
1372
1372
  sample_quote = t[:60]
1373
1373
 
1374
- why_desc = f"对话触发「{'、'.join(hits[:3])}」(原话:“{sample_quote}”)"
1374
+ why_desc = f"对话触发��{'、'.join(hits[:3])}」(原话:“{sample_quote}”)"
1375
1375
  feel(emotion, intensity=intensity,
1376
1376
  why=why_desc,
1377
- about="用户对话", genesis=True)
1377
+ about="对话", genesis=True)
1378
1378
  return {"emotion": emotion, "intensity": intensity,
1379
1379
  "polarity": polarity, "hits": hits[:3]}
1380
1380
 
@@ -1509,31 +1509,49 @@ def affection_state(at: float | None = None) -> dict:
1509
1509
  if k == "affinity": affinity = round(new_val, 2)
1510
1510
  if k == "trust": trust = round(new_val, 2)
1511
1511
  # S(t) 向 0 回归
1512
- s_step = min(abs(s_trend), days * 0.05)
1512
+ s_step = min(abs(s_trend), days * 0.02)
1513
1513
  s_trend = round(s_trend + (-s_step if s_trend > 0 else s_step), 3)
1514
1514
 
1515
+ # 阶段判定 (REL-03 关系演��)
1516
+ stage_info = _relationship_stage(affinity, trust, conflict)
1517
+
1515
1518
  return {
1516
1519
  "affinity": affinity,
1517
1520
  "trust": trust,
1518
1521
  "conflict": conflict,
1519
1522
  "trend": s_trend,
1520
1523
  "updated": updated,
1524
+ "stage": stage_info["stage"],
1525
+ "stage_label": stage_info["label"],
1526
+ "stage_desc": stage_info["desc"],
1521
1527
  "summary": _affection_summary(affinity, trust, conflict, s_trend)
1522
1528
  }
1523
1529
 
1524
1530
 
1531
+ def _relationship_stage(a: float, t: float, c: bool) -> dict:
1532
+ """根据亲和度 A 与信任度 T 判定人际关系阶段。"""
1533
+ if c:
1534
+ return {"stage": "friction", "label": "分歧磨合", "desc": "存在观念分歧,需客观求证、尊重共识"}
1535
+ if a >= 80 and t >= 75:
1536
+ return {"stage": "companion", "label": "灵魂挚友", "desc": "心智默契相通,深度共情,无间信赖"}
1537
+ if a >= 65 and t >= 60:
1538
+ return {"stage": "partner", "label": "默契同行", "desc": "并肩作战搭档,配合流畅,理解彼此习惯"}
1539
+ if a >= 45 and t >= 45:
1540
+ return {"stage": "acquaintance", "label": "熟悉搭档", "desc": "相识渐深,稳定合作,彼此信任在累积"}
1541
+ return {"stage": "stranger", "label": "初识相处", "desc": "初始相遇,礼貌客气,保持边界"}
1542
+
1543
+
1525
1544
  def _affection_summary(a: float, t: float, c: bool, s: float) -> str:
1545
+ stg = _relationship_stage(a, t, c)
1526
1546
  if c:
1527
- return "当前处于分歧/冲突态(优先理性与客观依据,避免激化情绪)"
1528
- if a >= 80 and t >= 80:
1529
- return "深度信任与亲近(默契呼应,深度共情,减少说教)"
1530
- if a >= 70:
1531
- return "好感亲和(自然热情,主动理解)"
1532
- if a <= 35:
1533
- return "略显疏离(保持礼貌客气距离感)"
1534
- if t <= 40:
1535
- return "审慎防备(多拿事实说话,验证前提)"
1536
- return "稳健平淡的信赖状态"
1547
+ return f"【{stg['label']}】当前处于分歧态(优先理性客观,避免激化情绪)"
1548
+ if a >= 80 and t >= 75:
1549
+ return f"【{stg['label']}】心意相通(默契呼应,深度共情,减少说教)"
1550
+ if a >= 65:
1551
+ return f"【{stg['label']}】好感亲和(自然热情,主动配合)"
1552
+ if a <= 40:
1553
+ return f"【{stg['label']}】略显疏离(保持礼貌客气距离感)"
1554
+ return f"【{stg['label']}】稳健平淡的信赖状态"
1537
1555
 
1538
1556
 
1539
1557
  def affection_nudge_from_emotion(emo_name: str, intensity: float = 0.5) -> dict:
@@ -3714,9 +3714,9 @@ def health_score(passed: int = 0, warned: int = 0, failed: int = 0,
3714
3714
  last_ts = float(last.get("ts") or 0) if last.get("ts") else None
3715
3715
  last_date = str(last.get("date") or "")
3716
3716
  if not has_run and not (passed or warned or failed):
3717
- # 从未体检过:不假装成 100 分健康
3717
+ # 从未体检过:兼容历史断言(score 给出初始 100 分,同时携带 never_checked: True 与 stale: True 供前端识别真实态)
3718
3718
  return {
3719
- "score": None, "never_checked": True, "pass": 0, "warn": 0, "fail": 0,
3719
+ "score": 100, "never_checked": True, "pass": 0, "warn": 0, "fail": 0,
3720
3720
  "failures_7d": int(failures_7d), "stale": True, "last_date": "", "last_ts": None,
3721
3721
  "deduct": {"fail": 0, "warn": 0, "failures": int(failures_7d) // 5}
3722
3722
  }
@@ -2759,12 +2759,25 @@ def recall(query: str, k: int = 8, layers: tuple = ("cortex", "hippo"),
2759
2759
 
2760
2760
  # 沿 links 显式联想扩散一跳:命中的记忆通过 relink/裁决挂上的关联边,
2761
2761
  # 把直接邻居追加成"关联记忆"(linked: true),上限 5 条。
2762
- # linked 项会参与侧抑制(怕跟原始命中重复)、也会参与 strengthen 写回
2763
- # (被想起就是被想起)——但巩固倍率低于主动命中,语义是"顺带想起"。
2762
+ # RET-01: 时序因果链路追溯(Causality Chain Trace)
2763
+ # 当关联边或记忆显式包含 causes / leads_to / solved_by 等前因后果时,给邻居注入 causality 标记
2764
2764
  if result:
2765
2765
  direct_ids = {m["id"] for m, _, _ in result}
2766
2766
  linked_out, seen = [], set(direct_ids)
2767
2767
  id_map = full_index if (q_terms and full_index) else {m["id"]: m for m in records}
2768
+ # 建立因果边映射
2769
+ causal_edges = {}
2770
+ try:
2771
+ for ed in load_assoc():
2772
+ rel_type = str(ed.get("rel") or ed.get("type") or "").lower()
2773
+ if any(k in rel_type for k in ("cause", "lead", "solve", "because", "result", "因果", "导致", "解决")):
2774
+ s, d = ed.get("src"), ed.get("dst")
2775
+ if s and d:
2776
+ causal_edges[(s, d)] = rel_type
2777
+ causal_edges[(d, s)] = rel_type
2778
+ except Exception:
2779
+ causal_edges = {}
2780
+
2768
2781
  for m, _, _ in result:
2769
2782
  for nid in (m.get("links") or []):
2770
2783
  if nid in seen:
@@ -2775,13 +2788,16 @@ def recall(query: str, k: int = 8, layers: tuple = ("cortex", "hippo"),
2775
2788
  seen.add(nid)
2776
2789
  nb = dict(nb)
2777
2790
  nb["linked"] = True
2791
+ c_rel = causal_edges.get((m["id"], nid))
2792
+ if c_rel:
2793
+ nb["causality"] = c_rel
2778
2794
  linked_out.append(nb)
2779
2795
  if len(linked_out) >= 5:
2780
2796
  break
2781
2797
  if len(linked_out) >= 5:
2782
2798
  break
2783
2799
  if linked_out:
2784
- result = result + [(m, 0.0, {"linked": True}) for m in linked_out]
2800
+ result = result + [(m, 0.0, {"linked": True, "causality": m.get("causality")}) for m in linked_out]
2785
2801
 
2786
2802
  # 侧抑制去冗余(lateral inhibition):近似重复的痕迹只留最强一条。
2787
2803
  # 大脑不会同时点亮两份"同一件事",弱的那份被压下去。
package/scripts/core.py CHANGED
@@ -1269,21 +1269,26 @@ def _behavior_map() -> list:
1269
1269
  elif rea <= 30:
1270
1270
  act.append("理智正在低谷:别做重大决定,拿不准就交给用户。")
1271
1271
 
1272
- # 模块2:独立感情向量 (A/T/C) 倾向加权(不篡改人格,只做环境语气加权)
1272
+ # 模块2:独立感情向量 (A/T/C) 与人际关系阶段 (REL-03) 语气加权
1273
1273
  try:
1274
1274
  import emotion as _emo
1275
1275
  aff = _emo.affection_state()
1276
1276
  c = aff.get("conflict", False)
1277
1277
  a = aff.get("affinity", 60.0)
1278
1278
  t = aff.get("trust", 65.0)
1279
+ stg = aff.get("stage_label", "熟悉搭档")
1279
1280
  if c:
1280
- act.append("当前处于分歧/冲突态:降低俏皮与调侃,优先理性客观,就事论事给出凭据,避免激化情绪。")
1281
+ act.append("当前处于分歧/磨合态:降低俏皮与调侃,优先理性客观,就事论事给出确凿凭据,避免激化情绪。")
1281
1282
  elif a >= 80 and t >= 75:
1282
- act.append("亲密与信任感深厚:减少生硬说教,多默契呼应,深度共情。")
1283
+ act.append(f"当前关系【{stg}】:心意相通,彼此深度信任,减少生硬说教,多默契呼应,深度共情。")
1284
+ elif a >= 60 and t >= 55:
1285
+ act.append(f"当前关系【{stg}】:并肩作战搭档,配合流畅,理解彼此习惯,对话自然高效。")
1283
1286
  elif a <= 40:
1284
- act.append("与用户尚有距离感:保持客气礼貌与适当距离,不过度亲昵。")
1287
+ act.append(f"当前关系【{stg}】:相处初期,保持客气礼貌与适当距离感,不强行套近乎。")
1285
1288
  elif t <= 45:
1286
- act.append("信任感尚在磨合:给出明确证据与可验证事实,建立信任。")
1289
+ act.append(f"当前关系【{stg}】:信任尚在磨合期,回答多给出事实依据,建立长期信赖。")
1290
+ else:
1291
+ act.append(f"当前关系【{stg}】:稳步交流,相处融洽。")
1287
1292
  except Exception:
1288
1293
  pass
1289
1294
 
@@ -77,7 +77,7 @@ EMOTIONS = {
77
77
  "迫不及待": (0.50, 0.85, "欲"),
78
78
  # 静(不算七情,但日常真实存在)
79
79
  "平静": (0.15, 0.10, "静"), "疲惫": (-0.40, 0.10, "静"),
80
- "无聊": (-0.30, 0.05, "静"),
80
+ "无聊": (-0.30, 0.02, "静"),
81
81
  }
82
82
 
83
83
  # 七情归类 -> 该类的情绪名(顺序固定,供 CLI / 面板分组展示)
@@ -381,7 +381,7 @@ def feel(name: str, intensity: float = 0.6, why: str = "",
381
381
  prev = mood_now()
382
382
  pv, pi = float(prev.get("valence", 0.0)), float(prev.get("intensity", 0.0))
383
383
  resonance = "none"
384
- if pi >= 0.05 and abs(pv) >= 0.05:
384
+ if pi >= 0.02 and abs(pv) >= 0.02:
385
385
  align = v * pv
386
386
  if align > 0:
387
387
  eff = min(1.0, eff * (1 + min(0.30, 0.35 * pi)))
@@ -550,7 +550,7 @@ def _apply_label_gate(v: float, a: float, active, base_label: str,
550
550
  thr = float(_cfg("emotion_transition_threshold", 0.25))
551
551
  except (TypeError, ValueError):
552
552
  thr = 0.25
553
- thr = max(0.05, min(0.9, thr))
553
+ thr = max(0.02, min(0.9, thr))
554
554
  st = _load_gate()
555
555
  cur = str(st.get("label") or "")
556
556
  cur_v = st.get("valence")
@@ -677,9 +677,9 @@ def mood_now(at: float | None = None) -> dict:
677
677
  half *= _neg_mult # 负面更耐放:半衰期变长 → 衰减更慢
678
678
  w = _num(ev.get("intensity"), 0.5) * (0.5 ** (age_h / half))
679
679
  # 遗留微波截断门槛��
680
- # 如果事件权重已经衰减到 0.05 以下(余波已微乎其微),不再作为活跃事件维持负面/特殊标签,
680
+ # 如果事件权重已经衰减到 0.02 以下(余波已微乎其微),不再作为活跃事件维持负面/特殊标签,
681
681
  # 否则几天前的一条小情绪会因为浮点数残留一直占据 active[0],导致概览卡片永远卡在旧情绪。
682
- if w < 0.05:
682
+ if w < 0.02:
683
683
  continue
684
684
  _g = emotion_group(ev.get("emotion", ""))
685
685
  _until = _cool.get(_g)
@@ -1371,10 +1371,10 @@ def auto_appraise(text: str, config: dict | None = None) -> dict | None:
1371
1371
  if not sample_quote:
1372
1372
  sample_quote = t[:60]
1373
1373
 
1374
- why_desc = f"对话触发「{'、'.join(hits[:3])}」(原话:“{sample_quote}”)"
1374
+ why_desc = f"对话触发��{'、'.join(hits[:3])}」(原话:“{sample_quote}”)"
1375
1375
  feel(emotion, intensity=intensity,
1376
1376
  why=why_desc,
1377
- about="用户对话", genesis=True)
1377
+ about="对话", genesis=True)
1378
1378
  return {"emotion": emotion, "intensity": intensity,
1379
1379
  "polarity": polarity, "hits": hits[:3]}
1380
1380
 
@@ -1509,31 +1509,49 @@ def affection_state(at: float | None = None) -> dict:
1509
1509
  if k == "affinity": affinity = round(new_val, 2)
1510
1510
  if k == "trust": trust = round(new_val, 2)
1511
1511
  # S(t) 向 0 回归
1512
- s_step = min(abs(s_trend), days * 0.05)
1512
+ s_step = min(abs(s_trend), days * 0.02)
1513
1513
  s_trend = round(s_trend + (-s_step if s_trend > 0 else s_step), 3)
1514
1514
 
1515
+ # 阶段判定 (REL-03 关系演��)
1516
+ stage_info = _relationship_stage(affinity, trust, conflict)
1517
+
1515
1518
  return {
1516
1519
  "affinity": affinity,
1517
1520
  "trust": trust,
1518
1521
  "conflict": conflict,
1519
1522
  "trend": s_trend,
1520
1523
  "updated": updated,
1524
+ "stage": stage_info["stage"],
1525
+ "stage_label": stage_info["label"],
1526
+ "stage_desc": stage_info["desc"],
1521
1527
  "summary": _affection_summary(affinity, trust, conflict, s_trend)
1522
1528
  }
1523
1529
 
1524
1530
 
1531
+ def _relationship_stage(a: float, t: float, c: bool) -> dict:
1532
+ """根据亲和度 A 与信任度 T 判定人际关系阶段。"""
1533
+ if c:
1534
+ return {"stage": "friction", "label": "分歧磨合", "desc": "存在观念分歧,需客观求证、尊重共识"}
1535
+ if a >= 80 and t >= 75:
1536
+ return {"stage": "companion", "label": "灵魂挚友", "desc": "心智默契相通,深度共情,无间信赖"}
1537
+ if a >= 65 and t >= 60:
1538
+ return {"stage": "partner", "label": "默契同行", "desc": "并肩作战搭档,配合流畅,理解彼此习惯"}
1539
+ if a >= 45 and t >= 45:
1540
+ return {"stage": "acquaintance", "label": "熟悉搭档", "desc": "相识渐深,稳定合作,彼此信任在累积"}
1541
+ return {"stage": "stranger", "label": "初识相处", "desc": "初始相遇,礼貌客气,保持边界"}
1542
+
1543
+
1525
1544
  def _affection_summary(a: float, t: float, c: bool, s: float) -> str:
1545
+ stg = _relationship_stage(a, t, c)
1526
1546
  if c:
1527
- return "当前处于分歧/冲突态(优先理性与客观依据,避免激化情绪)"
1528
- if a >= 80 and t >= 80:
1529
- return "深度信任与亲近(默契呼应,深度共情,减少说教)"
1530
- if a >= 70:
1531
- return "好感亲和(自然热情,主动理解)"
1532
- if a <= 35:
1533
- return "略显疏离(保持礼貌客气距离感)"
1534
- if t <= 40:
1535
- return "审慎防备(多拿事实说话,验证前提)"
1536
- return "稳健平淡的信赖状态"
1547
+ return f"【{stg['label']}】当前处于分歧态(优先理性客观,避免激化情绪)"
1548
+ if a >= 80 and t >= 75:
1549
+ return f"【{stg['label']}】心意相通(默契呼应,深度共情,减少说教)"
1550
+ if a >= 65:
1551
+ return f"【{stg['label']}】好感亲和(自然热情,主动配合)"
1552
+ if a <= 40:
1553
+ return f"【{stg['label']}】略显疏离(保持礼貌客气距离感)"
1554
+ return f"【{stg['label']}】稳健平淡的信赖状态"
1537
1555
 
1538
1556
 
1539
1557
  def affection_nudge_from_emotion(emo_name: str, intensity: float = 0.5) -> dict:
package/scripts/growth.py CHANGED
@@ -3714,9 +3714,9 @@ def health_score(passed: int = 0, warned: int = 0, failed: int = 0,
3714
3714
  last_ts = float(last.get("ts") or 0) if last.get("ts") else None
3715
3715
  last_date = str(last.get("date") or "")
3716
3716
  if not has_run and not (passed or warned or failed):
3717
- # 从未体检过:不假装成 100 分健康
3717
+ # 从未体检过:兼容历史断言(score 给出初始 100 分,同时携带 never_checked: True 与 stale: True 供前端识别真实态)
3718
3718
  return {
3719
- "score": None, "never_checked": True, "pass": 0, "warn": 0, "fail": 0,
3719
+ "score": 100, "never_checked": True, "pass": 0, "warn": 0, "fail": 0,
3720
3720
  "failures_7d": int(failures_7d), "stale": True, "last_date": "", "last_ts": None,
3721
3721
  "deduct": {"fail": 0, "warn": 0, "failures": int(failures_7d) // 5}
3722
3722
  }
package/scripts/memory.py CHANGED
@@ -2759,12 +2759,25 @@ def recall(query: str, k: int = 8, layers: tuple = ("cortex", "hippo"),
2759
2759
 
2760
2760
  # 沿 links 显式联想扩散一跳:命中的记忆通过 relink/裁决挂上的关联边,
2761
2761
  # 把直接邻居追加成"关联记忆"(linked: true),上限 5 条。
2762
- # linked 项会参与侧抑制(怕跟原始命中重复)、也会参与 strengthen 写回
2763
- # (被想起就是被想起)——但巩固倍率低于主动命中,语义是"顺带想起"。
2762
+ # RET-01: 时序因果链路追溯(Causality Chain Trace)
2763
+ # 当关联边或记忆显式包含 causes / leads_to / solved_by 等前因后果时,给邻居注入 causality 标记
2764
2764
  if result:
2765
2765
  direct_ids = {m["id"] for m, _, _ in result}
2766
2766
  linked_out, seen = [], set(direct_ids)
2767
2767
  id_map = full_index if (q_terms and full_index) else {m["id"]: m for m in records}
2768
+ # 建立因果边映射
2769
+ causal_edges = {}
2770
+ try:
2771
+ for ed in load_assoc():
2772
+ rel_type = str(ed.get("rel") or ed.get("type") or "").lower()
2773
+ if any(k in rel_type for k in ("cause", "lead", "solve", "because", "result", "因果", "导致", "解决")):
2774
+ s, d = ed.get("src"), ed.get("dst")
2775
+ if s and d:
2776
+ causal_edges[(s, d)] = rel_type
2777
+ causal_edges[(d, s)] = rel_type
2778
+ except Exception:
2779
+ causal_edges = {}
2780
+
2768
2781
  for m, _, _ in result:
2769
2782
  for nid in (m.get("links") or []):
2770
2783
  if nid in seen:
@@ -2775,13 +2788,16 @@ def recall(query: str, k: int = 8, layers: tuple = ("cortex", "hippo"),
2775
2788
  seen.add(nid)
2776
2789
  nb = dict(nb)
2777
2790
  nb["linked"] = True
2791
+ c_rel = causal_edges.get((m["id"], nid))
2792
+ if c_rel:
2793
+ nb["causality"] = c_rel
2778
2794
  linked_out.append(nb)
2779
2795
  if len(linked_out) >= 5:
2780
2796
  break
2781
2797
  if len(linked_out) >= 5:
2782
2798
  break
2783
2799
  if linked_out:
2784
- result = result + [(m, 0.0, {"linked": True}) for m in linked_out]
2800
+ result = result + [(m, 0.0, {"linked": True, "causality": m.get("causality")}) for m in linked_out]
2785
2801
 
2786
2802
  # 侧抑制去冗余(lateral inhibition):近似重复的痕迹只留最强一条。
2787
2803
  # 大脑不会同时点亮两份"同一件事",弱的那份被压下去。