lingshu-skill 5.32.0 → 5.37.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 +4281 -4173
- package/README.md +1584 -1577
- package/SKILL-lite.md +59 -59
- package/SKILL-tiny.md +38 -38
- package/SKILL.md +356 -317
- package/assets/panel.html +6753 -5698
- package/cordis-plugin/lingshu-cron/plugin.js +1455 -1417
- package/cordis-plugin/lingshu-startup/context-fold.js +170 -0
- package/cordis-plugin/lingshu-startup/context-pressure.js +16 -0
- package/cordis-plugin/lingshu-startup/context-snapshot.js +176 -0
- package/cordis-plugin/lingshu-startup/plugin.js +499 -467
- package/docs/audit_notes//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 +162 -0
- 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 +92 -0
- package/docs/audit_notes//345/276/205/345/212/236/346/250/241/346/235/277.md +140 -0
- package/docs/commands.md +278 -247
- package/docs/mechanics.md +610 -610
- 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 +162 -0
- 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 +92 -0
- package/package.json +52 -52
- package/scripts/_scratch/_tmp_backup_race.py +70 -0
- package/scripts/_scratch/_tmp_cleanup_move.py +34 -0
- package/scripts/_scratch/_tmp_count_kinds.py +25 -0
- package/scripts/_scratch/_tmp_diag_paths.py +48 -0
- package/scripts/_scratch/_tmp_facts.py +63 -0
- package/scripts/_scratch/_tmp_find_copies.py +31 -0
- package/scripts/_scratch/_tmp_find_pin.py +29 -0
- package/scripts/_scratch/_tmp_fix_pin.py +36 -0
- package/scripts/_scratch/_tmp_fold_fixture.py +55 -0
- package/scripts/_scratch/_tmp_fold_test.mjs +81 -0
- package/scripts/_scratch/_tmp_inject_secs.py +30 -0
- package/scripts/_scratch/_tmp_kb_balance.py +159 -0
- package/scripts/_scratch/_tmp_lines.py +15 -0
- package/scripts/_scratch/_tmp_market_probe.py +13 -0
- package/scripts/_scratch/_tmp_move_partial.py +16 -0
- package/scripts/_scratch/_tmp_patch_b3.py +41 -0
- package/scripts/_scratch/_tmp_patch_b5.py +62 -0
- package/scripts/_scratch/_tmp_patch_crash_excl.py +24 -0
- package/scripts/_scratch/_tmp_patch_handoff.py +21 -0
- package/scripts/_scratch/_tmp_patch_ps1.py +25 -0
- package/scripts/_scratch/_tmp_patch_stat.py +27 -0
- package/scripts/_scratch/_tmp_patch_todo.py +25 -0
- package/scripts/_scratch/_tmp_patch_todo2.py +64 -0
- package/scripts/_scratch/_tmp_probe_session.py +51 -0
- package/scripts/_scratch/_tmp_style_probe.py +40 -0
- package/scripts/_scratch/_tmp_write_note.py +139 -0
- package/scripts/_scratch/_/346/235/245/346/272/220/350/256/260/345/275/225.txt +1 -0
- package/scripts/_scratch/asar_compaction/dsh-compaction-basic__lib__index.js +1044 -0
- package/scripts/_scratch/asar_compaction/dsh-compaction-tool-result-pruner__lib__index.js +194 -0
- package/scripts/_scratch/asar_compaction/dsh-compaction__lib__index.js +175 -0
- package/scripts/_scratch/asar_compaction/dsh-compaction__lib__types__tool-pairing.js +97 -0
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__image-offload.js +47 -0
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__index.js +40 -0
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__project-message.js +37 -0
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__brand.js +9 -0
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__checkpoint.js +36 -0
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__types.js +10 -0
- package/scripts/_scratch/commit_msg_occ.txt +16 -0
- package/scripts/_scratch/commit_msg_struct.txt +16 -0
- package/scripts/_scratch/v5.34_changelog.txt +36 -0
- package/scripts/_sync_trae_cn.py +102 -34
- package/scripts/_tmp_add_s10.py +54 -0
- package/scripts/_tmp_add_s11.py +61 -0
- package/scripts/_tmp_add_s12.py +66 -0
- package/scripts/_tmp_add_s13.py +69 -0
- package/scripts/_tmp_add_s14.py +80 -0
- package/scripts/_tmp_add_s9.py +68 -0
- package/scripts/_tmp_cache_load.py +82 -0
- package/scripts/_tmp_clean_market.py +40 -0
- package/scripts/_tmp_clean_pruned.py +81 -0
- package/scripts/_tmp_cleanup_docs.py +39 -0
- package/scripts/_tmp_cmp_ranker.py +17 -0
- package/scripts/_tmp_dolater_note.py +35 -0
- package/scripts/_tmp_dust_why.py +27 -0
- package/scripts/_tmp_explicit_import.py +40 -0
- package/scripts/_tmp_extract_compaction.py +35 -0
- package/scripts/_tmp_extract_compaction2.py +63 -0
- package/scripts/_tmp_extract_compaction3.py +51 -0
- package/scripts/_tmp_extract_compaction4.py +54 -0
- package/scripts/_tmp_finalize_s14.py +39 -0
- package/scripts/_tmp_find_compaction.py +43 -0
- package/scripts/_tmp_fix_b4.py +22 -0
- package/scripts/_tmp_fix_cli76.py +26 -0
- package/scripts/_tmp_fix_docs.py +38 -0
- package/scripts/_tmp_fix_docs_b.py +46 -0
- package/scripts/_tmp_fix_docs_b2.py +22 -0
- package/scripts/_tmp_fix_i3.py +23 -0
- package/scripts/_tmp_fix_s10.py +83 -0
- package/scripts/_tmp_fix_s11.py +14 -0
- package/scripts/_tmp_fix_s9_status.py +19 -0
- package/scripts/_tmp_fix_shadow_sim.py +37 -0
- package/scripts/_tmp_fix_traits_value.py +41 -0
- package/scripts/_tmp_import_idem.py +106 -0
- package/scripts/_tmp_log_ack.py +45 -0
- package/scripts/_tmp_mark_batch.py +28 -0
- package/scripts/_tmp_mark_batch2.py +32 -0
- package/scripts/_tmp_mark_dolater.py +26 -0
- package/scripts/_tmp_mark_dolater2.py +31 -0
- package/scripts/_tmp_move_self.py +16 -0
- package/scripts/_tmp_occ_cli.py +22 -0
- package/scripts/_tmp_occ_link.py +108 -0
- package/scripts/_tmp_optimize_recall.py +54 -0
- package/scripts/_tmp_panel_audit.py +26 -0
- package/scripts/_tmp_patch_batch3.py +65 -0
- package/scripts/_tmp_patch_rrf.py +46 -0
- package/scripts/_tmp_patch_s2s3.py +80 -0
- package/scripts/_tmp_patch_s4.py +39 -0
- package/scripts/_tmp_patch_s7.py +43 -0
- package/scripts/_tmp_patch_s8.py +91 -0
- package/scripts/_tmp_patch_skill.py +17 -0
- package/scripts/_tmp_release_guard.py +57 -0
- package/scripts/_tmp_rerank_breaker.py +62 -0
- package/scripts/_tmp_s16.py +41 -0
- package/scripts/_tmp_scan_asar.py +41 -0
- package/scripts/_tmp_scan_asar2.py +37 -0
- package/scripts/_tmp_struct_docs.py +49 -0
- package/scripts/_tmp_sum_fallback.py +42 -0
- package/scripts/_tmp_sweep.py +81 -0
- package/scripts/_tmp_sync_check.py +69 -0
- package/scripts/_tmp_sync_tail.py +39 -0
- package/scripts/_tmp_todo_clean.py +67 -0
- package/scripts/_tmp_verify_copy.py +17 -0
- package/scripts/_tmp_wire_extras.py +93 -0
- package/scripts/_tmp_wire_hsum.py +34 -0
- package/scripts/_tmp_wire_occ_b5.py +40 -0
- package/scripts/_tmp_wire_ranker.py +13 -0
- package/scripts/_tmp_wire_shadow_timeline.py +45 -0
- package/scripts/anchor_retention.py +68 -0
- package/scripts/app_context.py +1160 -0
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +38 -22
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +4281 -4173
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1584 -1577
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +59 -59
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +38 -38
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +356 -317
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +6753 -5698
- package/scripts/astrbot_plugin_lingshu/engine/docs/commands.md +278 -247
- package/scripts/astrbot_plugin_lingshu/engine/docs/mechanics.md +610 -610
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_sync_trae_cn.py +102 -34
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s10.py +54 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s11.py +61 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s12.py +66 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s13.py +69 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s14.py +80 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s9.py +68 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cache_load.py +82 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_market.py +40 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_pruned.py +81 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cleanup_docs.py +39 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cmp_ranker.py +17 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dolater_note.py +35 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dust_why.py +27 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_explicit_import.py +40 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction.py +35 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction2.py +63 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction3.py +51 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction4.py +54 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_finalize_s14.py +39 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_find_compaction.py +43 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_b4.py +22 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_cli76.py +26 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs.py +38 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b.py +46 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b2.py +22 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_i3.py +23 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s10.py +83 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s11.py +14 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s9_status.py +19 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_shadow_sim.py +37 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_traits_value.py +41 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_import_idem.py +106 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_log_ack.py +45 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch.py +28 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch2.py +32 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater.py +26 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater2.py +31 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_move_self.py +16 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_cli.py +22 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_link.py +108 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_optimize_recall.py +54 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_panel_audit.py +26 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_batch3.py +65 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_rrf.py +46 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s2s3.py +80 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s4.py +39 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s7.py +43 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s8.py +91 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_skill.py +17 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_release_guard.py +57 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_rerank_breaker.py +62 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_s16.py +41 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar.py +41 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar2.py +37 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_struct_docs.py +49 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sum_fallback.py +42 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sweep.py +81 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_check.py +69 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_tail.py +39 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_todo_clean.py +67 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_verify_copy.py +17 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_extras.py +93 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_hsum.py +34 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_occ_b5.py +40 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_ranker.py +13 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_shadow_timeline.py +45 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/anchor_retention.py +68 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/app_context.py +1160 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/bigfive.py +90 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/brain.py +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/check_docs.py +191 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +940 -88
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +2468 -2406
- package/scripts/astrbot_plugin_lingshu/engine/scripts/coverage_report.py +5 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/delivery.py +112 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +41 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +202 -23
- package/scripts/astrbot_plugin_lingshu/engine/scripts/gap_memory.py +186 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +72 -8
- package/scripts/astrbot_plugin_lingshu/engine/scripts/hsum.py +206 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_score.py +92 -7
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +533 -60
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory_extras.py +200 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/occ.py +190 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +232 -142
- package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +2498 -2349
- package/scripts/astrbot_plugin_lingshu/engine/scripts/prepublish_tests.py +90 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/release.py +326 -287
- package/scripts/astrbot_plugin_lingshu/engine/scripts/rss_ingest.py +181 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/session_import.py +832 -764
- package/scripts/astrbot_plugin_lingshu/engine/scripts/shadow_memory.py +173 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/style_check.py +220 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/summarizer.py +343 -252
- package/scripts/astrbot_plugin_lingshu/engine/scripts/timeline.py +118 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/watchdog.py +110 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/web_research.py +125 -0
- package/scripts/bigfive.py +90 -0
- package/scripts/brain.py +1 -1
- package/scripts/check_docs.py +191 -0
- package/scripts/cli.py +940 -88
- package/scripts/core.py +2468 -2406
- package/scripts/coverage_report.py +5 -0
- package/scripts/delivery.py +112 -0
- package/scripts/dream.py +41 -3
- package/scripts/emotion.py +202 -23
- package/scripts/gap_memory.py +186 -0
- package/scripts/growth.py +72 -8
- package/scripts/hsum.py +206 -0
- package/scripts/mem_score.py +92 -7
- package/scripts/memory.py +533 -60
- package/scripts/memory_extras.py +200 -0
- package/scripts/occ.py +190 -0
- package/scripts/panel_server.py +232 -142
- package/scripts/persona.py +2498 -2349
- package/scripts/prepublish_tests.py +90 -0
- package/scripts/release.py +326 -287
- package/scripts/rss_ingest.py +181 -0
- package/scripts/run_tests.py +13 -0
- package/scripts/session_import.py +832 -764
- package/scripts/shadow_memory.py +173 -0
- package/scripts/style_check.py +220 -0
- package/scripts/summarizer.py +343 -252
- package/scripts/timeline.py +118 -0
- package/scripts/update_dsh_copy.ps1 +110 -107
- package/scripts/watchdog.py +110 -0
- package/scripts/web_research.py +125 -0
- package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +0 -370
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""成长时间线(#46,§9 机制"记忆溯源"的可读版)。
|
|
4
|
+
|
|
5
|
+
回答一个问题:**"我是怎么变成现在这样的?"**
|
|
6
|
+
|
|
7
|
+
数据其实都在,但散在四处:梦 report、人格快照、教训库、缺口记忆。这里把它们按时间
|
|
8
|
+
并成一条线,只读、不改任何东西。
|
|
9
|
+
|
|
10
|
+
用法:
|
|
11
|
+
brain.py timeline # 最近 30 天
|
|
12
|
+
brain.py timeline --days 90
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import time
|
|
17
|
+
|
|
18
|
+
import brain
|
|
19
|
+
import core
|
|
20
|
+
from core import _num, fmt_time
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _dream_events() -> list:
|
|
24
|
+
out = []
|
|
25
|
+
ddir = brain.HOME / "dreams"
|
|
26
|
+
if not ddir.is_dir():
|
|
27
|
+
return out
|
|
28
|
+
for f in ddir.glob("*.md"):
|
|
29
|
+
try:
|
|
30
|
+
st = f.stat()
|
|
31
|
+
first = ""
|
|
32
|
+
for line in f.read_text(encoding="utf-8", errors="replace").splitlines():
|
|
33
|
+
line = line.strip().lstrip("#").strip()
|
|
34
|
+
if line:
|
|
35
|
+
first = line[:70]
|
|
36
|
+
break
|
|
37
|
+
out.append({"ts": int(st.st_mtime), "kind": "梦",
|
|
38
|
+
"title": first or f.name, "ref": f.name})
|
|
39
|
+
except OSError:
|
|
40
|
+
continue
|
|
41
|
+
return out
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _snapshot_events() -> list:
|
|
45
|
+
out = []
|
|
46
|
+
try:
|
|
47
|
+
for s in brain.persona_snapshots(80):
|
|
48
|
+
out.append({"ts": int(s.get("ts") or 0), "kind": "人格快照",
|
|
49
|
+
"title": str(s.get("label") or s.get("action") or "快照")[:70],
|
|
50
|
+
"ref": str(s.get("name") or "")})
|
|
51
|
+
except Exception:
|
|
52
|
+
pass
|
|
53
|
+
return out
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _lesson_events() -> list:
|
|
57
|
+
out = []
|
|
58
|
+
try:
|
|
59
|
+
for r in brain.load_lessons() or []:
|
|
60
|
+
out.append({"ts": int(_num(r.get("ts"), 0)), "kind": "教训",
|
|
61
|
+
"title": str(r.get("text") or "")[:70], "ref": r.get("id") or ""})
|
|
62
|
+
except Exception:
|
|
63
|
+
pass
|
|
64
|
+
return out
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _gap_events() -> list:
|
|
68
|
+
out = []
|
|
69
|
+
try:
|
|
70
|
+
for m in brain.load_all():
|
|
71
|
+
if str(m.get("kind") or "") != "gap":
|
|
72
|
+
continue
|
|
73
|
+
out.append({"ts": int(_num(m.get("created"), 0)), "kind": "缺口",
|
|
74
|
+
"title": str(m.get("text") or "")[:70], "ref": m.get("id") or ""})
|
|
75
|
+
except Exception:
|
|
76
|
+
pass
|
|
77
|
+
return out
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _stage_event() -> list:
|
|
81
|
+
try:
|
|
82
|
+
import growth
|
|
83
|
+
st = growth.stage_state() or {}
|
|
84
|
+
if st:
|
|
85
|
+
return [{"ts": int(time.time()), "kind": "阶段",
|
|
86
|
+
"title": f"{st.get('name') or st.get('stage') or '?'}"
|
|
87
|
+
f"(doctor {st.get('doctor_runs', st.get('runs', 0))} 次 / "
|
|
88
|
+
f"failures {st.get('failures', 0)} 条)",
|
|
89
|
+
"ref": ""}]
|
|
90
|
+
except Exception:
|
|
91
|
+
pass
|
|
92
|
+
return []
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def build(days: int = 30, limit: int = 40) -> list:
|
|
96
|
+
cut = time.time() - max(0, int(days)) * 86400
|
|
97
|
+
rows = _dream_events() + _snapshot_events() + _lesson_events() + _gap_events()
|
|
98
|
+
rows = [r for r in rows if r["ts"] >= cut]
|
|
99
|
+
rows.sort(key=lambda r: -r["ts"])
|
|
100
|
+
return rows[:max(1, int(limit))]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def render(rows: list, days: int) -> list:
|
|
104
|
+
if not rows:
|
|
105
|
+
return [f"最近 {days} 天没有可回溯的事件(梦/人格快照/教训/缺口都没有)。"]
|
|
106
|
+
lines = [f"成长时间线(最近 {days} 天,{len(rows)} 件事,新→旧):"]
|
|
107
|
+
for r in rows:
|
|
108
|
+
when = fmt_time(r["ts"]) if r["ts"] else "??"
|
|
109
|
+
lines.append(f" {when} [{r['kind']}] {r['title']}")
|
|
110
|
+
return lines
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def run(args) -> int:
|
|
114
|
+
days = int(getattr(args, "days", 30) or 30)
|
|
115
|
+
rows = build(days=days, limit=int(getattr(args, "limit", 40) or 40))
|
|
116
|
+
for line in render(rows, days):
|
|
117
|
+
print(line)
|
|
118
|
+
return 0
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""灵枢 · 宿主看门狗(B5)
|
|
4
|
+
|
|
5
|
+
问题:灵枢的定时任务(做梦/备份/体检)全都跑在**宿主进程**里,宿主挂掉时
|
|
6
|
+
它们一起死,而且没有任何声音——v3.53 就出现过"插件装着但全停 6 小时,
|
|
7
|
+
doctor 仍然全绿"。
|
|
8
|
+
|
|
9
|
+
分工:
|
|
10
|
+
· 插件侧(lingshu-cron)每回合写一次 `.host-heartbeat.json`;
|
|
11
|
+
· 本模块只负责**判断宿主是否还活着**:心跳过期就记一条失败事件并返回非零。
|
|
12
|
+
· **只告警,绝不尝试自启**——自启很容易变成两个进程互相打架。
|
|
13
|
+
|
|
14
|
+
用法:
|
|
15
|
+
python scripts/brain.py watchdog # 看一眼
|
|
16
|
+
python scripts/brain.py watchdog --check # 给外部调度器用:不新鲜返回非零
|
|
17
|
+
python scripts/brain.py watchdog --max-age-min 10
|
|
18
|
+
|
|
19
|
+
挂 Windows 任务计划的示例(每 2 分钟一次):
|
|
20
|
+
schtasks /create /tn "灵枢看门狗" /sc minute /mo 2 /tr ^
|
|
21
|
+
"D:\\ServBay\\packages\\python\\current\\python.exe <仓库>\\scripts\\brain.py watchdog --check"
|
|
22
|
+
"""
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import json
|
|
26
|
+
import time
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
|
|
29
|
+
import core
|
|
30
|
+
|
|
31
|
+
HEARTBEAT = ".host-heartbeat.json"
|
|
32
|
+
DEFAULT_MAX_AGE_MIN = 10
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def path() -> Path:
|
|
36
|
+
return Path(core.HOME) / HEARTBEAT
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def load() -> dict | None:
|
|
40
|
+
try:
|
|
41
|
+
p = path()
|
|
42
|
+
if not p.is_file():
|
|
43
|
+
return None
|
|
44
|
+
d = json.loads(p.read_text(encoding="utf-8", errors="replace") or "null")
|
|
45
|
+
return d if isinstance(d, dict) else None
|
|
46
|
+
except Exception:
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def check(max_age_min: int = DEFAULT_MAX_AGE_MIN) -> dict:
|
|
51
|
+
"""返回 {state, ok, age_sec, ts, pid, max_age_min}。
|
|
52
|
+
|
|
53
|
+
state: fresh(新鲜)/ stale(过期)/ missing(从未收到)。
|
|
54
|
+
"""
|
|
55
|
+
hb = load()
|
|
56
|
+
now = int(time.time())
|
|
57
|
+
if not hb:
|
|
58
|
+
return {"state": "missing", "ok": False, "age_sec": None,
|
|
59
|
+
"ts": None, "pid": None, "max_age_min": max_age_min}
|
|
60
|
+
try:
|
|
61
|
+
ts = int(hb.get("ts") or 0)
|
|
62
|
+
except Exception:
|
|
63
|
+
ts = 0
|
|
64
|
+
age = now - ts if ts else None
|
|
65
|
+
fresh = age is not None and age <= max_age_min * 60
|
|
66
|
+
return {"state": "fresh" if fresh else "stale", "ok": fresh, "age_sec": age,
|
|
67
|
+
"ts": ts, "pid": hb.get("pid"), "max_age_min": max_age_min}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def alert(d: dict) -> None:
|
|
71
|
+
"""记一条可聚合的失败事件(不是每 2 分钟刷一行日志)。"""
|
|
72
|
+
try:
|
|
73
|
+
import failures
|
|
74
|
+
failures.record("watchdog.stale",
|
|
75
|
+
f"宿主心跳 {d.get('age_sec')} 秒未更新(阈值 {d.get('max_age_min')} 分钟)",
|
|
76
|
+
ctx={"pid": d.get("pid")})
|
|
77
|
+
except Exception:
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def render(d: dict) -> list[str]:
|
|
82
|
+
st = d.get("state")
|
|
83
|
+
mx = d.get("max_age_min")
|
|
84
|
+
if st == "missing":
|
|
85
|
+
return [f"宿主心跳:从未收到({path().name} 不存在)",
|
|
86
|
+
" 插件可能没装、没跑,或还没升级到带心跳的版本。"]
|
|
87
|
+
age = d.get("age_sec") or 0
|
|
88
|
+
mins = age / 60
|
|
89
|
+
head = (f"宿主心跳:{'新鲜' if st == 'fresh' else '**过期**'}"
|
|
90
|
+
f"({mins:.1f} 分钟前,pid {d.get('pid')},阈值 {mx} 分钟)")
|
|
91
|
+
out = [head]
|
|
92
|
+
if st != "fresh":
|
|
93
|
+
out.append(" 宿主可能已掉线:定时任务不会自己恢复;重启 APP/插件后心跳会恢复。")
|
|
94
|
+
return out
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def run(args) -> int:
|
|
98
|
+
max_age = int(getattr(args, "max_age_min", DEFAULT_MAX_AGE_MIN) or DEFAULT_MAX_AGE_MIN)
|
|
99
|
+
d = check(max_age)
|
|
100
|
+
if getattr(args, "json", False):
|
|
101
|
+
print(json.dumps(d, ensure_ascii=False, indent=2))
|
|
102
|
+
else:
|
|
103
|
+
for line in render(d):
|
|
104
|
+
print(line)
|
|
105
|
+
if d["state"] == "fresh":
|
|
106
|
+
return 0
|
|
107
|
+
if d["state"] == "stale" and getattr(args, "check", False):
|
|
108
|
+
alert(d)
|
|
109
|
+
return 2
|
|
110
|
+
return 3 if d["state"] == "missing" else 2
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""联网调研工具(零依赖,stdlib)。
|
|
4
|
+
|
|
5
|
+
为什么需要它:`web_search` 工具走模型 provider 的搜索端点,2026-11-30 实测 **HTTP 402 余额不足**;
|
|
6
|
+
但**普通 HTTP 是通的**(实测 api.github.com 200、www.bing.com 200)。所以给灵枢自带一条
|
|
7
|
+
"能联网就联网"的调研路径:
|
|
8
|
+
|
|
9
|
+
brain.py web search "关键词" # Bing HTML 结果(标题 + 链接)
|
|
10
|
+
brain.py web fetch <url> # 抓正文纯文本(去标签/脚本,限长)
|
|
11
|
+
|
|
12
|
+
调研阶梯(按顺序用,失败才降级):
|
|
13
|
+
1. `web` 工具 / `report-page` 技能(如果可用)
|
|
14
|
+
2. 本工具:search + fetch(Bing HTML + urllib)
|
|
15
|
+
3. `skill` 里的 webapp-testing(Playwright,能跑真浏览器)
|
|
16
|
+
4. 本地取证:安装包(asar)/ 源码 / 文档
|
|
17
|
+
|
|
18
|
+
设计约束:零依赖;超时短(默认 12s);UA 伪装;任何异常都返回结构化错误而不是抛栈。
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import html as _html
|
|
23
|
+
import json
|
|
24
|
+
import re
|
|
25
|
+
import urllib.parse
|
|
26
|
+
import urllib.request
|
|
27
|
+
|
|
28
|
+
UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
29
|
+
"(KHTML, like Gecko) Chrome/120.0 Safari/537.36")
|
|
30
|
+
MAX_HTML = 4 << 20 # 4MB 上限,防超大页面拖死
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _get(url: str, timeout: float = 12.0) -> tuple:
|
|
34
|
+
"""返回 (status, text)。失败返回 (0, 错误信息)。只在 HTTP 错误时也尽量读 body。"""
|
|
35
|
+
try:
|
|
36
|
+
req = urllib.request.Request(url, headers={
|
|
37
|
+
"User-Agent": UA,
|
|
38
|
+
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
|
39
|
+
"Accept": "text/html,application/xhtml+xml,application/json;q=0.9,*/*;q=0.8",
|
|
40
|
+
})
|
|
41
|
+
with urllib.request.urlopen(req, timeout=timeout) as r:
|
|
42
|
+
raw = r.read(MAX_HTML)
|
|
43
|
+
charset = r.headers.get_content_charset() or "utf-8"
|
|
44
|
+
try:
|
|
45
|
+
text = raw.decode(charset, "replace")
|
|
46
|
+
except LookupError:
|
|
47
|
+
text = raw.decode("utf-8", "replace")
|
|
48
|
+
return r.status, text
|
|
49
|
+
except Exception as exc: # noqa: BLE001
|
|
50
|
+
return 0, f"{type(exc).__name__}: {exc}"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def search(query: str, n: int = 8, timeout: float = 12.0) -> dict:
|
|
54
|
+
"""Bing HTML 搜索,返回 {ok, query, results:[{title,url}]}。"""
|
|
55
|
+
q = urllib.parse.quote_plus(query)
|
|
56
|
+
status, body = _get(f"https://www.bing.com/search?q={q}&setlang=zh-CN", timeout)
|
|
57
|
+
if status != 200:
|
|
58
|
+
return {"ok": False, "query": query, "error": body, "results": []}
|
|
59
|
+
out, seen = [], set()
|
|
60
|
+
for m in re.finditer(r"<h2[^>]*>\s*<a[^>]*href=\"([^\"]+)\"[^>]*>(.*?)</a>\s*</h2>", body, re.S):
|
|
61
|
+
url = _html.unescape(m.group(1))
|
|
62
|
+
title = _html.unescape(re.sub(r"<[^>]+>", "", m.group(2))).strip()
|
|
63
|
+
if not title or url.startswith("javascript") or url in seen:
|
|
64
|
+
continue
|
|
65
|
+
# Bing 会把真实链接包在 /ck/a?u=a1... 里,能解就解
|
|
66
|
+
if "bing.com/ck/a" in url:
|
|
67
|
+
qs = urllib.parse.parse_qs(urllib.parse.urlparse(url).query)
|
|
68
|
+
u = (qs.get("u") or [""])[0]
|
|
69
|
+
if u.startswith("a1"):
|
|
70
|
+
u = u[2:]
|
|
71
|
+
try:
|
|
72
|
+
import base64
|
|
73
|
+
pad = "=" * (-len(u) % 4)
|
|
74
|
+
url = base64.urlsafe_b64decode(u + pad).decode("utf-8", "replace")
|
|
75
|
+
except Exception:
|
|
76
|
+
pass
|
|
77
|
+
seen.add(url)
|
|
78
|
+
out.append({"title": title, "url": url})
|
|
79
|
+
if len(out) >= max(1, int(n)):
|
|
80
|
+
break
|
|
81
|
+
return {"ok": bool(out), "query": query, "results": out}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def fetch(url: str, max_chars: int = 20000, timeout: float = 15.0) -> dict:
|
|
85
|
+
"""抓页面并抽正文纯文本(去 script/style/标签,压缩空白)。"""
|
|
86
|
+
status, body = _get(url, timeout)
|
|
87
|
+
if status != 200:
|
|
88
|
+
return {"ok": False, "url": url, "error": body, "text": ""}
|
|
89
|
+
t = re.sub(r"<script[\s\S]*?</script>|<style[\s\S]*?</style>|<!--[\s\S]*?-->", " ", body, flags=re.I)
|
|
90
|
+
t = re.sub(r"<br\s*/?>|</p>|</div>|</h[1-6]>|</li>", "\n", t, flags=re.I)
|
|
91
|
+
t = re.sub(r"<[^>]+>", " ", t)
|
|
92
|
+
t = _html.unescape(t)
|
|
93
|
+
t = re.sub(r"[ \t\u00a0]+", " ", t)
|
|
94
|
+
t = re.sub(r"\n\s*\n+", "\n\n", t).strip()
|
|
95
|
+
return {"ok": True, "url": url, "chars": len(t), "text": t[:max_chars]}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def render_search(d: dict) -> list:
|
|
99
|
+
if not d.get("ok"):
|
|
100
|
+
return [f"搜索失败:{d.get('error')}", "(可依次降级:web fetch 直连 → playwright 技能 → 本地取证)"]
|
|
101
|
+
lines = [f"搜索「{d['query']}」→ {len(d['results'])} 条:"]
|
|
102
|
+
for i, r in enumerate(d["results"], 1):
|
|
103
|
+
lines.append(f" {i}. {r['title']}")
|
|
104
|
+
lines.append(f" {r['url']}")
|
|
105
|
+
return lines
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def run(args) -> int:
|
|
109
|
+
action = getattr(args, "web_action", None) or "search"
|
|
110
|
+
if action == "fetch":
|
|
111
|
+
d = fetch(args.url, max_chars=int(getattr(args, "max_chars", 20000) or 20000))
|
|
112
|
+
if getattr(args, "json", False):
|
|
113
|
+
print(json.dumps(d, ensure_ascii=False, indent=2))
|
|
114
|
+
elif d["ok"]:
|
|
115
|
+
print(d["text"])
|
|
116
|
+
else:
|
|
117
|
+
print(f"抓取失败:{d.get('error')}", file=__import__("sys").stderr)
|
|
118
|
+
return 0 if d["ok"] else 1
|
|
119
|
+
d = search(args.query, n=int(getattr(args, "limit", 8) or 8))
|
|
120
|
+
if getattr(args, "json", False):
|
|
121
|
+
print(json.dumps(d, ensure_ascii=False, indent=2))
|
|
122
|
+
else:
|
|
123
|
+
for line in render_search(d):
|
|
124
|
+
print(line)
|
|
125
|
+
return 0 if d.get("ok") else 1
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""Big Five 数值化(do-later「M」,§14.1 决定版)。
|
|
4
|
+
|
|
5
|
+
问题:traits 是自由命名(好奇/温和/理智…),**改名或加轴,历史就不可比**;
|
|
6
|
+
drift 散度需要固定维度。
|
|
7
|
+
|
|
8
|
+
做法:固定 5 维,把现有 traits 按关键词归并(未列出的**不计分**,避免瞎归):
|
|
9
|
+
开放性 ← 好奇/求知/探索/创造/审美
|
|
10
|
+
尽责性 ← 严谨/理智/秩序/尽责/条理
|
|
11
|
+
外向性 ← 表达/社交/热烈/主动
|
|
12
|
+
宜人性 ← 温和/共情/包容/体贴
|
|
13
|
+
神经质 ← 敏感/焦虑/波动/脆弱(**低=情绪稳定**)
|
|
14
|
+
|
|
15
|
+
用法:
|
|
16
|
+
brain.py bigfive # 看当前 5 维
|
|
17
|
+
brain.py bigfive --save # 写进 persona.json 的 big_five(供 drift 比较)
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import brain
|
|
22
|
+
import core
|
|
23
|
+
from core import _num
|
|
24
|
+
|
|
25
|
+
DIMENSIONS = ("开放性", "尽责性", "外向性", "宜人性", "神经质")
|
|
26
|
+
|
|
27
|
+
MAP = {
|
|
28
|
+
"开放性": ("好奇", "求知", "探索", "创造", "审美", "开放", "想象"),
|
|
29
|
+
"尽责性": ("严谨", "理智", "秩序", "尽责", "条理", "自律", "克制"),
|
|
30
|
+
"外向性": ("表达", "社交", "热烈", "主动", "外向", "健谈", "热情"),
|
|
31
|
+
"宜人性": ("温和", "共情", "包容", "体贴", "善意", "耐心", "友好"),
|
|
32
|
+
"神经质": ("敏感", "焦虑", "波动", "脆弱", "易感", "紧张", "情绪化"),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def compute(persona: dict | None = None) -> dict:
|
|
37
|
+
"""把自由命名的 traits 归并成 5 维(0~100)。未命中任何维度的 trait 不计分。"""
|
|
38
|
+
p = persona if isinstance(persona, dict) else (brain.load_persona() or {})
|
|
39
|
+
traits = p.get("traits") or {}
|
|
40
|
+
acc: dict = {d: [] for d in DIMENSIONS}
|
|
41
|
+
unmapped = []
|
|
42
|
+
for name, val in traits.items():
|
|
43
|
+
key = str(name)
|
|
44
|
+
# traits 是嵌套结构 {value, why, evidence},不是裸数字——直接 _num(dict) 会得 0。
|
|
45
|
+
_raw = val.get("value") if isinstance(val, dict) else val
|
|
46
|
+
v = _num(_raw, 0.0)
|
|
47
|
+
hit = None
|
|
48
|
+
for dim, words in MAP.items():
|
|
49
|
+
if any(w in key for w in words):
|
|
50
|
+
hit = dim
|
|
51
|
+
break
|
|
52
|
+
if hit:
|
|
53
|
+
acc[hit].append(v)
|
|
54
|
+
else:
|
|
55
|
+
unmapped.append(key)
|
|
56
|
+
out = {d: (round(sum(vs) / len(vs), 1) if vs else None) for d, vs in acc.items()}
|
|
57
|
+
out["_unmapped"] = unmapped
|
|
58
|
+
out["_n"] = sum(len(v) for v in acc.values())
|
|
59
|
+
return out
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def save(values: dict | None = None) -> dict:
|
|
63
|
+
vals = values or compute()
|
|
64
|
+
clean = {k: v for k, v in vals.items() if k in DIMENSIONS}
|
|
65
|
+
with core._locked(core.HOME / "persona.json"):
|
|
66
|
+
p = brain.load_persona() or {}
|
|
67
|
+
p["big_five"] = clean
|
|
68
|
+
brain.save_persona(p)
|
|
69
|
+
return clean
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def render(v: dict) -> list:
|
|
73
|
+
lines = []
|
|
74
|
+
for d in DIMENSIONS:
|
|
75
|
+
x = v.get(d)
|
|
76
|
+
lines.append(f" {d:<4} {'—' if x is None else str(x):>5}")
|
|
77
|
+
if v.get("_unmapped"):
|
|
78
|
+
lines.append(f" (未映射的 traits:{'、'.join(v['_unmapped'][:8])}——按决定不计分)")
|
|
79
|
+
return lines
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def run(args) -> int:
|
|
83
|
+
v = compute()
|
|
84
|
+
print("Big Five(由 traits 归并,未映射不计分):")
|
|
85
|
+
for line in render(v):
|
|
86
|
+
print(line)
|
|
87
|
+
if getattr(args, "save", False):
|
|
88
|
+
saved = save(v)
|
|
89
|
+
print("已写入 persona.json 的 big_five:", saved)
|
|
90
|
+
return 0
|
package/scripts/brain.py
CHANGED
|
@@ -27,7 +27,7 @@ _MODULES = (core, memory, emotion, persona, dream, cli)
|
|
|
27
27
|
# 登记进 _SYNC_TARGETS,让 _sync_state() 把状态同步过去(注意只登记进同步表,
|
|
28
28
|
# 不进 _MODULES:它们的命名空间不该参与双向合并)。
|
|
29
29
|
_EXTRA_SYNC = []
|
|
30
|
-
for _name in ("mem_lesson", "mem_score", "mem_topic", "mem_dialogue"
|
|
30
|
+
for _name in ("mem_lesson", "mem_score", "mem_topic", "mem_dialogue"):
|
|
31
31
|
_m = sys.modules.get(_name)
|
|
32
32
|
if _m is not None:
|
|
33
33
|
_EXTRA_SYNC.append(_m)
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""文档数字自检(§3 C)。
|
|
4
|
+
|
|
5
|
+
为什么要有它:文档里的"45 个情绪名 / 13 项体检 / 15 个页签 / 29 项设置 / 75 个命令"
|
|
6
|
+
全是**手写**的,改代码时没人回去同步,于是反复对不上(实测一次就抓出 5 处)。
|
|
7
|
+
这里从代码**现算**真值,再和文档里抓到的数字比对,不一致就非零退出——接进 CI
|
|
8
|
+
就能防复发(与 check_version.py 同层)。
|
|
9
|
+
|
|
10
|
+
用法:
|
|
11
|
+
python scripts/check_docs.py # 报告差异(不一致 exit 1)
|
|
12
|
+
python scripts/check_docs.py --json
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
import subprocess
|
|
19
|
+
import sys
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
23
|
+
SCRIPTS = ROOT / "scripts"
|
|
24
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _truth() -> dict:
|
|
28
|
+
"""从代码现算真实数字。任何一项失败就留 None(不猜)。"""
|
|
29
|
+
t: dict = {}
|
|
30
|
+
|
|
31
|
+
# 情绪:名数 + 分组
|
|
32
|
+
try:
|
|
33
|
+
import emotion
|
|
34
|
+
emos = getattr(emotion, "EMOTIONS", {}) or {}
|
|
35
|
+
t["emotions"] = len(emos)
|
|
36
|
+
grp = getattr(emotion, "EMOTION_GROUPS", None)
|
|
37
|
+
if isinstance(grp, dict) and grp:
|
|
38
|
+
t["emotion_groups"] = len(grp)
|
|
39
|
+
except Exception:
|
|
40
|
+
t["emotions"] = None
|
|
41
|
+
|
|
42
|
+
# doctor 项数:直接跑 --json 数(最不容易和实现漂移)
|
|
43
|
+
try:
|
|
44
|
+
r = subprocess.run([sys.executable, str(SCRIPTS / "brain.py"), "doctor", "--json"],
|
|
45
|
+
cwd=ROOT, capture_output=True, text=True,
|
|
46
|
+
encoding="utf-8", errors="replace", timeout=300)
|
|
47
|
+
txt = r.stdout
|
|
48
|
+
i = txt.find("{")
|
|
49
|
+
t["doctor"] = len(json.loads(txt[i:]).get("checks") or [])
|
|
50
|
+
except Exception:
|
|
51
|
+
t["doctor"] = None
|
|
52
|
+
|
|
53
|
+
# 面板页签:从产物里数 data-tab 的唯一名字
|
|
54
|
+
try:
|
|
55
|
+
html = (ROOT / "assets" / "panel.html").read_text(encoding="utf-8", errors="replace")
|
|
56
|
+
names = re.findall(r'data-tab="([^"]+)"', html)
|
|
57
|
+
t["panel_tabs"] = len(set(names))
|
|
58
|
+
except Exception:
|
|
59
|
+
t["panel_tabs"] = None
|
|
60
|
+
|
|
61
|
+
# 设置项/组
|
|
62
|
+
try:
|
|
63
|
+
import panel_settings
|
|
64
|
+
schema = getattr(panel_settings, "CONFIG_SCHEMA", None)
|
|
65
|
+
if isinstance(schema, dict):
|
|
66
|
+
t["settings_groups"] = len(schema)
|
|
67
|
+
n = 0
|
|
68
|
+
for v in schema.values():
|
|
69
|
+
if isinstance(v, dict):
|
|
70
|
+
items = v.get("items") or v.get("fields") or []
|
|
71
|
+
n += len(items)
|
|
72
|
+
if n:
|
|
73
|
+
t["settings_items"] = n
|
|
74
|
+
elif isinstance(schema, list):
|
|
75
|
+
t["settings_items"] = len(schema)
|
|
76
|
+
groups = {(x or {}).get("group") for x in schema if isinstance(x, dict)}
|
|
77
|
+
groups.discard(None)
|
|
78
|
+
if groups:
|
|
79
|
+
t["settings_groups"] = len(groups)
|
|
80
|
+
except Exception:
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
# CLI 命令数:--help 的 choices
|
|
84
|
+
try:
|
|
85
|
+
r = subprocess.run([sys.executable, str(SCRIPTS / "brain.py"), "--help"],
|
|
86
|
+
cwd=ROOT, capture_output=True, text=True,
|
|
87
|
+
encoding="utf-8", errors="replace", timeout=120)
|
|
88
|
+
m = re.search(r"\{([a-z0-9,\-_]+)\}", r.stdout)
|
|
89
|
+
if m:
|
|
90
|
+
t["cli_commands"] = len(m.group(1).split(","))
|
|
91
|
+
except Exception:
|
|
92
|
+
t["cli_commands"] = None
|
|
93
|
+
return t
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# 文档里的"数字断言": (文档, 正则, 真值键, 说明)
|
|
97
|
+
CLAIMS = [
|
|
98
|
+
("SKILL.md", r"(\d+)\s*个情绪名", "emotions", "情绪名数量"),
|
|
99
|
+
("SKILL.md", r"doctor\s*\[--json\][^\n]*?(\d+)\s*项体检", "doctor", "doctor 体检项数"),
|
|
100
|
+
("SKILL.md", r"(\d+)\s*项体检", "doctor", "doctor 体检项数"),
|
|
101
|
+
("README.md", r"(\d+)\s*项体检", "doctor", "doctor 体检项数"),
|
|
102
|
+
("README.md", r"(\d+)\s*个页签", "panel_tabs", "面板页签数"),
|
|
103
|
+
("README.md", r"设置页\s*(\d+)\s*项", "settings_items", "设置项数"),
|
|
104
|
+
("README.md", r"(\d+)\s*个 CLI 命令", "cli_commands", "CLI 命令数"),
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def main(argv=None) -> int:
|
|
109
|
+
argv = list(sys.argv[1:] if argv is None else argv)
|
|
110
|
+
truth = _truth()
|
|
111
|
+
mismatches = []
|
|
112
|
+
for rel, pat, key, label in CLAIMS:
|
|
113
|
+
p = ROOT / rel
|
|
114
|
+
if not p.is_file():
|
|
115
|
+
continue
|
|
116
|
+
text = p.read_text(encoding="utf-8", errors="replace")
|
|
117
|
+
for m in re.finditer(pat, text):
|
|
118
|
+
claimed = int(m.group(1))
|
|
119
|
+
real = truth.get(key)
|
|
120
|
+
if real is None:
|
|
121
|
+
continue
|
|
122
|
+
if claimed != real:
|
|
123
|
+
line = text[:m.start()].count("\n") + 1
|
|
124
|
+
mismatches.append({"file": rel, "line": line, "label": label,
|
|
125
|
+
"claimed": claimed, "real": real,
|
|
126
|
+
"snippet": text[max(0, m.start() - 30):m.end() + 20].replace("\n", " ")})
|
|
127
|
+
|
|
128
|
+
# 额外:命令名必须真实存在(照做会报错的那类)
|
|
129
|
+
bad_cmds = []
|
|
130
|
+
try:
|
|
131
|
+
r = subprocess.run([sys.executable, str(SCRIPTS / "brain.py"), "--help"],
|
|
132
|
+
cwd=ROOT, capture_output=True, text=True,
|
|
133
|
+
encoding="utf-8", errors="replace", timeout=120)
|
|
134
|
+
m = re.search(r"\{([a-z0-9,\-_]+)\}", r.stdout)
|
|
135
|
+
valid = set(m.group(1).split(",")) if m else set()
|
|
136
|
+
for rel in ("README.md", "SKILL.md"):
|
|
137
|
+
p = ROOT / rel
|
|
138
|
+
if not p.is_file():
|
|
139
|
+
continue
|
|
140
|
+
text = p.read_text(encoding="utf-8", errors="replace")
|
|
141
|
+
for cm in re.finditer(r"brain\.py\s+([a-z][a-z0-9\-]+)", text):
|
|
142
|
+
name = cm.group(1)
|
|
143
|
+
if not valid or name in valid:
|
|
144
|
+
continue
|
|
145
|
+
# 有些命令(如 `skill`)是隐藏的:不进 --help 的 choices 但确实可用。
|
|
146
|
+
# 所以不靠列表下结论,真跑一次 --help 验证(只对少数候选做,代价可忽略)。
|
|
147
|
+
try:
|
|
148
|
+
rr = subprocess.run([sys.executable, str(SCRIPTS / "brain.py"), name, "--help"],
|
|
149
|
+
cwd=ROOT, capture_output=True, text=True,
|
|
150
|
+
encoding="utf-8", errors="replace", timeout=60)
|
|
151
|
+
if rr.returncode == 0 or "invalid choice" not in (rr.stderr or ""):
|
|
152
|
+
continue
|
|
153
|
+
except Exception:
|
|
154
|
+
pass
|
|
155
|
+
line = text[:cm.start()].count("\n") + 1
|
|
156
|
+
bad_cmds.append({"file": rel, "line": line, "command": name})
|
|
157
|
+
except Exception:
|
|
158
|
+
pass
|
|
159
|
+
|
|
160
|
+
if "--json" in argv:
|
|
161
|
+
print(json.dumps({"truth": truth, "mismatches": mismatches,
|
|
162
|
+
"bad_commands": bad_cmds}, ensure_ascii=False, indent=2))
|
|
163
|
+
else:
|
|
164
|
+
print("[check_docs] 代码现算的真值:")
|
|
165
|
+
for k, v in truth.items():
|
|
166
|
+
print(f" {k:<16} = {v}")
|
|
167
|
+
if not mismatches and not bad_cmds:
|
|
168
|
+
print("\n[check_docs] 文档数字与命令名全部对得上 ✔")
|
|
169
|
+
for m in mismatches:
|
|
170
|
+
print(f"\n[不一致] {m['file']}:{m['line']} {m['label']}:文档写 {m['claimed']},实际 {m['real']}")
|
|
171
|
+
print(f" …{m['snippet']}…")
|
|
172
|
+
seen = set()
|
|
173
|
+
for b in bad_cmds:
|
|
174
|
+
key = (b["file"], b["command"])
|
|
175
|
+
if key in seen:
|
|
176
|
+
continue
|
|
177
|
+
seen.add(key)
|
|
178
|
+
print(f"\n[命令不存在] {b['file']}:{b['line']} `brain.py {b['command']}`")
|
|
179
|
+
return 1 if (mismatches or bad_cmds) else 0
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
if __name__ == "__main__":
|
|
183
|
+
for _n in ("stdout", "stderr"):
|
|
184
|
+
_s = getattr(sys, _n, None)
|
|
185
|
+
_f = getattr(_s, "reconfigure", None)
|
|
186
|
+
if callable(_f):
|
|
187
|
+
try:
|
|
188
|
+
_f(encoding="utf-8", errors="replace")
|
|
189
|
+
except (OSError, ValueError, AttributeError):
|
|
190
|
+
pass
|
|
191
|
+
sys.exit(main())
|