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,181 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""RSS/Atom 摄入(§4 P2-1,窄口径版)。
|
|
4
|
+
|
|
5
|
+
范围(按待办建议收窄):**本地 RSS/Atom 文件** 或 **显式 URL 列表**,默认不自动跑。
|
|
6
|
+
不内置定时抓取、不做订阅管理界面——想自动化就把 `rss ingest --url-list` 挂到你自己的计划任务里。
|
|
7
|
+
|
|
8
|
+
设计约束:
|
|
9
|
+
· 零依赖:`xml.etree` + `urllib`,够用;
|
|
10
|
+
· 幂等:按条目的 link(没有则 title+published)做 sha1 存 `rss_seen.json`,重复摄入不重复记;
|
|
11
|
+
· 可逆/可审计:每条记成 `kind=episode` 的记忆,带 `rss` 标签与来源链接;
|
|
12
|
+
· 宽容:坏 XML、坏日期、断网都只跳过该条/该源,不抛。
|
|
13
|
+
|
|
14
|
+
用法:
|
|
15
|
+
python scripts/brain.py rss ingest --file feed.xml
|
|
16
|
+
python scripts/brain.py rss ingest --url-list urls.txt --limit 20
|
|
17
|
+
python scripts/brain.py rss ingest --file feed.xml --dry-run
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import hashlib
|
|
22
|
+
import json
|
|
23
|
+
import re
|
|
24
|
+
import time
|
|
25
|
+
import urllib.request
|
|
26
|
+
import xml.etree.ElementTree as ET
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
|
|
29
|
+
import core
|
|
30
|
+
|
|
31
|
+
SEEN = "rss_seen.json"
|
|
32
|
+
MAX_KEEP_SEEN = 5000 # 只记最近这么多条 link 哈希,防无限增长
|
|
33
|
+
DEFAULT_LIMIT = 20
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _seen_path() -> Path:
|
|
37
|
+
return Path(core.HOME) / SEEN
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def load_seen() -> list:
|
|
41
|
+
try:
|
|
42
|
+
p = _seen_path()
|
|
43
|
+
if not p.is_file():
|
|
44
|
+
return []
|
|
45
|
+
d = json.loads(p.read_text(encoding="utf-8", errors="replace") or "[]")
|
|
46
|
+
return d if isinstance(d, list) else []
|
|
47
|
+
except Exception:
|
|
48
|
+
return []
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def save_seen(items: list) -> None:
|
|
52
|
+
try:
|
|
53
|
+
if getattr(core, "READONLY", False):
|
|
54
|
+
return
|
|
55
|
+
with core._locked(core.HOME / SEEN):
|
|
56
|
+
core.atomic_json(_seen_path(), items[-MAX_KEEP_SEEN:])
|
|
57
|
+
except Exception:
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _text(el) -> str:
|
|
62
|
+
if el is None:
|
|
63
|
+
return ""
|
|
64
|
+
return re.sub(r"\s+", " ", "".join(el.itertext())).strip()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def parse_feed(raw: bytes) -> list:
|
|
68
|
+
"""解析 RSS 2.0 / Atom。返回 [{title, link, summary, published}]。"""
|
|
69
|
+
out = []
|
|
70
|
+
try:
|
|
71
|
+
root = ET.fromstring(raw)
|
|
72
|
+
except Exception:
|
|
73
|
+
return out
|
|
74
|
+
# Atom: {http://www.w3.org/2005/Atom}entry
|
|
75
|
+
ns_atom = "{http://www.w3.org/2005/Atom}"
|
|
76
|
+
entries = root.findall(f".//{ns_atom}entry")
|
|
77
|
+
if entries:
|
|
78
|
+
for e in entries:
|
|
79
|
+
link = ""
|
|
80
|
+
for ln in e.findall(f"{ns_atom}link"):
|
|
81
|
+
if ln.get("rel") in (None, "alternate") and ln.get("href"):
|
|
82
|
+
link = ln.get("href")
|
|
83
|
+
break
|
|
84
|
+
# ⚠ 不能写 `e.find(summary) or e.find(content)`:ElementTree 里**空元素布尔值为 False**,
|
|
85
|
+
# 一个没有子节点的 <summary> 会让 or 落到 content 上(实测 Atom 摘要因此变空)。
|
|
86
|
+
_sum = e.find(f"{ns_atom}summary")
|
|
87
|
+
if _sum is None:
|
|
88
|
+
_sum = e.find(f"{ns_atom}content")
|
|
89
|
+
_pub = e.find(f"{ns_atom}published")
|
|
90
|
+
if _pub is None:
|
|
91
|
+
_pub = e.find(f"{ns_atom}updated")
|
|
92
|
+
out.append({
|
|
93
|
+
"title": _text(e.find(f"{ns_atom}title")),
|
|
94
|
+
"link": link,
|
|
95
|
+
"summary": _text(_sum),
|
|
96
|
+
"published": _text(_pub),
|
|
97
|
+
})
|
|
98
|
+
return out
|
|
99
|
+
# RSS 2.0: channel/item
|
|
100
|
+
for it in root.findall(".//item"):
|
|
101
|
+
out.append({
|
|
102
|
+
"title": _text(it.find("title")),
|
|
103
|
+
"link": _text(it.find("link")),
|
|
104
|
+
"summary": _text(it.find("description")),
|
|
105
|
+
"published": _text(it.find("pubDate")),
|
|
106
|
+
})
|
|
107
|
+
return out
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _key(it: dict) -> str:
|
|
111
|
+
basis = (it.get("link") or "").strip() or (it.get("title", "") + "|" + it.get("published", ""))
|
|
112
|
+
return hashlib.sha1(basis.encode("utf-8", "replace")).hexdigest()[:16]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _fetch(url: str, timeout: float = 15.0) -> bytes | None:
|
|
116
|
+
try:
|
|
117
|
+
req = urllib.request.Request(url, headers={"User-Agent": "lingshu-rss/1.0"})
|
|
118
|
+
with urllib.request.urlopen(req, timeout=timeout) as r:
|
|
119
|
+
return r.read()
|
|
120
|
+
except Exception:
|
|
121
|
+
return None
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def ingest(files=None, urls=None, limit: int = DEFAULT_LIMIT, dry_run: bool = False) -> dict:
|
|
125
|
+
"""从本地文件 / 显式 URL 摄入条目。返回 {sources, parsed, new, ingested, errors}。"""
|
|
126
|
+
import memory # 延迟导入:只有真要写记忆时才需要
|
|
127
|
+
|
|
128
|
+
files = list(files or [])
|
|
129
|
+
urls = list(urls or [])
|
|
130
|
+
seen = load_seen()
|
|
131
|
+
seen_set = set(seen)
|
|
132
|
+
stats = {"sources": 0, "parsed": 0, "new": 0, "ingested": 0, "errors": []}
|
|
133
|
+
|
|
134
|
+
raws: list = []
|
|
135
|
+
for f in files:
|
|
136
|
+
try:
|
|
137
|
+
raws.append(Path(f).read_bytes())
|
|
138
|
+
stats["sources"] += 1
|
|
139
|
+
except Exception as e: # noqa: BLE001
|
|
140
|
+
stats["errors"].append(f"{f}: {e}")
|
|
141
|
+
for u in urls:
|
|
142
|
+
b = _fetch(u)
|
|
143
|
+
if b is None:
|
|
144
|
+
stats["errors"].append(f"{u}: 拉取失败")
|
|
145
|
+
continue
|
|
146
|
+
raws.append(b)
|
|
147
|
+
stats["sources"] += 1
|
|
148
|
+
|
|
149
|
+
for raw in raws:
|
|
150
|
+
items = parse_feed(raw)
|
|
151
|
+
stats["parsed"] += len(items)
|
|
152
|
+
for it in items:
|
|
153
|
+
if stats["new"] >= max(1, int(limit)):
|
|
154
|
+
break
|
|
155
|
+
k = _key(it)
|
|
156
|
+
if k in seen_set:
|
|
157
|
+
continue
|
|
158
|
+
stats["new"] += 1
|
|
159
|
+
if dry_run:
|
|
160
|
+
continue
|
|
161
|
+
title = (it.get("title") or "(无标题)")[:80]
|
|
162
|
+
summary = (it.get("summary") or "")[:400]
|
|
163
|
+
text = f"[RSS] {title}" + (f" —— {summary}" if summary else "")
|
|
164
|
+
try:
|
|
165
|
+
memory.remember(text, kind="episode", importance=0.4,
|
|
166
|
+
tags=["rss"], source=(it.get("link") or "rss")[:200])
|
|
167
|
+
stats["ingested"] += 1
|
|
168
|
+
seen.append(k)
|
|
169
|
+
except Exception as e: # noqa: BLE001
|
|
170
|
+
stats["errors"].append(f"{title}: {e}")
|
|
171
|
+
if not dry_run and seen:
|
|
172
|
+
save_seen(seen)
|
|
173
|
+
return stats
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def render(stats: dict) -> list[str]:
|
|
177
|
+
lines = [f"来源 {stats['sources']} 个 · 解析 {stats['parsed']} 条 · "
|
|
178
|
+
f"新条目 {stats['new']} · 已写入记忆 {stats['ingested']}"]
|
|
179
|
+
for e in (stats.get("errors") or [])[:5]:
|
|
180
|
+
lines.append(f" ⚠ {e}")
|
|
181
|
+
return lines
|
package/scripts/run_tests.py
CHANGED
|
@@ -34,6 +34,19 @@ TESTS = ROOT / "tests"
|
|
|
34
34
|
def main(argv: list[str]) -> int:
|
|
35
35
|
verbose = "-v" in argv or "--verbose" in argv
|
|
36
36
|
keywords = [a for a in argv if not a.startswith("-")]
|
|
37
|
+
# 跑测前先把 engine 派生产物刷一遍(幂等):否则"改了 scripts 忘了 sync"会让
|
|
38
|
+
# engine-sync 相关的测试红灯,看起来像业务 bug,实际只是产物过期(2026-11-29 连踩 3 次)。
|
|
39
|
+
# 失败不阻断:同步脚本自己缺失/出错时照常跑测试,只是多一条提示。
|
|
40
|
+
_sync = ROOT / "scripts" / "sync_engine.py"
|
|
41
|
+
if _sync.is_file():
|
|
42
|
+
try:
|
|
43
|
+
_r = subprocess.run([sys.executable, str(_sync)], capture_output=True,
|
|
44
|
+
text=True, encoding="utf-8", errors="replace", timeout=120)
|
|
45
|
+
_line = next((l for l in (_r.stdout or "").splitlines() if "[sync]" in l), "")
|
|
46
|
+
if _line:
|
|
47
|
+
print(_line)
|
|
48
|
+
except Exception as _e: # noqa: BLE001
|
|
49
|
+
print(f"[提示] engine 预同步跳过:{_e}")
|
|
37
50
|
files = sorted(TESTS.glob("test_*.py"))
|
|
38
51
|
if keywords:
|
|
39
52
|
files = [f for f in files if any(k in f.name for k in keywords)]
|