lingshu-skill 5.29.0 → 5.31.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 (46) hide show
  1. package/CHANGELOG.md +168 -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 +341 -405
  6. package/assets/panel.html +532 -19
  7. package/cordis-plugin/lingshu-cron/plugin.js +195 -29
  8. package/docs//344/275/277/347/224/250/346/214/207/345/215/227.md +229 -0
  9. package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +134 -43
  10. package/docs//345/276/205/345/212/236/346/250/241/346/235/277.md +140 -0
  11. package/package.json +1 -1
  12. package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +20 -17
  13. package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +168 -0
  14. package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
  15. package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
  16. package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
  17. package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +341 -405
  18. package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +532 -19
  19. package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +47 -18
  20. package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +32 -0
  21. package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +22 -7
  22. package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +14 -6
  23. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +27 -5
  24. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_dialogue.py +15 -0
  25. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +641 -61
  26. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_icon.py +220 -0
  27. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_launcher.py +114 -10
  28. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +225 -72
  29. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_shortcut.py +330 -0
  30. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_splash.py +181 -0
  31. package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +31 -11
  32. package/scripts/astrbot_plugin_lingshu/engine/scripts/safety_net.py +45 -9
  33. package/scripts/cli.py +47 -18
  34. package/scripts/core.py +32 -0
  35. package/scripts/dream.py +22 -7
  36. package/scripts/emotion.py +14 -6
  37. package/scripts/growth.py +27 -5
  38. package/scripts/mem_dialogue.py +15 -0
  39. package/scripts/memory.py +641 -61
  40. package/scripts/panel_icon.py +220 -0
  41. package/scripts/panel_launcher.py +114 -10
  42. package/scripts/panel_server.py +225 -72
  43. package/scripts/panel_shortcut.py +330 -0
  44. package/scripts/panel_splash.py +181 -0
  45. package/scripts/persona.py +31 -11
  46. package/scripts/safety_net.py +45 -9
