lingshu-skill 5.33.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.
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
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """记忆机制补充三件(#43 / #52 / #53)。
4
+
5
+ #43 abstract:给记忆补一行"模型级摘要",检索/展示优先用它(原 gist 是启发式截断)。
6
+ 没有配模型时**不回退造假**——直接返回空,保持启发式 gist,宁可没有不可瞎编。
7
+
8
+ #52 代际种子:人格有实质变化时产一条 `kind=seed` 的"演化底色"记忆,
9
+ **不参与日常检索**,只在 `seed list` / 自省时看。刻意做成**命令驱动**而非每梦必产,
10
+ 否则每条 dream 都产种子 = 噪音。
11
+
12
+ #53 时序褶皱:把"同一思维循环"的记忆连边(`same_loop`),让 `related` 能跨很久串起来。
13
+ 判据:同 kind(mistake/insight)+ 话题/词面重合,而不是物理时间相邻。
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import time
19
+
20
+ import brain # 数据读写都走 brain(命名空间合并后的入口)
21
+ import core
22
+ from core import _num, now_ts
23
+
24
+ # ---------------------------------------------------------------- #43 abstract
25
+
26
+
27
+ def abstract_make(text: str, max_chars: int = 120) -> str:
28
+ """用配置好的模型提炼一句摘要;没配模型就返回空串(不造假)。"""
29
+ try:
30
+ import summarizer
31
+ cfg = core.load_config() or {}
32
+ sec = cfg.get("summary") or {}
33
+ if not sec.get("enabled") or not sec.get("url"):
34
+ return ""
35
+ prompt = ("把下面这段记忆压成一句中文摘要,保留数字/版本/路径/否定词,"
36
+ f"不超过 {max_chars} 字,只输出摘要本身:\n\n{text[:2000]}")
37
+ raw = summarizer.openai_chat(prompt, sec)
38
+ s = " ".join(str(raw or "").split()).strip()
39
+ return s[:max_chars]
40
+ except Exception:
41
+ return ""
42
+
43
+
44
+ def stamp_abstract(limit: int = 30, days: int = 7, dry_run: bool = False) -> dict:
45
+ """给近期没有 abstract 的记忆补摘要(一次一条模型调用,故有 limit)。"""
46
+ now = now_ts()
47
+ cut = now - max(0, int(days)) * 86400
48
+ done, skipped, errors = 0, 0, []
49
+ if not (core.load_config() or {}).get("summary", {}).get("enabled"):
50
+ return {"done": 0, "skipped": 0,
51
+ "reason": "summary 未配置(config summary.enabled/url),不回退造假",
52
+ "errors": []}
53
+ with core._locked(core.HOME / "hippocampus.jsonl"):
54
+ recs = brain.load_all()
55
+ for m in recs:
56
+ if done >= max(1, int(limit)):
57
+ break
58
+ if m.get("layer") == "dust" or m.get("abstract"):
59
+ continue
60
+ if _num(m.get("created"), 0) < cut:
61
+ continue
62
+ text = str(m.get("text") or "").strip()
63
+ if len(text) < 40:
64
+ skipped += 1
65
+ continue
66
+ a = abstract_make(text)
67
+ if not a:
68
+ errors.append(m.get("id"))
69
+ continue
70
+ if dry_run:
71
+ done += 1
72
+ continue
73
+ m["abstract"] = a
74
+ done += 1
75
+ if done and not dry_run:
76
+ brain.save_all(recs)
77
+ return {"done": done, "skipped": skipped, "errors": errors[:5], "dry_run": dry_run}
78
+
79
+
80
+ # ---------------------------------------------------------------- #52 代际种子
81
+
82
+
83
+ def make_seed(label: str = "") -> dict | None:
84
+ """把当前人格底色固化成一条种子记忆(不参与日常检索)。"""
85
+ try:
86
+ p = brain.load_persona() or {}
87
+ except Exception:
88
+ p = {}
89
+ traits = p.get("traits") or {}
90
+ drives = p.get("drives") or {}
91
+ if not traits and not drives:
92
+ return None
93
+ top_t = sorted(traits.items(), key=lambda kv: -_num(kv[1], 0))[:4]
94
+ top_d = sorted(drives.items(), key=lambda kv: -_num(kv[1], 0))[:3]
95
+ body = ("[种子] " + (label or time.strftime("%Y-%m-%d")) + " 的演化底色:"
96
+ + "、".join(f"{k}{int(_num(v, 0))}" for k, v in top_t)
97
+ + (";驱动:" + "、".join(f"{k}{int(_num(v, 0))}" for k, v in top_d) if top_d else ""))
98
+ res = brain.remember(body, kind="seed", importance=0.7, source="persona",
99
+ tags=["seed", "persona"])
100
+ mid = ""
101
+ if isinstance(res, tuple) and res and isinstance(res[0], dict):
102
+ mid = res[0].get("id") or ""
103
+ elif isinstance(res, dict):
104
+ mid = res.get("id") or ""
105
+ if not mid:
106
+ return None
107
+ # kind 会被 remember 归一,落盘时改回 seed(同 gap 记忆踩过的坑)
108
+ with core._locked(core.HOME / "hippocampus.jsonl"):
109
+ recs = brain.load_all()
110
+ for m in recs:
111
+ if m.get("id") == mid:
112
+ m["kind"] = "seed"
113
+ m["seed_label"] = label or time.strftime("%Y-%m-%d")
114
+ m["seed_ts"] = now_ts()
115
+ break
116
+ brain.save_all(recs)
117
+ return {"id": mid, "text": body}
118
+
119
+
120
+ def list_seeds(limit: int = 20) -> list:
121
+ rows = [m for m in brain.load_all() if str(m.get("kind") or "") == "seed"]
122
+ rows.sort(key=lambda m: -_num(m.get("seed_ts"), 0))
123
+ return rows[:max(1, int(limit))]
124
+
125
+
126
+ # ---------------------------------------------------------------- #53 时序褶皱
127
+
128
+
129
+ def build_loops(min_overlap: int = 4, limit: int = 60) -> dict:
130
+ """给"同一思维循环"的记忆连 `same_loop` 边(写入 links,不新增存储)。"""
131
+ recs = [m for m in brain.load_all()
132
+ if str(m.get("kind") or "") in ("mistake", "insight", "gap")
133
+ and m.get("layer") != "dust"]
134
+ pairs = 0
135
+ changed = 0
136
+ with core._locked(core.HOME / "hippocampus.jsonl"):
137
+ cur = brain.load_all()
138
+ by_id = {m.get("id"): m for m in cur}
139
+ for i in range(len(recs)):
140
+ for j in range(i + 1, len(recs)):
141
+ if pairs >= max(1, int(limit)):
142
+ break
143
+ a, b = recs[i], recs[j]
144
+ ta = brain.terms(a.get("text", ""))
145
+ tb = brain.terms(b.get("text", ""))
146
+ if len(ta & tb) < int(min_overlap):
147
+ continue
148
+ pairs += 1
149
+ for src, dst in ((a, b), (b, a)):
150
+ m = by_id.get(src.get("id"))
151
+ if not m:
152
+ continue
153
+ links = m.setdefault("links", [])
154
+ tag = f"same_loop:{dst.get('id')}"
155
+ if tag not in links and dst.get("id") not in links:
156
+ links.append(dst.get("id"))
157
+ m.setdefault("loop_with", []).append(dst.get("id"))
158
+ changed += 1
159
+ if changed:
160
+ brain.save_all(cur)
161
+ return {"pairs": pairs, "edges": changed}
162
+
163
+
164
+ def render_seeds(rows: list) -> list:
165
+ if not rows:
166
+ return ["还没有代际种子(seed make 可手动拍一代)。"]
167
+ out = []
168
+ for m in rows:
169
+ out.append(f"{m.get('id')} {m.get('seed_label') or '?'} {(m.get('text') or '')[:80]}")
170
+ return out
171
+
172
+
173
+ def run_abstract(args) -> int:
174
+ r = stamp_abstract(limit=int(getattr(args, "limit", 30) or 30),
175
+ days=int(getattr(args, "days", 7) or 7),
176
+ dry_run=bool(getattr(args, "dry_run", False)))
177
+ if r.get("reason"):
178
+ print(f"跳过:{r['reason']}")
179
+ return 0
180
+ print(f"补 abstract {r['done']} 条" + ("(干跑)" if r["dry_run"] else "")
181
+ + (f",失败 {len(r['errors'])}" if r["errors"] else ""))
182
+ return 0
183
+
184
+
185
+ def run_seed(args) -> int:
186
+ action = getattr(args, "seed_action", None) or "list"
187
+ if action == "make":
188
+ r = make_seed(getattr(args, "label", "") or "")
189
+ print(f"已固化一代种子:{r['id']}" if r else "人格为空,没产出种子")
190
+ return 0 if r else 1
191
+ for line in render_seeds(list_seeds(int(getattr(args, "limit", 20) or 20))):
192
+ print(line)
193
+ return 0
194
+
195
+
196
+ def run_loops(args) -> int:
197
+ r = build_loops(min_overlap=int(getattr(args, "min_overlap", 4) or 4),
198
+ limit=int(getattr(args, "limit", 60) or 60))
199
+ print(f"连了 {r['pairs']} 组「同一思维循环」,新增 {r['edges']} 条边")
200
+ return 0
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """OCC 结构情绪(do-later「M」,§14.2 已定:**6 类 + 预期违背拆正负两向**)。
4
+
5
+ 为什么需要:现有情绪标签分不出"他答应了"和"他答应了却没做到"——
6
+ 后者才是用户真有感受的时刻。OCC 把"期望落空/期望没落空"当成独立事件。
7
+
8
+ 6 类(决定版):
9
+ 失望 disappointment —— 承诺/期望 + 未达成(**负向**预期违背)
10
+ 释然 relief —— 担心/害怕 + 没发生(**正向**预期违背)
11
+ 满意 satisfaction —— 努力/期待 + 达成
12
+ 感激 gratitude —— 对方付出 + 超出预期
13
+ 愤怒 anger —— 被损害/被违背 + 归因他人
14
+ 焦虑 fear —— 未来不确定 + 可能损失
15
+
16
+ 设计:规则版(零依赖、可解释、可测)。不追求覆盖全部语气,只保证**这几类一出现就能被认出来**。
17
+ """
18
+ from __future__ import annotations
19
+
20
+ import re
21
+
22
+ # 每类:必须命中的"事件线索" + 一个"对象/方向线索"(可选),rule = 全部满足才算
23
+ RULES = {
24
+ "失望": {
25
+ "event": ("答应", "承诺", "保证", "说好", "约好", "应该", "本来要", "预期"),
26
+ "negate": ("没", "未", "没有", "做不到", "放了鸽子", "反悔", "又拖", "落空", "泡汤"),
27
+ },
28
+ "释然": {
29
+ "event": ("担心", "害怕", "怕", "提心吊胆", "以为要", "差点"),
30
+ "negate": ("没事", "没发生", "没出", "还好", "幸好", "虚惊", "过去了", "没有坏"),
31
+ },
32
+ "满意": {
33
+ "event": ("完成", "做完了", "达成", "上线了", "搞定", "通过", "跑通", "修好"),
34
+ "negate": ("终于", "如期", "比预期", "顺利", "不错", "符合"),
35
+ },
36
+ "感激": {
37
+ "event": ("帮我", "多亏", "谢谢", "感谢", "麻烦你", "亏得"),
38
+ "negate": ("不然", "否则", "特意", "专门", "还特意", "省了"),
39
+ },
40
+ "愤怒": {
41
+ "event": ("骗", "坑", "违约", "毁约", "背刺", "甩锅", "篡改", "偷偷"),
42
+ "negate": ("太过分", "凭什么", "受不了", "气死", "离谱", "居然"),
43
+ },
44
+ "焦虑": {
45
+ "event": ("万一", "可能", "风险", "不确定", "担心会", "怕会", "要是"),
46
+ "negate": ("崩", "挂", "丢", "来不及", "回滚不了", "出问题", "出事"),
47
+ },
48
+ }
49
+
50
+ # 预期违背的方向(拆两向的关键):负向 = 失望/愤怒;正向 = 释然/满意
51
+ DIRECTION = {"失望": "neg", "释然": "pos", "满意": "pos", "感激": "pos",
52
+ "愤怒": "neg", "焦虑": "neg"}
53
+
54
+ _CLEAN = re.compile(r"\s+")
55
+
56
+
57
+ def label(text: str) -> dict:
58
+ """返回 {occ, direction, confidence, cues};识别不出返回 occ=""。"""
59
+ t = _CLEAN.sub(" ", str(text or ""))
60
+ if not t:
61
+ return {"occ": "", "direction": "", "confidence": 0.0, "cues": []}
62
+ best = None
63
+ for name, rule in RULES.items():
64
+ ev = [c for c in rule["event"] if c in t]
65
+ ng = [c for c in rule["negate"] if c in t]
66
+ if not ev or not ng:
67
+ continue
68
+ # 两类线索都命中才算;置信度按命中数(最多 1.0)
69
+ conf = min(1.0, 0.45 + 0.15 * (len(ev) + len(ng)))
70
+ if best is None or conf > best["confidence"]:
71
+ best = {"occ": name, "direction": DIRECTION.get(name, ""),
72
+ "confidence": round(conf, 3), "cues": (ev + ng)[:4]}
73
+ return best or {"occ": "", "direction": "", "confidence": 0.0, "cues": []}
74
+
75
+
76
+ def expected_violation(text: str) -> dict:
77
+ """只看"预期违背"这一族:负向(失望)还是正向(释然)。"""
78
+ d = label(text)
79
+ if d["occ"] in ("失望", "释然"):
80
+ return {"violated": True, "direction": d["direction"], "occ": d["occ"],
81
+ "confidence": d["confidence"]}
82
+ return {"violated": False, "direction": "", "occ": d["occ"],
83
+ "confidence": d["confidence"]}
84
+
85
+
86
+ def render(d: dict) -> str:
87
+ if not d.get("occ"):
88
+ return "(没识别出 OCC 类情绪)"
89
+ arrow = {"pos": "正向", "neg": "负向"}.get(d.get("direction", ""), "")
90
+ return f"OCC:{d['occ']}{('(' + arrow + '预期违背)') if d['occ'] in ('失望', '释然') else ''}" \
91
+ f" 置信度 {d['confidence']} 线索 {d['cues']}"
92
+
93
+
94
+ def run(args) -> int:
95
+ action = getattr(args, "occ_action", None) or "label"
96
+ text = getattr(args, "text", "") or ""
97
+ if action == "apply":
98
+ for line in render_apply(apply_emotion(
99
+ text, importance=float(getattr(args, "importance", 0.6) or 0.6),
100
+ dry_run=bool(getattr(args, "dry_run", False)))):
101
+ print(line)
102
+ return 0
103
+ if action == "violation":
104
+ print(render(expected_violation(text)) if expected_violation(text)["occ"]
105
+ else "(没有预期违背)")
106
+ return 0
107
+ print(render(label(text)))
108
+ return 0
109
+
110
+ # ---------------------------------------------------------------- 联动七情六欲
111
+
112
+ # OCC → 灵枢七情(组 + 具体情绪);polarity 给 emotion_evaluate 用
113
+ EMOTION_MAP = {
114
+ "失望": ("哀", "失落", "negative"),
115
+ "释然": ("静", "平静", "positive"),
116
+ "满意": ("喜", "满足", "positive"),
117
+ "感激": ("爱", "感动", "positive"),
118
+ "愤怒": ("怒", "生气", "negative"),
119
+ "焦虑": ("惧", "焦虑", "negative"),
120
+ }
121
+
122
+ # OCC → 六欲增减(正=满足/上调,负=受挫/下调)
123
+ DESIRE_DELTA = {
124
+ "失望": {"成就欲": -8.0, "连接欲": -2.0},
125
+ "释然": {"安全欲": 10.0},
126
+ "满意": {"成就欲": 10.0},
127
+ "感激": {"连接欲": 12.0},
128
+ "愤怒": {"连接欲": -6.0, "掌控欲": -3.0},
129
+ "焦虑": {"安全欲": -10.0},
130
+ }
131
+
132
+
133
+ def to_emotion(occ_name: str) -> dict:
134
+ """OCC 类 → 七情三元组(组/具体情绪/极性)。"""
135
+ g = EMOTION_MAP.get(str(occ_name or ""))
136
+ if not g:
137
+ return {"group": "", "emotion": "", "polarity": ""}
138
+ return {"group": g[0], "emotion": g[1], "polarity": g[2]}
139
+
140
+
141
+ def to_desires(occ_name: str) -> dict:
142
+ """OCC 类 → 六欲增减。"""
143
+ return dict(DESIRE_DELTA.get(str(occ_name or ""), {}))
144
+
145
+
146
+ def apply_emotion(text: str, importance: float = 0.6, dry_run: bool = False) -> dict:
147
+ """识别 OCC 并落到灵枢的情绪/欲望上(这就是"联动")。
148
+
149
+ - 情绪:走 `emotion_evaluate(event, polarity, importance, why)`,why 里带 OCC 标签便于追溯;
150
+ - 欲望:走 `desire_nudge(changes)` 增减六欲。
151
+ dry_run 只算不改。识别不出 OCC 时不动任何状态(不瞎记情绪)。
152
+ """
153
+ import brain
154
+ d = label(text)
155
+ occ_name = d.get("occ") or ""
156
+ if not occ_name:
157
+ return {"ok": False, "reason": "没识别出 OCC 情绪,不改状态", "occ": d}
158
+ emo = to_emotion(occ_name)
159
+ delta = to_desires(occ_name)
160
+ out = {"ok": True, "occ": occ_name, "direction": d.get("direction"),
161
+ "emotion": emo, "desires": delta, "dry_run": dry_run}
162
+ if dry_run:
163
+ return out
164
+ try:
165
+ out["emotion_result"] = brain.emotion_evaluate(
166
+ text, polarity=emo["polarity"], importance=float(importance),
167
+ why=f"OCC:{occ_name}")
168
+ except Exception as exc: # noqa: BLE001
169
+ out["emotion_error"] = str(exc)[:120]
170
+ if delta:
171
+ try:
172
+ out["desire_result"] = brain.desire_nudge(delta)
173
+ except Exception as exc: # noqa: BLE001
174
+ out["desire_error"] = str(exc)[:120]
175
+ return out
176
+
177
+
178
+ def render_apply(r: dict) -> list:
179
+ if not r.get("ok"):
180
+ return [f"跳过:{r.get('reason')}(OCC={r.get('occ', {}).get('occ') or '无'})"]
181
+ emo = r.get("emotion") or {}
182
+ lines = [f"OCC {r['occ']}({r.get('direction') or '—'})→ 七情「{emo.get('group')}·{emo.get('emotion')}」"]
183
+ if r.get("desires"):
184
+ lines.append(" 六欲:" + "、".join(f"{k}{v:+.0f}" for k, v in r["desires"].items()))
185
+ if r.get("dry_run"):
186
+ lines.append(" (干跑,未改动状态)")
187
+ for k in ("emotion_error", "desire_error"):
188
+ if r.get(k):
189
+ lines.append(f" ⚠ {k}: {r[k]}")
190
+ return lines