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.
Files changed (266) hide show
  1. package/CHANGELOG.md +4281 -4227
  2. package/README.md +1584 -1577
  3. package/SKILL-lite.md +59 -59
  4. package/SKILL-tiny.md +38 -38
  5. package/SKILL.md +356 -331
  6. package/assets/panel.html +6753 -5698
  7. package/cordis-plugin/lingshu-cron/plugin.js +1455 -1417
  8. package/cordis-plugin/lingshu-startup/context-fold.js +170 -0
  9. package/cordis-plugin/lingshu-startup/context-pressure.js +16 -0
  10. package/cordis-plugin/lingshu-startup/context-snapshot.js +176 -0
  11. package/cordis-plugin/lingshu-startup/plugin.js +499 -467
  12. 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
  13. 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
  14. package/docs/audit_notes//345/276/205/345/212/236/346/250/241/346/235/277.md +140 -0
  15. package/docs/commands.md +278 -247
  16. package/docs/mechanics.md +610 -610
  17. 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
  18. 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
  19. package/package.json +52 -52
  20. package/scripts/_scratch/_tmp_backup_race.py +70 -0
  21. package/scripts/_scratch/_tmp_cleanup_move.py +34 -0
  22. package/scripts/_scratch/_tmp_count_kinds.py +25 -0
  23. package/scripts/_scratch/_tmp_diag_paths.py +48 -0
  24. package/scripts/_scratch/_tmp_facts.py +63 -0
  25. package/scripts/_scratch/_tmp_find_copies.py +31 -0
  26. package/scripts/_scratch/_tmp_find_pin.py +29 -0
  27. package/scripts/_scratch/_tmp_fix_pin.py +36 -0
  28. package/scripts/_scratch/_tmp_fold_fixture.py +55 -0
  29. package/scripts/_scratch/_tmp_fold_test.mjs +81 -0
  30. package/scripts/_scratch/_tmp_inject_secs.py +30 -0
  31. package/scripts/_scratch/_tmp_kb_balance.py +159 -0
  32. package/scripts/_scratch/_tmp_lines.py +15 -0
  33. package/scripts/_scratch/_tmp_market_probe.py +13 -0
  34. package/scripts/_scratch/_tmp_move_partial.py +16 -0
  35. package/scripts/_scratch/_tmp_patch_b3.py +41 -0
  36. package/scripts/_scratch/_tmp_patch_b5.py +62 -0
  37. package/scripts/_scratch/_tmp_patch_crash_excl.py +24 -0
  38. package/scripts/_scratch/_tmp_patch_handoff.py +21 -0
  39. package/scripts/_scratch/_tmp_patch_ps1.py +25 -0
  40. package/scripts/_scratch/_tmp_patch_stat.py +27 -0
  41. package/scripts/_scratch/_tmp_patch_todo.py +25 -0
  42. package/scripts/_scratch/_tmp_patch_todo2.py +64 -0
  43. package/scripts/_scratch/_tmp_probe_session.py +51 -0
  44. package/scripts/_scratch/_tmp_style_probe.py +40 -0
  45. package/scripts/_scratch/_tmp_write_note.py +139 -0
  46. package/scripts/_scratch/_/346/235/245/346/272/220/350/256/260/345/275/225.txt +1 -0
  47. package/scripts/_scratch/asar_compaction/dsh-compaction-basic__lib__index.js +1044 -0
  48. package/scripts/_scratch/asar_compaction/dsh-compaction-tool-result-pruner__lib__index.js +194 -0
  49. package/scripts/_scratch/asar_compaction/dsh-compaction__lib__index.js +175 -0
  50. package/scripts/_scratch/asar_compaction/dsh-compaction__lib__types__tool-pairing.js +97 -0
  51. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__image-offload.js +47 -0
  52. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__index.js +40 -0
  53. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__project-message.js +37 -0
  54. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__brand.js +9 -0
  55. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__checkpoint.js +36 -0
  56. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__types.js +10 -0
  57. package/scripts/_scratch/commit_msg_occ.txt +16 -0
  58. package/scripts/_scratch/commit_msg_struct.txt +16 -0
  59. package/scripts/_scratch/v5.34_changelog.txt +36 -0
  60. package/scripts/_sync_trae_cn.py +102 -34
  61. package/scripts/_tmp_add_s10.py +54 -0
  62. package/scripts/_tmp_add_s11.py +61 -0
  63. package/scripts/_tmp_add_s12.py +66 -0
  64. package/scripts/_tmp_add_s13.py +69 -0
  65. package/scripts/_tmp_add_s14.py +80 -0
  66. package/scripts/_tmp_add_s9.py +68 -0
  67. package/scripts/_tmp_cache_load.py +82 -0
  68. package/scripts/_tmp_clean_market.py +40 -0
  69. package/scripts/_tmp_clean_pruned.py +81 -0
  70. package/scripts/_tmp_cleanup_docs.py +39 -0
  71. package/scripts/_tmp_cmp_ranker.py +17 -0
  72. package/scripts/_tmp_dolater_note.py +35 -0
  73. package/scripts/_tmp_dust_why.py +27 -0
  74. package/scripts/_tmp_explicit_import.py +40 -0
  75. package/scripts/_tmp_extract_compaction.py +35 -0
  76. package/scripts/_tmp_extract_compaction2.py +63 -0
  77. package/scripts/_tmp_extract_compaction3.py +51 -0
  78. package/scripts/_tmp_extract_compaction4.py +54 -0
  79. package/scripts/_tmp_finalize_s14.py +39 -0
  80. package/scripts/_tmp_find_compaction.py +43 -0
  81. package/scripts/_tmp_fix_b4.py +22 -0
  82. package/scripts/_tmp_fix_cli76.py +26 -0
  83. package/scripts/_tmp_fix_docs.py +38 -0
  84. package/scripts/_tmp_fix_docs_b.py +46 -0
  85. package/scripts/_tmp_fix_docs_b2.py +22 -0
  86. package/scripts/_tmp_fix_i3.py +23 -0
  87. package/scripts/_tmp_fix_s10.py +83 -0
  88. package/scripts/_tmp_fix_s11.py +14 -0
  89. package/scripts/_tmp_fix_s9_status.py +19 -0
  90. package/scripts/_tmp_fix_shadow_sim.py +37 -0
  91. package/scripts/_tmp_fix_traits_value.py +41 -0
  92. package/scripts/_tmp_import_idem.py +106 -0
  93. package/scripts/_tmp_log_ack.py +45 -0
  94. package/scripts/_tmp_mark_batch.py +28 -0
  95. package/scripts/_tmp_mark_batch2.py +32 -0
  96. package/scripts/_tmp_mark_dolater.py +26 -0
  97. package/scripts/_tmp_mark_dolater2.py +31 -0
  98. package/scripts/_tmp_move_self.py +16 -0
  99. package/scripts/_tmp_occ_cli.py +22 -0
  100. package/scripts/_tmp_occ_link.py +108 -0
  101. package/scripts/_tmp_optimize_recall.py +54 -0
  102. package/scripts/_tmp_panel_audit.py +26 -0
  103. package/scripts/_tmp_patch_batch3.py +65 -0
  104. package/scripts/_tmp_patch_rrf.py +46 -0
  105. package/scripts/_tmp_patch_s2s3.py +80 -0
  106. package/scripts/_tmp_patch_s4.py +39 -0
  107. package/scripts/_tmp_patch_s7.py +43 -0
  108. package/scripts/_tmp_patch_s8.py +91 -0
  109. package/scripts/_tmp_patch_skill.py +17 -0
  110. package/scripts/_tmp_release_guard.py +57 -0
  111. package/scripts/_tmp_rerank_breaker.py +62 -0
  112. package/scripts/_tmp_s16.py +41 -0
  113. package/scripts/_tmp_scan_asar.py +41 -0
  114. package/scripts/_tmp_scan_asar2.py +37 -0
  115. package/scripts/_tmp_struct_docs.py +49 -0
  116. package/scripts/_tmp_sum_fallback.py +42 -0
  117. package/scripts/_tmp_sweep.py +81 -0
  118. package/scripts/_tmp_sync_check.py +69 -0
  119. package/scripts/_tmp_sync_tail.py +39 -0
  120. package/scripts/_tmp_todo_clean.py +67 -0
  121. package/scripts/_tmp_verify_copy.py +17 -0
  122. package/scripts/_tmp_wire_extras.py +93 -0
  123. package/scripts/_tmp_wire_hsum.py +34 -0
  124. package/scripts/_tmp_wire_occ_b5.py +40 -0
  125. package/scripts/_tmp_wire_ranker.py +13 -0
  126. package/scripts/_tmp_wire_shadow_timeline.py +45 -0
  127. package/scripts/anchor_retention.py +68 -0
  128. package/scripts/app_context.py +1160 -0
  129. package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +38 -22
  130. package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +4281 -4227
  131. package/scripts/astrbot_plugin_lingshu/engine/README.md +1584 -1577
  132. package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +59 -59
  133. package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +38 -38
  134. package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +356 -331
  135. package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +6753 -5698
  136. package/scripts/astrbot_plugin_lingshu/engine/docs/commands.md +278 -247
  137. package/scripts/astrbot_plugin_lingshu/engine/docs/mechanics.md +610 -610
  138. package/scripts/astrbot_plugin_lingshu/engine/scripts/_sync_trae_cn.py +102 -34
  139. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s10.py +54 -0
  140. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s11.py +61 -0
  141. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s12.py +66 -0
  142. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s13.py +69 -0
  143. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s14.py +80 -0
  144. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s9.py +68 -0
  145. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cache_load.py +82 -0
  146. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_market.py +40 -0
  147. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_pruned.py +81 -0
  148. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cleanup_docs.py +39 -0
  149. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cmp_ranker.py +17 -0
  150. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dolater_note.py +35 -0
  151. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dust_why.py +27 -0
  152. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_explicit_import.py +40 -0
  153. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction.py +35 -0
  154. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction2.py +63 -0
  155. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction3.py +51 -0
  156. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction4.py +54 -0
  157. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_finalize_s14.py +39 -0
  158. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_find_compaction.py +43 -0
  159. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_b4.py +22 -0
  160. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_cli76.py +26 -0
  161. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs.py +38 -0
  162. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b.py +46 -0
  163. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b2.py +22 -0
  164. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_i3.py +23 -0
  165. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s10.py +83 -0
  166. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s11.py +14 -0
  167. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s9_status.py +19 -0
  168. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_shadow_sim.py +37 -0
  169. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_traits_value.py +41 -0
  170. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_import_idem.py +106 -0
  171. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_log_ack.py +45 -0
  172. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch.py +28 -0
  173. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch2.py +32 -0
  174. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater.py +26 -0
  175. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater2.py +31 -0
  176. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_move_self.py +16 -0
  177. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_cli.py +22 -0
  178. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_link.py +108 -0
  179. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_optimize_recall.py +54 -0
  180. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_panel_audit.py +26 -0
  181. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_batch3.py +65 -0
  182. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_rrf.py +46 -0
  183. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s2s3.py +80 -0
  184. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s4.py +39 -0
  185. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s7.py +43 -0
  186. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s8.py +91 -0
  187. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_skill.py +17 -0
  188. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_release_guard.py +57 -0
  189. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_rerank_breaker.py +62 -0
  190. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_s16.py +41 -0
  191. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar.py +41 -0
  192. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar2.py +37 -0
  193. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_struct_docs.py +49 -0
  194. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sum_fallback.py +42 -0
  195. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sweep.py +81 -0
  196. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_check.py +69 -0
  197. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_tail.py +39 -0
  198. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_todo_clean.py +67 -0
  199. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_verify_copy.py +17 -0
  200. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_extras.py +93 -0
  201. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_hsum.py +34 -0
  202. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_occ_b5.py +40 -0
  203. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_ranker.py +13 -0
  204. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_shadow_timeline.py +45 -0
  205. package/scripts/astrbot_plugin_lingshu/engine/scripts/anchor_retention.py +68 -0
  206. package/scripts/astrbot_plugin_lingshu/engine/scripts/app_context.py +1160 -0
  207. package/scripts/astrbot_plugin_lingshu/engine/scripts/bigfive.py +90 -0
  208. package/scripts/astrbot_plugin_lingshu/engine/scripts/brain.py +1 -1
  209. package/scripts/astrbot_plugin_lingshu/engine/scripts/check_docs.py +191 -0
  210. package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +921 -86
  211. package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +2468 -2406
  212. package/scripts/astrbot_plugin_lingshu/engine/scripts/coverage_report.py +5 -0
  213. package/scripts/astrbot_plugin_lingshu/engine/scripts/delivery.py +112 -0
  214. package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +41 -3
  215. package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +202 -23
  216. package/scripts/astrbot_plugin_lingshu/engine/scripts/gap_memory.py +186 -0
  217. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +72 -8
  218. package/scripts/astrbot_plugin_lingshu/engine/scripts/hsum.py +206 -0
  219. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_score.py +92 -7
  220. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +530 -60
  221. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory_extras.py +200 -0
  222. package/scripts/astrbot_plugin_lingshu/engine/scripts/occ.py +190 -0
  223. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +232 -142
  224. package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +2498 -2349
  225. package/scripts/astrbot_plugin_lingshu/engine/scripts/prepublish_tests.py +90 -0
  226. package/scripts/astrbot_plugin_lingshu/engine/scripts/release.py +326 -287
  227. package/scripts/astrbot_plugin_lingshu/engine/scripts/rss_ingest.py +181 -0
  228. package/scripts/astrbot_plugin_lingshu/engine/scripts/session_import.py +832 -764
  229. package/scripts/astrbot_plugin_lingshu/engine/scripts/shadow_memory.py +173 -0
  230. package/scripts/astrbot_plugin_lingshu/engine/scripts/style_check.py +220 -0
  231. package/scripts/astrbot_plugin_lingshu/engine/scripts/summarizer.py +343 -252
  232. package/scripts/astrbot_plugin_lingshu/engine/scripts/timeline.py +118 -0
  233. package/scripts/astrbot_plugin_lingshu/engine/scripts/watchdog.py +110 -0
  234. package/scripts/astrbot_plugin_lingshu/engine/scripts/web_research.py +125 -0
  235. package/scripts/bigfive.py +90 -0
  236. package/scripts/brain.py +1 -1
  237. package/scripts/check_docs.py +191 -0
  238. package/scripts/cli.py +921 -86
  239. package/scripts/core.py +2468 -2406
  240. package/scripts/coverage_report.py +5 -0
  241. package/scripts/delivery.py +112 -0
  242. package/scripts/dream.py +41 -3
  243. package/scripts/emotion.py +202 -23
  244. package/scripts/gap_memory.py +186 -0
  245. package/scripts/growth.py +72 -8
  246. package/scripts/hsum.py +206 -0
  247. package/scripts/mem_score.py +92 -7
  248. package/scripts/memory.py +530 -60
  249. package/scripts/memory_extras.py +200 -0
  250. package/scripts/occ.py +190 -0
  251. package/scripts/panel_server.py +232 -142
  252. package/scripts/persona.py +2498 -2349
  253. package/scripts/prepublish_tests.py +90 -0
  254. package/scripts/release.py +326 -287
  255. package/scripts/rss_ingest.py +181 -0
  256. package/scripts/run_tests.py +13 -0
  257. package/scripts/session_import.py +832 -764
  258. package/scripts/shadow_memory.py +173 -0
  259. package/scripts/style_check.py +220 -0
  260. package/scripts/summarizer.py +343 -252
  261. package/scripts/timeline.py +118 -0
  262. package/scripts/update_dsh_copy.ps1 +110 -107
  263. package/scripts/watchdog.py +110 -0
  264. package/scripts/web_research.py +125 -0
  265. package/docs//344/272/244/346/216/245/347/254/224/350/256/260-20261128.md +0 -128
  266. package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +0 -408