@@ -397,10 +397,21 @@ def cmd_backup(target: str | None = None, keep: int = 20, password: str | None =
397
397
  keep_h = int(cfg.get("backup_keep_hourly") or 0)
398
398
  keep_d = int(cfg.get("backup_keep_daily") or 0)
399
399
  keep_w = int(cfg.get("backup_keep_weekly") or 0)
400
- drop: set = set()
401
- if keep_h > 0:
402
- drop.update(existing[keep_h:])
403
- if keep_d > 0:
400
+ # ★ 各层各算"要保留哪些",最后取**并集**(审计 cli.py:402)。
401
+ # 原实现把 drop 当并集用:hourly 先 `drop.update(existing[keep_h:])`
402
+ # 把第 keep_h 个之后全标废弃,daily/weekly 只能继续往 drop 里加、
403
+ # 救不回来 → backup_keep_daily/weekly 完全失效,3 天前那份按天该留的
404
+ # 备份照样被移进 .pruned。分层保留必须"任一层想留就留"。
405
+ keep_set: set = set()
406
+ # 语义分层(改错过一次,务必看清):
407
+ # · **显式 keep>0 = 硬上限**:只保留最近 keep 个,GFS 三层不参与。
408
+ # · **keep<=0 = 交给 GFS**:三层各算保留集取并集,任一层想留就留。
409
+ _explicit_keep = bool(keep and keep > 0)
410
+ if _explicit_keep:
411
+ keep_set.update(existing[:keep])
412
+ elif keep_h > 0:
413
+ keep_set.update(existing[:keep_h]) # 最近 N 个
414
+ if not _explicit_keep and keep_d > 0:
404
415
  seen_days, kept_d = set(), 0
405
416
  for p in existing:
406
417
  day = datetime.fromtimestamp(p.stat().st_mtime).strftime("%Y%m%d")
@@ -408,9 +419,9 @@ def cmd_backup(target: str | None = None, keep: int = 20, password: str | None =
408
419
  continue
409
420
  seen_days.add(day)
410
421
  kept_d += 1
411
- if kept_d > keep_d:
412
- drop.add(p)
413
- if keep_w > 0:
422
+ if kept_d <= keep_d:
423
+ keep_set.add(p) # 每天的第一个
424
+ if not _explicit_keep and keep_w > 0:
414
425
  seen_weeks, kept_w = set(), 0
415
426
  for p in existing:
416
427
  wk = datetime.fromtimestamp(p.stat().st_mtime).strftime("%G%V")
@@ -418,11 +429,11 @@ def cmd_backup(target: str | None = None, keep: int = 20, password: str | None =
418
429
  continue
419
430
  seen_weeks.add(wk)
420
431
  kept_w += 1
421
- if kept_w > keep_w:
422
- drop.add(p)
423
- if keep and keep > 0:
424
- drop.update(existing[keep:])
432
+ if kept_w <= keep_w:
433
+ keep_set.add(p) # 每周的第一个
425
434
  # 最新那份永不删(否则备份完立刻把自己删了)
435
+ keep_set.add(existing[0])
436
+ drop = set(existing) - keep_set
426
437
  drop.discard(existing[0])
427
438
  # 修剪 = **移到 .pruned/**,不是删除(待办 L718 #2 + 用户"只移不删"规矩)。
428
439
  # 理由:备份策略误配(keep 设太小)时,被"修剪"的好备份还能从这里捞回来;
@@ -4384,9 +4395,18 @@ def _main(argv=None) -> int:
4384
4395
  try:
4385
4396
  import persona as _persona
4386
4397
  pr = _persona.persona_check()
4387
- issues = pr.get("issues") or pr.get("problems") or []
4388
- checks.append(("persona", "PASS" if not issues else "WARN",
4389
- "; ".join(map(str, issues)) or "人格完整"))
4398
+ # ⚠ 必须按 persona_check() 真实返回的键读(它返回 fails/warns/info):
4399
+ # 原来读 issues/problems,这两个键从不出现 → issues 恒空 → 无论
4400
+ # NaN traits、evidence 非数组、数值越界,永远输出"人格完整"。
4401
+ # 这条检查的意义就是让故障暴露,结果自己静默失效。
4402
+ issues = list(pr.get("fails") or [])
4403
+ warns = list(pr.get("warns") or [])
4404
+ st = "FAIL" if issues else ("WARN" if warns else "PASS")
4405
+ detail = ("; ".join(map(str, issues)) or "; ".join(map(str, warns))
4406
+ or "人格完整")
4407
+ if issues:
4408
+ detail += f"({len(issues)} 处必须修)"
4409
+ checks.append(("persona", st, detail))
4390
4410
  except Exception as e:
4391
4411
  checks.append(("persona", "FAIL", str(e)))
4392
4412
  # 3. memory diagnose
@@ -4600,12 +4620,17 @@ def _main(argv=None) -> int:
4600
4620
 
4601
4621
  # v5.12:把本次体检结果追加到 doctor-history.jsonl——灵枢自己的成长账本,
4602
4622
  # 面板"体检历史"页签和未来的健康度分数用它。append-only,单条 try/except 吞掉。
4623
+ # ⚠ 字段名必须与 growth.record_doctor_run() 一致({kind,pass,warn,fail}):
4624
+ # 原来这里写成 {fails,warns,passes},同一个文件里两套字段名 → 面板按
4625
+ # passes/fails 求和时,由 record_doctor_run 写的那一半永远贡献 0,
4626
+ # 折线图恒平、成长阶段按双倍计数晋级。
4603
4627
  try:
4604
4628
  _dr = {
4605
4629
  "ts": int(time.time()),
4606
- "fails": sum(1 for _, s, _ in checks if s == "FAIL"),
4607
- "warns": sum(1 for _, s, _ in checks if s == "WARN"),
4608
- "passes": sum(1 for _, s, _ in checks if s == "PASS"),
4630
+ "kind": "doctor",
4631
+ "pass": sum(1 for _, s, _ in checks if s == "PASS"),
4632
+ "warn": sum(1 for _, s, _ in checks if s == "WARN"),
4633
+ "fail": sum(1 for _, s, _ in checks if s == "FAIL"),
4609
4634
  "checks": {n: s for n, s, _ in checks},
4610
4635
  }
4611
4636
  _dh_path = (globals().get("brain") or sys.modules.get("brain")).HOME / "doctor-history.jsonl"
@@ -4746,7 +4771,11 @@ def _main(argv=None) -> int:
4746
4771
  out_lines.append(f"## 知识库({len(kb)} 条)")
4747
4772
  out_lines.append("")
4748
4773
  for k in kb[:200]:
4749
- body = str(k.get("content") or k.get("text") or "").replace("\n", " ")
4774
+ # 知识条目的正文字段是 body(见 growth 的 _new_knowledge);
4775
+ # 原来读 content/text,两个键都不存在 → 恒空串 →
4776
+ # export 的"知识库"节每条只剩一个 "- "(审计 cli.py:4763)。
4777
+ body = str(k.get("body") or k.get("content") or k.get("text")
4778
+ or "").replace("\n", " ")
4750
4779
  if len(body) > 200:
4751
4780
  body = body[:200] + "…"
4752
4781
  out_lines.append(f"- {body}")
@@ -956,6 +956,27 @@ def config_unset(key: str) -> dict:
956
956
  return cfg
957
957
 
958
958
 
959
+ def _num(v, default: float = 0.0) -> float:
960
+ """安全取数:None / bool / 非数值 / NaN / inf 一律回 default。
961
+
962
+ ⚠ 本轮(v5.32)才发现 core.py 里**有 6 处调用 _num() 却从未定义它**:
963
+ token_context_pressure()(4 处)每次都抛 NameError,又被 except 吞成
964
+ return None → 灵枢**从来没读到过 APP tokenMeter 的准确水位**,
965
+ 只能退回字符估算,于是报 14% 而实际 66%。
966
+ DETAIL_CONSOLIDATE 的 lambda 同样会炸(做梦淡化规则静默失效)。
967
+ 这是典型的「except Exception 吞掉真实错误」——异常没有消失,只是没声张。
968
+ """
969
+ try:
970
+ if v is None or isinstance(v, bool):
971
+ return default
972
+ f = float(v)
973
+ if f != f or f in (float("inf"), float("-inf")):
974
+ return default
975
+ return f
976
+ except (TypeError, ValueError):
977
+ return default
978
+
979
+
959
980
  def _cfg_num(cfg: dict, key: str, default, cast=float):
960
981
  """从配置里安全取一个数字:坏值/手改错时回退默认,绝不让注入崩掉。"""
961
982
  try:
@@ -1333,6 +1354,17 @@ def read_pressure(cfg: dict | None = None) -> dict | None:
1333
1354
  except Exception:
1334
1355
  pass
1335
1356
  tp = token_context_pressure()
1357
+ # ★ 估算值让位给 tokenMeter(v5.32,实测修):
1358
+ # lingshu-cron 拿不到完整对话历史,只能按「本轮几条消息的字符数」估,
1359
+ # 实测报 14% 而 APP tokenMeter 实测 65.7%(窗口是 1M 不是 131K)。
1360
+ # 它写进 _pressure.json 的 source 就是 'chars'/'floor',属于**估算**,
1361
+ # 不该冒充用户显式给的准值去压住宿主真值。
1362
+ # 规则:人工/真值(manual、usage、check-context)优先;
1363
+ # 估算类(chars、floor、chars+calib、cron)在有 tokenMeter 时让位。
1364
+ _EST_SOURCES = ('chars', 'floor', 'chars+calib', 'cron', 'unknown')
1365
+ if (legacy is not None and tp is not None
1366
+ and str(legacy.get('source') or '').lower() in _EST_SOURCES):
1367
+ legacy = None
1336
1368
  if legacy is not None:
1337
1369
  th = pressure_thresholds(cfg if cfg is not None else load_config())
1338
1370
  pct = legacy["pct"]
@@ -237,9 +237,14 @@ def cluster_memories(records: list, max_clusters: int = 6, include_ids: set | No
237
237
  def _dream_snapshot() -> str:
238
238
  """做梦改库前的自动快照(借鉴 sage-mem:整理前强制建回滚点)。
239
239
 
240
- 只打包记忆相关的核心文件(hippocampus/assoc/archive 等),比全库 backup
241
- 轻量得多;存在 ~/.brain-memory/dream-snapshots/ 下,保留最近 10 份。
240
+ 存 ~/.brain-memory/dream-snapshots/ 下,保留最近 10 份。
242
241
  失败返回 "" 并记事件日志;调用方(dream)fail-closed:拿不到快照就拒绝整理。
242
+
243
+ **core_files 必须覆盖 `save_all` 真正会写的全部文件**。`save_all` 写的是
244
+ ("hippocampus.jsonl", "cortex.jsonl", "dust.jsonl"),而 dream 恰好会 promote 到
245
+ cortex、淡忘到 dust——早期版本只备份 hippocampus 一层,于是 restore 之后
246
+ cortex/dust 保持新状态、hippocampus 回到旧状态,同一条记忆同时出现在两处,
247
+ 库处于半新半旧状态,而报告却写着"可用 restore 还原"(审计 dream.py:253)。
243
248
  """
244
249
  snap_dir = HOME / "dream-snapshots"
245
250
  try:
@@ -250,19 +255,23 @@ def _dream_snapshot() -> str:
250
255
  while path.exists():
251
256
  k += 1
252
257
  path = snap_dir / f"dream-snap_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{k}.zip"
253
- core_files = ["hippocampus.jsonl", "archive.jsonl", "assoc.jsonl",
258
+ # 三层记忆全都要(hippo/cortex/dust 是 save_all 的写入目标,缺一层回滚点就是残的)
259
+ core_files = ["hippocampus.jsonl", "cortex.jsonl", "dust.jsonl",
260
+ "archive.jsonl", "assoc.jsonl",
254
261
  "knowledge.jsonl", "persona.json", "dream_state.json"]
255
262
  with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as zf:
256
263
  for name in core_files:
257
264
  f = HOME / name
258
265
  if f.is_file():
259
266
  zf.write(f, name)
260
- # 保留最近 10 份,旧的删掉
267
+ # 保留最近 10 份;旧的移入 .pruned/ 而不是删除(用户规矩:要删的进垃圾桶/归档)
268
+ pruned = snap_dir / ".pruned"
261
269
  snaps = sorted(snap_dir.glob("dream-snap_*.zip"))
262
270
  for p in snaps[:-10]:
263
271
  try:
264
- p.unlink()
265
- except OSError:
272
+ pruned.mkdir(parents=True, exist_ok=True)
273
+ shutil.move(str(p), str(pruned / p.name))
274
+ except (OSError, shutil.Error):
266
275
  pass
267
276
  return str(path)
268
277
  except Exception as exc:
@@ -495,8 +504,14 @@ def _bounded_growth(records: list, now: int) -> list:
495
504
  软上限可用 config `dream.capacity_cap` 覆盖。返回本次被归档的记录列表。
496
505
  保护名单与 _is_archivable 一致:pinned / verbatim / identity / correction / pending。
497
506
  """
507
+ # ⚠ `config set dream.capacity_cap N` 经 _set_cfg_path 写的是**嵌套**
508
+ # cfg["dream"]["capacity_cap"];这里原来读平铺键 "dream.capacity_cap",
509
+ # 永远取不到 → 软上限恒为 3000,用户配置形同虚设(审计 dream.py:499)。
498
510
  try:
499
- cap = int(_num(load_config().get("dream.capacity_cap"), 3000))
511
+ _cfg = load_config()
512
+ _drm = _cfg.get("dream") if isinstance(_cfg.get("dream"), dict) else {}
513
+ _raw_cap = _drm.get("capacity_cap", _cfg.get("dream.capacity_cap"))
514
+ cap = int(_num(_raw_cap, 3000))
500
515
  except Exception:
501
516
  cap = 3000
502
517
  cap = max(cap, 100) # 防呆:设得太小也不至于清空热层
@@ -410,8 +410,11 @@ def feel(name: str, intensity: float = 0.6, why: str = "",
410
410
  "ts": ts_now, "emotion": name, "valence": v, "arousal": a,
411
411
  "intensity": round(eff, 3),
412
412
  "why": _why, "about": _about,
413
+ # ⚠ 用 `is not None` 判"给没给",不能用真值判断(审计 emotion.py:413):
414
+ # `if decay_hours` 把 0 当假 → `--decay-hours 0` 不落到钳制下限 0.5,
415
+ # 而是回落默认 6 小时,用户显式传 0 却被无视。
413
416
  "decay_hours": (max(0.5, min(720.0, float(decay_hours)))
414
- if decay_hours else EMOTION_HALF_LIFE / HOUR),
417
+ if decay_hours is not None else EMOTION_HALF_LIFE / HOUR),
415
418
  "genesis": bool(genesis),
416
419
  }
417
420
  if resonance != "none":
@@ -529,7 +532,8 @@ def _save_gate(st: dict) -> None:
529
532
  pass
530
533
 
531
534
 
532
- def _apply_label_gate(v: float, a: float, active, base_label: str) -> str:
535
+ def _apply_label_gate(v: float, a: float, active, base_label: str,
536
+ n_ev_total: int | None = None) -> str:
533
537
  """跃迁阈值 + 2 轮确认:标签不能单轮跳变。
534
538
 
535
539
  规则:候选标签与当前对外标签不同时,若 |Δv| ≥ 阈值 → 记为待定并计数;
@@ -582,9 +586,12 @@ def _apply_label_gate(v: float, a: float, active, base_label: str) -> str:
582
586
  _save_gate(st)
583
587
  return cur
584
588
  # 幅度够:看是否有**新的情绪事件**支撑同一候选(单条事件不许独自翻转标签)
589
+ # 用**截断前**的事件总数:active 在 _mood_snapshot 里已被截成 active[:6]
590
+ # 供注入展示用,拿它当"事件数"会在满 6 条后恒不再增长,
591
+ # `n_ev > prev_n` 永不成立 → 标签卡死不切换(审计 emotion.py:591)。
585
592
  try:
586
- n_ev = len(active or [])
587
- except TypeError:
593
+ n_ev = int(n_ev_total) if n_ev_total is not None else len(active or [])
594
+ except (TypeError, ValueError):
588
595
  n_ev = 0
589
596
  prev_pending = str(st.get("pending") or "")
590
597
  prev_n = int(st.get("pending_events") or 0)
@@ -624,7 +631,7 @@ def _finalize_mood(m: dict) -> dict:
624
631
  return out
625
632
  out["label"] = _apply_label_gate(
626
633
  _num(out.get("valence"), 0.0), _num(out.get("arousal"), 0.0),
627
- out.get("active"), _lbl)
634
+ out.get("active"), _lbl, out.get("active_total"))
628
635
  return out
629
636
  except Exception: # noqa: BLE001
630
637
  return m
@@ -707,7 +714,8 @@ def mood_now(at: float | None = None) -> dict:
707
714
  "raw_label": _base_label,
708
715
  "category": groups[0]["group"] if groups else "静",
709
716
  "intensity": round(min(1.0, sw), 3),
710
- "active": active[:6], "groups": groups,
717
+ # active 截断只影响展示;active_total 供门控用(见 _apply_label_gate)
718
+ "active": active[:6], "active_total": len(active), "groups": groups,
711
719
  "complex": complex_flag, "storm": a >= STORM_AROUSAL,
712
720
  "note": "悲喜交加" if complex_flag else ""}
713
721
  # 跃迁阈值 + 2 轮确认:**必须在 EMA 之后**——`_mood_ema` 自己会重算 label,
@@ -2870,10 +2870,16 @@ def install_skill(name: str, force: bool = False, from_dir: str | None = None,
2870
2870
  inst_meta = {}
2871
2871
 
2872
2872
  def _vt(v) -> tuple | None:
2873
+ # 必须补零到三段再比(审计 growth.py:2872):
2874
+ # "5.11" → (5,11),"5.11.0" → (5,11,0),而 (5,11) < (5,11,0) 为真
2875
+ # → 一个合法的更新会被误判成"倒退"而拒绝。
2873
2876
  try:
2874
- return tuple(int(x) for x in str(v).strip().split("."))
2877
+ parts = [int(x) for x in str(v).strip().split(".")]
2875
2878
  except (TypeError, ValueError):
2876
2879
  return None
2880
+ while len(parts) < 3:
2881
+ parts.append(0)
2882
+ return tuple(parts[:3])
2877
2883
  src_v, inst_v = _vt(meta.get("version")), _vt(inst_meta.get("version"))
2878
2884
  if src_v is not None and inst_v is not None and src_v < inst_v:
2879
2885
  raise KeyError(
@@ -3417,9 +3423,21 @@ def _file_lock_probe(path: Path) -> dict:
3417
3423
  "($_.ExecutablePath -and $_.ExecutablePath.ToLower().Contains('" +
3418
3424
  target.replace("'", "''") + "'))} | "
3419
3425
  "Select-Object ProcessId,Name,CommandLine | ConvertTo-Json -Compress")
3420
- r = subprocess.run(["powershell", "-NoProfile", "-Command", ps],
3421
- capture_output=True, timeout=15)
3422
- rows = json.loads(r.stdout.decode("utf-8", "replace") or "[]")
3426
+ # ★ 用 Popen 而不是 subprocess.run(审计 growth.py:3430):
3427
+ # run() 返回的是 CompletedProcess,**没有 .pid 属性**(只有 args/returncode/
3428
+ # stdout/stderr)。原来下面写 `if pid in (my_pid, r.pid)` 每进这个分支必抛
3429
+ # AttributeError,又被外层 `except Exception: pass` 吞掉 → out["pids"] 恒为空,
3430
+ # 于是"占用者探测"只能回落到"查不到具体进程",这项诊断等于没做。
3431
+ proc = subprocess.Popen(["powershell", "-NoProfile", "-Command", ps],
3432
+ stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
3433
+ try:
3434
+ out_bytes, _ = proc.communicate(timeout=15)
3435
+ except subprocess.TimeoutExpired:
3436
+ proc.kill()
3437
+ out_bytes, _ = proc.communicate()
3438
+ raise
3439
+ ps_pid = proc.pid
3440
+ rows = json.loads((out_bytes or b"").decode("utf-8", "replace") or "[]")
3423
3441
  if isinstance(rows, dict):
3424
3442
  rows = [rows]
3425
3443
  my_pid = os.getpid()
@@ -3427,7 +3445,7 @@ def _file_lock_probe(path: Path) -> dict:
3427
3445
  try:
3428
3446
  pid = int(row.get("ProcessId", 0))
3429
3447
  # 排除自己(探测进程的命令行里也含目标路径)和跑查询的 powershell 子进程
3430
- if pid in (my_pid, r.pid):
3448
+ if pid in (my_pid, ps_pid):
3431
3449
  continue
3432
3450
  out["pids"].append({"pid": pid,
3433
3451
  "name": str(row.get("Name", "")),
@@ -4476,6 +4494,10 @@ def log_evolution(kind: str, title: str, detail: str = "", refs=None) -> dict:
4476
4494
  with brain._locked(EVOLUTION_FILE):
4477
4495
  rows = brain.read_jsonl(EVOLUTION_FILE)
4478
4496
  rows.append(row)
4497
+ # #26 有界增长:原来只追加不裁剪,load_evolution() 每次全量读 →
4498
+ # 长期使用后文件与读取成本无界。与 audit.jsonl(5000→4000)同口径。
4499
+ if len(rows) > 5000:
4500
+ rows = rows[-4000:]
4479
4501
  brain.write_jsonl(EVOLUTION_FILE, rows)
4480
4502
  return row
4481
4503
 
@@ -203,6 +203,21 @@ def ingest_dialogues(paths=None, limit: int | None = None, dry_run: bool = False
203
203
  if blob and not blob.endswith(b"\n"):
204
204
  cut = blob.rfind(b"\n")
205
205
  if cut < 0:
206
+ # #29:整块没有换行 = 这个文件被压成了一行(或单行超长)。
207
+ # 原来的裸 continue 不写日志、不推进 offset → 每次读 8MB、
208
+ # 每次跳过,永远不摄取且无任何提示。这里记一次日志
209
+ # (同一文件只报一次,避免每轮刷屏),让用户知道该换格式。
210
+ try:
211
+ _warned = globals().setdefault("_LONGLINE_WARNED", set())
212
+ if str(f) not in _warned:
213
+ _warned.add(str(f))
214
+ core.log_event(
215
+ "dialogue",
216
+ f"跳过 {f.name}:单块 {len(blob)} 字节内没有换行,"
217
+ "疑似被压成一行的导出文件——请改用逐行 JSONL",
218
+ level="warn")
219
+ except Exception: # noqa: BLE001
220
+ pass
206
221
  continue
207
222
  blob = blob[:cut + 1]
208
223
  text = _dialogue_decode(blob, f.name)