lingshu-skill 5.33.0 → 5.37.1
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 -4227
- package/README.md +1584 -1577
- package/SKILL-lite.md +59 -59
- package/SKILL-tiny.md +38 -38
- package/SKILL.md +356 -331
- 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 -4227
- 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 -331
- 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 +921 -86
- 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 +530 -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 +921 -86
- 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 +530 -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//344/272/244/346/216/245/347/254/224/350/256/260-20261128.md +0 -128
- package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +0 -408
|
@@ -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
|
|
@@ -1,107 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
3
|
-
# 用法(从哪个目录跑都行,脚本自己定位仓库根):
|
|
4
|
-
# powershell -ExecutionPolicy Bypass -File "<仓库>\scripts\update_dsh_copy.ps1"
|
|
5
|
-
# powershell -ExecutionPolicy Bypass -File "<仓库>\scripts\update_dsh_copy.ps1" -Profile desktop
|
|
6
|
-
#
|
|
7
|
-
# 为什么不再用 robocopy /E 整目录复制:那会把仓库旁边的本地杂物一起塞进插件目录
|
|
8
|
-
# (实测 .tmp_refs 129 MB、_ui_probe 12 MB、panel_src/tests 若干),而 DSH 只需要
|
|
9
|
-
# 发布清单 manifest.json 里的交付物。现在只拷清单里列出的文件(当前 65 个)。
|
|
10
|
-
#
|
|
11
|
-
# P1-1:engine/ 是 scripts/+docs/ 的派生副本,已从 git 移除(见 .gitignore)。
|
|
12
|
-
# 它不在发布清单里,本脚本也不复制它——目标副本的 engine 由市场包安装时带进来。
|
|
13
|
-
# 若从全新 clone 跑本脚本,磁盘可能还没有 engine;此时先手动跑一次
|
|
14
|
-
# `python scripts\sync_engine.py` 生成(幂等),否则同步后 doctor 的 engine-sync
|
|
15
|
-
# 会因源端缺 engine 而红。生成 engine 属于发版/打包职责,不塞进本脚本以免引入
|
|
16
|
-
# "找不到 python 解释器"的新失败点。
|
|
17
|
-
# 退出码:0 成功;1 有文件没拷成(多半是 DSH 正占用,完全退出 DSH 后重跑)。
|
|
18
|
-
|
|
19
|
-
param(
|
|
20
|
-
[string]$Profile = ""
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
$ErrorActionPreference = "Stop"
|
|
24
|
-
|
|
25
|
-
$src = Split-Path -Parent $PSScriptRoot # 仓库根目录(本脚本在 scripts/ 下)
|
|
26
|
-
$profilesRoot = Join-Path $env:USERPROFILE ".dsh\profiles"
|
|
27
|
-
|
|
28
|
-
function Get-CopyVersion($dir) {
|
|
29
|
-
try {
|
|
30
|
-
$pkg = Get-Content -LiteralPath (Join-Path $dir "package.json") -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
31
|
-
return [string]$pkg.version
|
|
32
|
-
} catch {
|
|
33
|
-
return "?"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
# 1) 找目标副本:指定 profile,否则自动挑所有已装 lingshu-skill 的 profile
|
|
38
|
-
$targets = @()
|
|
39
|
-
if ($Profile) {
|
|
40
|
-
$one = Join-Path $profilesRoot "$Profile\node_modules\lingshu-skill"
|
|
41
|
-
if (-not (Test-Path $one)) {
|
|
42
|
-
Write-Host "[错误] profile「$Profile」下没有 lingshu-skill:$one" -ForegroundColor Red
|
|
43
|
-
exit 1
|
|
44
|
-
}
|
|
45
|
-
$targets = @($one)
|
|
46
|
-
} elseif (Test-Path $profilesRoot) {
|
|
47
|
-
foreach ($p in Get-ChildItem -LiteralPath $profilesRoot -Directory) {
|
|
48
|
-
$d = Join-Path $p.FullName "node_modules\lingshu-skill"
|
|
49
|
-
if (Test-Path $d) { $targets += $d }
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (-not $targets) {
|
|
53
|
-
Write-Host "[错误] 找不到任何 DSH profile 里的 lingshu-skill 副本。" -ForegroundColor Red
|
|
54
|
-
Write-Host " 先让 DSH 装一次 lingshu-skill,或用 -Profile <名字> 指定 profile。" -ForegroundColor Red
|
|
55
|
-
exit 1
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
# 2) 读发布清单
|
|
59
|
-
$mfPath = Join-Path $src "manifest.json"
|
|
60
|
-
if (-not (Test-Path $mfPath)) {
|
|
61
|
-
Write-Host "[错误] 缺少 manifest.json(发布清单):$mfPath" -ForegroundColor Red
|
|
62
|
-
Write-Host " 先在仓库根运行:python scripts\make_manifest.py" -ForegroundColor Red
|
|
63
|
-
exit 1
|
|
64
|
-
}
|
|
65
|
-
$manifest = Get-Content -LiteralPath $mfPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
66
|
-
$files = @($manifest.files.PSObject.Properties | ForEach-Object { $_.Name })
|
|
67
|
-
if ($files.Count -eq 0) {
|
|
68
|
-
Write-Host "[错误] manifest.json 里没有任何文件条目。" -ForegroundColor Red
|
|
69
|
-
exit 1
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
# 3) 逐文件复制(不删除目标里多出来的旧文件,避免误删用户自装的东西)
|
|
73
|
-
$hadFailure = $false
|
|
74
|
-
foreach ($dst in $targets) {
|
|
75
|
-
$before = Get-CopyVersion $dst
|
|
76
|
-
$copied = 0
|
|
77
|
-
$failed = @()
|
|
78
|
-
foreach ($rel in $files) {
|
|
79
|
-
$relWin = $rel -replace '/', '\'
|
|
80
|
-
$s = Join-Path $src $relWin
|
|
81
|
-
$d = Join-Path $dst $relWin
|
|
82
|
-
try {
|
|
83
|
-
if (-not (Test-Path -LiteralPath $s)) { throw "源文件缺失" }
|
|
84
|
-
$dDir = Split-Path -Parent $d
|
|
85
|
-
if (-not (Test-Path -LiteralPath $dDir)) {
|
|
86
|
-
New-Item -ItemType Directory -Force -Path $dDir | Out-Null
|
|
87
|
-
}
|
|
88
|
-
Copy-Item -LiteralPath $s -Destination $d -Force
|
|
89
|
-
$copied++
|
|
90
|
-
} catch {
|
|
91
|
-
$failed += ("{0} —— {1}" -f $rel, $_.Exception.Message)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
$after = Get-CopyVersion $dst
|
|
95
|
-
Write-Host ("[同步] {0}" -f $dst)
|
|
96
|
-
Write-Host (" 版本 {0} -> {1},复制 {2}/{3} 个文件" -f $before, $after, $copied, $files.Count) -ForegroundColor Green
|
|
97
|
-
if ($failed.Count -gt 0) {
|
|
98
|
-
$hadFailure = $true
|
|
99
|
-
Write-Host (" 失败 {0} 个(多半是 DSH 正在占用文件,完全退出 DSH 后重跑):" -f $failed.Count) -ForegroundColor Yellow
|
|
100
|
-
$failed | Select-Object -First 5 | ForEach-Object { Write-Host (" - {0}" -f $_) -ForegroundColor Yellow }
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if ($hadFailure) { exit 1 }
|
|
105
|
-
|
|
106
|
-
Write-Host "[完成] 把 lingshu-skill 插件关一次再开一次(或重启 DSH),新版本才会被加载。" -ForegroundColor Green
|
|
107
|
-
Write-Host "
|
|
1
|
+
# 灵枢 → DSH 插件目录热同步(按发布清单精确复制,不重启 DSH)
|
|
2
|
+
#
|
|
3
|
+
# 用法(从哪个目录跑都行,脚本自己定位仓库根):
|
|
4
|
+
# powershell -ExecutionPolicy Bypass -File "<仓库>\scripts\update_dsh_copy.ps1"
|
|
5
|
+
# powershell -ExecutionPolicy Bypass -File "<仓库>\scripts\update_dsh_copy.ps1" -Profile desktop
|
|
6
|
+
#
|
|
7
|
+
# 为什么不再用 robocopy /E 整目录复制:那会把仓库旁边的本地杂物一起塞进插件目录
|
|
8
|
+
# (实测 .tmp_refs 129 MB、_ui_probe 12 MB、panel_src/tests 若干),而 DSH 只需要
|
|
9
|
+
# 发布清单 manifest.json 里的交付物。现在只拷清单里列出的文件(当前 65 个)。
|
|
10
|
+
#
|
|
11
|
+
# P1-1:engine/ 是 scripts/+docs/ 的派生副本,已从 git 移除(见 .gitignore)。
|
|
12
|
+
# 它不在发布清单里,本脚本也不复制它——目标副本的 engine 由市场包安装时带进来。
|
|
13
|
+
# 若从全新 clone 跑本脚本,磁盘可能还没有 engine;此时先手动跑一次
|
|
14
|
+
# `python scripts\sync_engine.py` 生成(幂等),否则同步后 doctor 的 engine-sync
|
|
15
|
+
# 会因源端缺 engine 而红。生成 engine 属于发版/打包职责,不塞进本脚本以免引入
|
|
16
|
+
# "找不到 python 解释器"的新失败点。
|
|
17
|
+
# 退出码:0 成功;1 有文件没拷成(多半是 DSH 正占用,完全退出 DSH 后重跑)。
|
|
18
|
+
|
|
19
|
+
param(
|
|
20
|
+
[string]$Profile = ""
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
$ErrorActionPreference = "Stop"
|
|
24
|
+
|
|
25
|
+
$src = Split-Path -Parent $PSScriptRoot # 仓库根目录(本脚本在 scripts/ 下)
|
|
26
|
+
$profilesRoot = Join-Path $env:USERPROFILE ".dsh\profiles"
|
|
27
|
+
|
|
28
|
+
function Get-CopyVersion($dir) {
|
|
29
|
+
try {
|
|
30
|
+
$pkg = Get-Content -LiteralPath (Join-Path $dir "package.json") -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
31
|
+
return [string]$pkg.version
|
|
32
|
+
} catch {
|
|
33
|
+
return "?"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# 1) 找目标副本:指定 profile,否则自动挑所有已装 lingshu-skill 的 profile
|
|
38
|
+
$targets = @()
|
|
39
|
+
if ($Profile) {
|
|
40
|
+
$one = Join-Path $profilesRoot "$Profile\node_modules\lingshu-skill"
|
|
41
|
+
if (-not (Test-Path $one)) {
|
|
42
|
+
Write-Host "[错误] profile「$Profile」下没有 lingshu-skill:$one" -ForegroundColor Red
|
|
43
|
+
exit 1
|
|
44
|
+
}
|
|
45
|
+
$targets = @($one)
|
|
46
|
+
} elseif (Test-Path $profilesRoot) {
|
|
47
|
+
foreach ($p in Get-ChildItem -LiteralPath $profilesRoot -Directory) {
|
|
48
|
+
$d = Join-Path $p.FullName "node_modules\lingshu-skill"
|
|
49
|
+
if (Test-Path $d) { $targets += $d }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (-not $targets) {
|
|
53
|
+
Write-Host "[错误] 找不到任何 DSH profile 里的 lingshu-skill 副本。" -ForegroundColor Red
|
|
54
|
+
Write-Host " 先让 DSH 装一次 lingshu-skill,或用 -Profile <名字> 指定 profile。" -ForegroundColor Red
|
|
55
|
+
exit 1
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
# 2) 读发布清单
|
|
59
|
+
$mfPath = Join-Path $src "manifest.json"
|
|
60
|
+
if (-not (Test-Path $mfPath)) {
|
|
61
|
+
Write-Host "[错误] 缺少 manifest.json(发布清单):$mfPath" -ForegroundColor Red
|
|
62
|
+
Write-Host " 先在仓库根运行:python scripts\make_manifest.py" -ForegroundColor Red
|
|
63
|
+
exit 1
|
|
64
|
+
}
|
|
65
|
+
$manifest = Get-Content -LiteralPath $mfPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
66
|
+
$files = @($manifest.files.PSObject.Properties | ForEach-Object { $_.Name })
|
|
67
|
+
if ($files.Count -eq 0) {
|
|
68
|
+
Write-Host "[错误] manifest.json 里没有任何文件条目。" -ForegroundColor Red
|
|
69
|
+
exit 1
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# 3) 逐文件复制(不删除目标里多出来的旧文件,避免误删用户自装的东西)
|
|
73
|
+
$hadFailure = $false
|
|
74
|
+
foreach ($dst in $targets) {
|
|
75
|
+
$before = Get-CopyVersion $dst
|
|
76
|
+
$copied = 0
|
|
77
|
+
$failed = @()
|
|
78
|
+
foreach ($rel in $files) {
|
|
79
|
+
$relWin = $rel -replace '/', '\'
|
|
80
|
+
$s = Join-Path $src $relWin
|
|
81
|
+
$d = Join-Path $dst $relWin
|
|
82
|
+
try {
|
|
83
|
+
if (-not (Test-Path -LiteralPath $s)) { throw "源文件缺失" }
|
|
84
|
+
$dDir = Split-Path -Parent $d
|
|
85
|
+
if (-not (Test-Path -LiteralPath $dDir)) {
|
|
86
|
+
New-Item -ItemType Directory -Force -Path $dDir | Out-Null
|
|
87
|
+
}
|
|
88
|
+
Copy-Item -LiteralPath $s -Destination $d -Force
|
|
89
|
+
$copied++
|
|
90
|
+
} catch {
|
|
91
|
+
$failed += ("{0} —— {1}" -f $rel, $_.Exception.Message)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
$after = Get-CopyVersion $dst
|
|
95
|
+
Write-Host ("[同步] {0}" -f $dst)
|
|
96
|
+
Write-Host (" 版本 {0} -> {1},复制 {2}/{3} 个文件" -f $before, $after, $copied, $files.Count) -ForegroundColor Green
|
|
97
|
+
if ($failed.Count -gt 0) {
|
|
98
|
+
$hadFailure = $true
|
|
99
|
+
Write-Host (" 失败 {0} 个(多半是 DSH 正在占用文件,完全退出 DSH 后重跑):" -f $failed.Count) -ForegroundColor Yellow
|
|
100
|
+
$failed | Select-Object -First 5 | ForEach-Object { Write-Host (" - {0}" -f $_) -ForegroundColor Yellow }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ($hadFailure) { exit 1 }
|
|
105
|
+
|
|
106
|
+
Write-Host "[完成] 把 lingshu-skill 插件关一次再开一次(或重启 DSH),新版本才会被加载。" -ForegroundColor Green
|
|
107
|
+
Write-Host " 验证(B2:别只看复制成功):python scripts\brain.py doctor" -ForegroundColor Green
|
|
108
|
+
Write-Host " - plugin-loaded PASS = 副本与源码一致,且之后有过「会话开始」记录" -ForegroundColor Green
|
|
109
|
+
Write-Host " - 若 WARN『副本比最近一次会话开始新』= 还没重载,重启 APP 再验" -ForegroundColor Green
|
|
110
|
+
Write-Host " - release-drift 只比版本号,不能证明已加载" -ForegroundColor Green
|
|
@@ -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
|