@@ -2347,12 +2347,13 @@ def _update_check_live(name: str = "lingshu", force_pull: bool = False) -> dict:
2347
2347
  }
2348
2348
  if dev_npm:
2349
2349
  # dev 模式下 npm 查询成功就必须设这两个字段——不管 npm 版本比本地新还是旧。
2350
- # 之前只在 npm 真更新(outdated=True)或 npm 查失败时才设,导致 npm 版本
2351
- # 落后于本地时(本地正在开发新版本、npm 还没同步)dev_repo 和 npm 字段
2352
- # 都丢失,前端和测试都懵。
2353
2350
  out["dev_repo"] = True
2354
2351
  out["npm"] = dev_npm
2355
- if out.get("outdated"):
2352
+ _nm_v = _ver_tuple(dev_npm.get("version"))
2353
+ # 只有当 npm 上的版本严格大于本地仓库版本(_nm_v > src_v)时,才算作来自 npm 的更新!
2354
+ # 若本地仓库版本比 npm 还新(如本地 5.36,npm 5.33.0),更新源是本地仓库(dev),
2355
+ # 绝不能把 source_version 降级覆盖成 npm 上的旧版,否则会导致「v5.35 → v5.33.0」倒退更新假报警!
2356
+ if out.get("outdated") and _nm_v is not None and src_v is not None and _nm_v > src_v:
2356
2357
  # 仓库 vX → npm vY:明确"能装的版本在 npm 上",别让人以为仓库自己会变
2357
2358
  out["source"] = "npm"
2358
2359
  out["installed_version"] = out["installed_version"] or out["version"]
@@ -3696,20 +3697,36 @@ def _tag_coverage() -> float:
3696
3697
 
3697
3698
  def health_score(passed: int = 0, warned: int = 0, failed: int = 0,
3698
3699
  failures_7d: int | None = None) -> dict:
3699
- """健康度分数(0~100)+ 扣分明细。参数没给就取最近一次体检历史。"""
3700
+ """健康度分数(0~100)+ 扣分明细与新鲜度(FEAT-03)。"""
3700
3701
  if failures_7d is None:
3701
3702
  failures_7d = _recent_failures(7)
3703
+ last_ts = None
3704
+ last_date = ""
3705
+ has_run = False
3702
3706
  if not (passed or warned or failed):
3703
3707
  hist = [r for r in doctor_history() if str(r.get("kind") or "doctor") == "doctor"]
3704
3708
  if hist:
3705
3709
  last = hist[-1]
3710
+ has_run = True
3706
3711
  passed = int(last.get("pass") or 0)
3707
3712
  warned = int(last.get("warn") or 0)
3708
3713
  failed = int(last.get("fail") or 0)
3714
+ last_ts = float(last.get("ts") or 0) if last.get("ts") else None
3715
+ last_date = str(last.get("date") or "")
3716
+ if not has_run and not (passed or warned or failed):
3717
+ # 从未体检过:不假装成 100 分健康
3718
+ return {
3719
+ "score": None, "never_checked": True, "pass": 0, "warn": 0, "fail": 0,
3720
+ "failures_7d": int(failures_7d), "stale": True, "last_date": "", "last_ts": None,
3721
+ "deduct": {"fail": 0, "warn": 0, "failures": int(failures_7d) // 5}
3722
+ }
3709
3723
  score = 100 - int(failed) * 10 - int(warned) * 3 - int(failures_7d) // 5
3710
3724
  score = max(0, min(100, score))
3711
- return {"score": score, "pass": int(passed), "warn": int(warned),
3712
- "fail": int(failed), "failures_7d": int(failures_7d),
3725
+ # 体检数据超过 2 天未更新视为 stale 过期
3726
+ stale = (brain.now_ts() - last_ts > 2 * brain.DAY) if last_ts else False
3727
+ return {"score": score, "never_checked": False, "pass": int(passed), "warn": int(warned),
3728
+ "fail": int(failed), "failures_7d": int(failures_7d), "stale": stale,
3729
+ "last_date": last_date, "last_ts": last_ts,
3713
3730
  "deduct": {"fail": int(failed) * 10, "warn": int(warned) * 3,
3714
3731
  "failures": int(failures_7d) // 5}}
3715
3732
 
@@ -3781,10 +3798,38 @@ def stage_state() -> dict:
3781
3798
  _health = health_score(failures_7d=fails)
3782
3799
  except Exception: # noqa: BLE001
3783
3800
  _health = None
3801
+
3802
+ # IDEA-01: 成就系统 (Milestones) 自动计算
3803
+ achievements = _calculate_milestones(doc_runs, self_reviews, fails, cov)
3804
+
3784
3805
  return {"stage": stage, "doctor_runs": doc_runs, "self_reviews": self_reviews,
3785
3806
  "failures_7d": fails, "coverage": round(cov, 3),
3786
3807
  "drift_fixed": drift_fixed, "next": need, "label": label,
3787
- "health": _health}
3808
+ "health": _health, "achievements": achievements}
3809
+
3810
+
3811
+ def _calculate_milestones(doc_runs: int, self_reviews: int, fails: int, cov: float) -> list:
3812
+ """计算系统心智成长里程碑奖章。"""
3813
+ try:
3814
+ import memory as _m
3815
+ mem_cnt = len(_m.load_all())
3816
+ except Exception:
3817
+ mem_cnt = 0
3818
+ try:
3819
+ skills_cnt = len(scan_skills())
3820
+ except Exception:
3821
+ skills_cnt = 0
3822
+
3823
+ defs = [
3824
+ {"id": "first_words", "name": "初识啼鸣", "icon": "🌱", "desc": "初建记忆档案并开启相伴旅程", "unlocked": mem_cnt >= 1},
3825
+ {"id": "hundred_mems", "name": "百记聚沙", "icon": "📚", "desc": "记忆库积累超过 100 条生活与事实印记", "unlocked": mem_cnt >= 100},
3826
+ {"id": "five_hundred_mems", "name": "千丝成网", "icon": "🕸️", "desc": "记忆库超过 500 条,关联形成繁密思维网", "unlocked": mem_cnt >= 500},
3827
+ {"id": "doctor_master", "name": "千锤百炼", "icon": "🛡️", "desc": "执行健康体检与自查超过 30 次", "unlocked": doc_runs >= 30},
3828
+ {"id": "deep_reflection", "name": "深省明心", "icon": "🪞", "desc": "完成自我复盘与自省总结超过 3 次", "unlocked": self_reviews >= 3},
3829
+ {"id": "tool_collector", "name": "万象纳身", "icon": "⚙️", "desc": "发现并挂载跨宿主工具能力超过 10 项", "unlocked": skills_cnt >= 10},
3830
+ {"id": "high_order", "name": "秩序井然", "icon": "✨", "desc": "记忆结构化标签覆盖率达到 40% 以上", "unlocked": cov >= 0.40},
3831
+ ]
3832
+ return defs
3788
3833
 
3789
3834
 
3790
3835
  def release_drift() -> dict:
@@ -4103,6 +4148,7 @@ def scan_skills(root_filter: str | None = None) -> list:
4103
4148
  """扫描所有技能根目录,列出发现的技能(跨宿主可用)。"""
4104
4149
  want = (root_filter or "").strip()
4105
4150
  out, seen = [], set()
4151
+ reg = load_registry()
4106
4152
  for label, root in _skill_roots():
4107
4153
  if want and str(root) != want and label != want:
4108
4154
  continue
@@ -4118,6 +4164,9 @@ def scan_skills(root_filter: str | None = None) -> list:
4118
4164
  meta, body = parse_frontmatter(p.read_text(encoding="utf-8-sig"))
4119
4165
  except (OSError, UnicodeDecodeError):
4120
4166
  meta, body = {}, ""
4167
+ # 注册表键是 _require_slug 归一化后的(set_skill_enabled 写入口径),
4168
+ # 目录名含大写/下划线时按原文查会静默 miss(审计 P2:键名口径不一)。
4169
+ enabled = reg.get(_require_slug(name), {}).get("enabled", True)
4121
4170
  out.append({
4122
4171
  "name": meta.get("name") or name,
4123
4172
  "dir": name,
@@ -4127,10 +4176,22 @@ def scan_skills(root_filter: str | None = None) -> list:
4127
4176
  "version": str(meta.get("version") or ""),
4128
4177
  "path": str(p),
4129
4178
  "self": (name or "").lower() in _SELF_NAMES,
4179
+ "enabled": enabled,
4130
4180
  })
4131
4181
  return out
4132
4182
 
4133
4183
 
4184
+ def set_skill_enabled(name: str, enabled: bool) -> dict:
4185
+ """开启或关闭一个技能(影响其是否被注入 context)。"""
4186
+ name = _require_slug(name)
4187
+ with brain._locked(SKILL_REG):
4188
+ reg = load_registry()
4189
+ old = reg.get(name) or {}
4190
+ # 注意:使用 update 模式以保留其他元数据
4191
+ reg[name] = {**old, "enabled": bool(enabled), "updated": brain.now_ts()}
4192
+ save_registry(reg)
4193
+ return {"name": name, "enabled": bool(enabled)}
4194
+
4134
4195
  def search_skills(query: str, limit: int = 12) -> list:
4135
4196
  """在「我自己写的技能」和「全局技能目录」里找能用的工具。"""
4136
4197
  q = (query or "").strip().lower()
@@ -4753,6 +4814,7 @@ def _run(argv=None) -> int:
4753
4814
  a = ss.add_parser("scan", help="扫描所有技能根目录,列出跨宿主可用的技能")
4754
4815
  a.add_argument("--root", default=None, help="只看某个目录/标签")
4755
4816
  a.add_argument("--json", action="store_true")
4817
+ a.add_argument("--enabled-only", action="store_true", help="只列出当前已启用且会注入上下文的技能(OPS-04)")
4756
4818
 
4757
4819
  # ---- 扩展模块(AI 自己写的可执行钩子,数据目录,更新永不覆盖)
4758
4820
  p = sub.add_parser("ext", help="扩展模块:自己写的可执行钩子(inject / run),更新技能永不覆盖")
@@ -5217,6 +5279,8 @@ def _run(argv=None) -> int:
5217
5279
  return 0
5218
5280
  if args.act == "scan":
5219
5281
  rows = scan_skills(getattr(args, "root", None))
5282
+ if getattr(args, "enabled_only", False):
5283
+ rows = [r for r in rows if r.get("enabled", True)]
5220
5284
  if args.json:
5221
5285
  print(json.dumps(rows, ensure_ascii=False, indent=2))
5222
5286
  elif not rows:
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """增量分层摘要(do-later「L」,§2)。
4
+
5
+ 问题:做梦每次重放最近 N 条 → 全部重压 → 同一段历史被反复抽象,**漂移逐轮累积**
6
+ (第三版摘要可能已经不是第一版在说的事)。
7
+
8
+ 做法:分层账本 + **按覆盖范围幂等**。
9
+ summaries/L1.jsonl 每轮对话一条摘要(covers = 该轮的消息 id)
10
+ summaries/L2.jsonl 每 10 条 L1 合成一条(covers = 10 条 L1 的 id)
11
+ summaries/L3.jsonl 每 10 条 L2 合成一条
12
+ 同一 covers 集合只生成一次;再跑就跳过,不重压、不漂移。
13
+
14
+ 护栏(宁可旧不可烂):新摘要先过 `anchor_retention.compare(源文本, 摘要)`,
15
+ 保留率 < 0.5 就**拒绝写入**、保留旧摘要,并在结果里记 rejected。
16
+
17
+ 用法:
18
+ brain.py hsum build --level 1 --max-units 8 [--dry-run]
19
+ brain.py hsum show --level 1
20
+ """
21
+ from __future__ import annotations
22
+
23
+ import hashlib
24
+ import json
25
+ from pathlib import Path
26
+
27
+ import app_context
28
+ import brain
29
+ import core
30
+ from core import now_ts
31
+
32
+ LEVELS = (1, 2, 3)
33
+ GROUP = 10 # 上一层每 10 条合成一条
34
+ RETAIN_FLOOR = 0.5 # 保留率下限(低于它不覆盖)
35
+ MAX_CHARS = 400
36
+
37
+
38
+ def _dir() -> Path:
39
+ d = Path(core.HOME) / "summaries"
40
+ d.mkdir(parents=True, exist_ok=True)
41
+ return d
42
+
43
+
44
+ def _path(level: int) -> Path:
45
+ return _dir() / f"L{int(level)}.jsonl"
46
+
47
+
48
+ def load_rows(level: int) -> list:
49
+ p = _path(level)
50
+ out = []
51
+ try:
52
+ if not p.is_file():
53
+ return out
54
+ for line in p.read_text(encoding="utf-8", errors="replace").splitlines():
55
+ line = line.strip()
56
+ if not line:
57
+ continue
58
+ try:
59
+ row = json.loads(line)
60
+ except json.JSONDecodeError:
61
+ continue
62
+ if isinstance(row, dict) and row.get("covers"):
63
+ out.append(row)
64
+ except OSError:
65
+ pass
66
+ return out
67
+
68
+
69
+ def covers_key(covers) -> str:
70
+ basis = "|".join(sorted(str(c) for c in covers))
71
+ return hashlib.sha1(basis.encode("utf-8", "replace")).hexdigest()[:16]
72
+
73
+
74
+ def summarize_text(text: str, max_chars: int = MAX_CHARS) -> str:
75
+ """只用离线抽取式(不联网、不烧 token);失败就截前 N 字。"""
76
+ t = " ".join(str(text or "").split())
77
+ if not t:
78
+ return ""
79
+ try:
80
+ import summarizer
81
+ return summarizer.extractive_fallback(
82
+ [{"role": "user", "text": t}], max_chars=max_chars) or t[:max_chars]
83
+ except Exception:
84
+ return t[:max_chars]
85
+
86
+
87
+ def _units_from_session() -> list:
88
+ """L1 的原料:会话里已结束的每一轮。"""
89
+ path = app_context.find_session()
90
+ if not path:
91
+ return []
92
+ try:
93
+ events = app_context.read_events(path)
94
+ msgs = app_context.reconstruct_messages(events)
95
+ except Exception:
96
+ return []
97
+ groups: dict = {}
98
+ for m in msgs:
99
+ t = m.get("turn")
100
+ if not isinstance(t, int):
101
+ continue
102
+ groups.setdefault(t, []).append(m)
103
+ out = []
104
+ for turn in sorted(groups):
105
+ g = groups[turn]
106
+ text = " ".join(str(x.get("preview") or "") for x in g if x.get("preview"))
107
+ if not text.strip():
108
+ continue
109
+ out.append({"covers": [f"turn{turn}"],
110
+ "text": text[:6000],
111
+ "chars": sum(int(x.get("chars") or 0) for x in g)})
112
+ return out
113
+
114
+
115
+ def _units_from_level(level: int) -> list:
116
+ """L2/L3 的原料:上一层摘要按 GROUP 分组。"""
117
+ rows = load_rows(level - 1)
118
+ out = []
119
+ for i in range(0, len(rows), GROUP):
120
+ chunk = rows[i:i + GROUP]
121
+ if len(chunk) < GROUP:
122
+ break # 不足一组先不压,等下一批补齐(避免半组摘要)
123
+ out.append({"covers": [r.get("id") for r in chunk],
124
+ "text": " ".join(str(r.get("text") or "") for r in chunk)[:6000],
125
+ "chars": sum(int(r.get("chars") or 0) for r in chunk)})
126
+ return out
127
+
128
+
129
+ def build(level: int = 1, max_units: int = 8, dry_run: bool = False) -> dict:
130
+ level = int(level)
131
+ if level not in LEVELS:
132
+ return {"ok": False, "reason": f"level 只能是 {LEVELS}"}
133
+ units = _units_from_session() if level == 1 else _units_from_level(level)
134
+ existing = {covers_key(r["covers"]) for r in load_rows(level)}
135
+ created, skipped, rejected = [], 0, []
136
+ new_rows = []
137
+ for u in units:
138
+ if len(created) >= max(1, int(max_units)):
139
+ break
140
+ key = covers_key(u["covers"])
141
+ if key in existing:
142
+ skipped += 1
143
+ continue
144
+ summary = summarize_text(u["text"])
145
+ if not summary:
146
+ continue
147
+ # 保留率闸门:宁可旧不可烂
148
+ try:
149
+ import anchor_retention
150
+ # 注意:不能用 ... or 1.0——保留率 0.0 是"全丢",会被 or 当成假值放行。
151
+ # (同 rerank 的 fail_cooldown_sec=0 被吞,是同一类 bug,本项目已踩两次。)
152
+ _cmp = anchor_retention.compare(u["text"], summary)
153
+ _r = _cmp.get("rate")
154
+ rate = float(_r) if _r is not None else 1.0
155
+ except Exception:
156
+ rate = 1.0
157
+ if rate < RETAIN_FLOOR:
158
+ rejected.append({"covers": u["covers"], "rate": round(rate, 3)})
159
+ continue
160
+ row = {"id": f"L{level}_{key}", "level": level, "covers": u["covers"],
161
+ "text": summary[:MAX_CHARS * 2], "chars": int(u.get("chars") or 0),
162
+ "retention": round(rate, 3), "ts": now_ts()}
163
+ created.append(row)
164
+ existing.add(key)
165
+ new_rows.append(row)
166
+ if new_rows and not dry_run:
167
+ p = _path(level)
168
+ with core._locked(p):
169
+ with open(p, "a", encoding="utf-8") as fh:
170
+ for r in new_rows:
171
+ fh.write(json.dumps(r, ensure_ascii=False) + "\n")
172
+ return {"ok": True, "level": level, "units": len(units), "created": len(created),
173
+ "skipped_same_covers": skipped, "rejected": rejected,
174
+ "dry_run": dry_run, "rows": created}
175
+
176
+
177
+ def render(r: dict) -> list:
178
+ if not r.get("ok"):
179
+ return [f"失败:{r.get('reason')}"]
180
+ lines = [f"L{r['level']}:原料 {r['units']} 组,新建 {r['created']} 条,"
181
+ f"覆盖范围已存在跳过 {r['skipped_same_covers']} 组"
182
+ + ("(干跑)" if r["dry_run"] else "")]
183
+ for x in r.get("rows") or []:
184
+ lines.append(f" {x['id']} covers={','.join(x['covers'][:3])}"
185
+ f"{'…' if len(x['covers']) > 3 else ''} 保留率 {x['retention']}")
186
+ for x in r.get("rejected") or []:
187
+ lines.append(f" ⚠ 拒绝(保留率 {x['rate']} < {RETAIN_FLOOR}):{x['covers'][:2]}")
188
+ return lines
189
+
190
+
191
+ def run(args) -> int:
192
+ action = getattr(args, "hsum_action", None) or "build"
193
+ level = int(getattr(args, "level", 1) or 1)
194
+ if action == "show":
195
+ rows = load_rows(level)
196
+ if not rows:
197
+ print(f"L{level} 还没有摘要。")
198
+ return 0
199
+ for r in rows[-20:]:
200
+ print(f"{r.get('id')} {r.get('ts')} {str(r.get('text') or '')[:80]}")
201
+ return 0
202
+ r = build(level=level, max_units=int(getattr(args, "max_units", 8) or 8),
203
+ dry_run=bool(getattr(args, "dry_run", False)))
204
+ for line in render(r):
205
+ print(line)
206
+ return 0 if r.get("ok") else 1
@@ -29,17 +29,98 @@ _WORD = re.compile(r"[a-z0-9]+")
29
29
  _PUNCT = re.compile(r"[^\w\u4e00-\u9fff]+")
30
30
 
31
31
 
32
- def terms(text: str) -> set:
32
+ class TermSet(set):
33
+ """词集,但**带着词频与长度**。
34
+
35
+ 为什么做成 set 子类:`terms()` 的返回值被大量代码当集合用(`&`、`|`、`jaccard`、
36
+ 去重、`len()`),直接改成 dict 会击穿一大片。这里保持 set 语义,额外挂 `counts`
37
+ 与 `length`,`relevance()` 有词频时就能走 BM25,没有时退回原来的集合余弦。
38
+ """
39
+
40
+ def __init__(self, items=(), counts=None, length=0):
41
+ super().__init__(items)
42
+ self.counts = dict(counts or {})
43
+ self.length = int(length or len(self))
44
+
45
+
46
+ def terms(text: str) -> "TermSet":
33
47
  """中文用字符二元组,英文/数字用词。构成模糊匹配的最小单元。"""
34
48
  t = (text or "").lower()
35
- out = set()
49
+ counts: dict = {}
50
+
51
+ def _hit(term: str) -> None:
52
+ counts[term] = counts.get(term, 0) + 1
53
+
36
54
  for seg in _CJK.findall(t):
37
55
  if len(seg) == 1:
38
- out.add(seg)
56
+ _hit(seg)
39
57
  for i in range(len(seg) - 1):
40
- out.add(seg[i:i + 2])
41
- out.update(_WORD.findall(t))
42
- return out
58
+ _hit(seg[i:i + 2])
59
+ for w in _WORD.findall(t):
60
+ _hit(w)
61
+ return TermSet(counts.keys(), counts, sum(counts.values()))
62
+
63
+
64
+ def bm25(q_counts: dict, d_counts: dict, idf: dict, avgdl: float | None = None,
65
+ k1: float = 1.2, b: float = 0.75) -> float:
66
+ """BM25(k1=1.2, b=0.75),归一化到 0~1。
67
+
68
+ 为什么换掉集合余弦:relevance 占五元权重 **0.55**,而余弦看不见词频与长度——
69
+ 同一条记忆提"部署"1 次和 5 次同分;长文本天然产生更多二元组,分子被"偶然重合"
70
+ 抬高,于是长而啰嗦的记忆挤掉短而精准的。
71
+ """
72
+ if not q_counts or not d_counts:
73
+ return 0.0
74
+ dl = sum(d_counts.values()) or 1
75
+ avg = float(avgdl or dl)
76
+ score = 0.0
77
+ for term in q_counts:
78
+ f = d_counts.get(term)
79
+ if not f:
80
+ continue
81
+ idf_t = idf.get(term, 0.5)
82
+ denom = f + k1 * (1.0 - b + b * dl / avg)
83
+ if denom > 0:
84
+ score += idf_t * (f * (k1 + 1.0)) / denom
85
+ # 归一:分母取"每个查询词都以最大贡献命中"的上限,保证落在 0~1
86
+ cap = (k1 + 1.0) * sum(idf.get(t, 0.5) for t in q_counts) or 1.0
87
+ return max(0.0, min(1.0, score / cap))
88
+
89
+
90
+ def actr_base_level(m: dict, now: int, d: float = 0.5) -> float:
91
+ """ACT-R 基础激活(§2 do-later:让频次真正参与决策)。
92
+
93
+ 问题:`access_count` 只被用来展示/防抖,**不参与任何打分**——于是"上周想过 5 次的"
94
+ 输给"昨天想过 1 次的"。
95
+
96
+ ACT-R:`B = ln(Σ t_j^-d)`,t_j 是第 j 次访问距今的天数。库里只存了 access_count /
97
+ last_access / created,所以假设 n 次访问在 [created, last_access] 上近似均匀。
98
+ 返回 0~1(sigmoid 压平,便于当加成项用)。
99
+
100
+ 回归/防漂移:n 越大、最近一次越近 → 越大;从没访问过 → 0。
101
+ """
102
+ try:
103
+ n = int(_num(m.get("access_count"), 0))
104
+ except Exception:
105
+ return 0.0
106
+ if n <= 0:
107
+ return 0.0
108
+ day = 86400.0
109
+ last = _num(m.get("last_access"), _num(m.get("created"), now))
110
+ first = _num(m.get("created"), last)
111
+ span = max(1.0, last - first)
112
+ step = span / (n - 1) if n > 1 else 0.0
113
+ total = 0.0
114
+ for j in range(n):
115
+ t_days = max(1e-3, (now - (last - j * step)) / day)
116
+ total += t_days ** (-d)
117
+ if total <= 0:
118
+ return 0.0
119
+ b = math.log(total)
120
+ try:
121
+ return 1.0 / (1.0 + math.exp(-b))
122
+ except OverflowError:
123
+ return 1.0 if b > 0 else 0.0
43
124
 
44
125
 
45
126
  def jaccard(a: set, b: set) -> float:
@@ -57,7 +138,11 @@ def build_idf(docs: list) -> dict:
57
138
  return {t: math.log((n + 1) / (c + 0.5)) + 0.5 for t, c in df.items()}
58
139
 
59
140
 
60
- def relevance(q_terms: set, d_terms: set, idf: dict) -> float:
141
+ def relevance(q_terms, d_terms, idf: dict, avgdl: float | None = None) -> float:
142
+ """相关性。有词频(TermSet)走 BM25;否则退回原来的 idf 集合余弦。"""
143
+ if isinstance(q_terms, TermSet) and isinstance(d_terms, TermSet) \
144
+ and q_terms.counts and d_terms.counts:
145
+ return bm25(q_terms.counts, d_terms.counts, idf, avgdl)
61
146
  shared = q_terms & d_terms
62
147
  if not shared:
63
148
  return 0.0