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
|
@@ -108,6 +108,11 @@ def _count_coverage(tracer: trace.Trace) -> dict:
|
|
|
108
108
|
# 每个文件的可执行行数:用 ast 之外最省事的办法——非空、非纯注释行
|
|
109
109
|
out = {}
|
|
110
110
|
for py in sorted(SCRIPTS.glob("*.py")):
|
|
111
|
+
# 跳过运维/探针脚本(下划线开头,如 _tmp_*、_smoke_*、_sync_*):
|
|
112
|
+
# 它们按设计就不会被 import,永远 0% 覆盖,混进榜单只会把"最低覆盖"刷满噪音
|
|
113
|
+
#(实测一份报告里 10 个最低项有 7 个是 _tmp_*)。
|
|
114
|
+
if py.name.startswith("_"):
|
|
115
|
+
continue
|
|
111
116
|
try:
|
|
112
117
|
lines = py.read_text(encoding="utf-8", errors="replace").splitlines()
|
|
113
118
|
except OSError:
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""记忆投递策略(#44 人格池分区 / #47 投递触发 / #50 寄生钩子 / #45 缓存守卫)。
|
|
4
|
+
|
|
5
|
+
统一在这里判"这条记忆该不该进上下文、要不要加权",**只读**、纯函数、可单测。
|
|
6
|
+
四个特性共享一次选择逻辑(避免三次改同一个地方)。
|
|
7
|
+
|
|
8
|
+
配置(config 里全是可选键,缺省即默认):
|
|
9
|
+
persona_pool 默认 true 人格演化池(kind=seed/gap 或 tags 命中)默认不进任务上下文
|
|
10
|
+
delivery_trigger 默认 false 记忆的 trigger 块命中当前上下文时加权
|
|
11
|
+
delivery_hooks 默认 false 记忆的 hooks(写时预埋)命中当前上下文时加权
|
|
12
|
+
prior_cooldown_sec 默认 300 同一 digest 的 prior 查询冷却(缓存守卫代理,见 §13.3)
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# 人格演化池:这些"不是任务知识,是灵枢自己的成长碎片"
|
|
17
|
+
PERSONA_KINDS = frozenset({"seed", "gap"})
|
|
18
|
+
PERSONA_TAGS = frozenset({"persona", "evolve", "self", "seed", "gap"})
|
|
19
|
+
|
|
20
|
+
# 自省类查询:只有这类才允许把人格局拉进上下文
|
|
21
|
+
SELF_CUES = ("我是谁", "自省", "人格", "成长", "灵枢自己", "你的感受", "你怎么想",
|
|
22
|
+
"persona self", "演化", "回看自己")
|
|
23
|
+
|
|
24
|
+
TRIGGER_WEIGHT = 0.18 # 触发命中:最多 +18%(和相关性同量级但更弱)
|
|
25
|
+
HOOK_WEIGHT = 0.15 # 钩子命中:最多 +15%
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def is_self_query(query: str) -> bool:
|
|
29
|
+
q = str(query or "").lower()
|
|
30
|
+
return any(c in q for c in SELF_CUES)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def is_persona_pool(m: dict) -> bool:
|
|
34
|
+
"""这条记忆属不属于"人格演化池"。"""
|
|
35
|
+
if str(m.get("kind") or "") in PERSONA_KINDS:
|
|
36
|
+
return True
|
|
37
|
+
tags = {str(t).lower() for t in (m.get("tags") or [])}
|
|
38
|
+
return bool(tags & PERSONA_TAGS)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _terms(text: str) -> set:
|
|
42
|
+
try:
|
|
43
|
+
import brain
|
|
44
|
+
return set(brain.terms(text))
|
|
45
|
+
except Exception:
|
|
46
|
+
return set(str(text or "").lower().split())
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def trigger_match(m: dict, ctx_terms: set) -> float:
|
|
50
|
+
"""#47:记忆自带的 trigger 是否命中当前上下文(0~1)。"""
|
|
51
|
+
tr = m.get("trigger")
|
|
52
|
+
if not isinstance(tr, dict):
|
|
53
|
+
return 0.0
|
|
54
|
+
kinds = {str(x) for x in (tr.get("topic_kinds") or [])}
|
|
55
|
+
words = {str(x) for x in (tr.get("terms") or [])}
|
|
56
|
+
hit = 0
|
|
57
|
+
if kinds & {str(t) for t in (m.get("tags") or [])}:
|
|
58
|
+
hit += 1
|
|
59
|
+
if words & ctx_terms:
|
|
60
|
+
hit += 1
|
|
61
|
+
base = float(tr.get("aggressiveness") or 0.5)
|
|
62
|
+
if hit == 0:
|
|
63
|
+
return 0.0
|
|
64
|
+
return min(1.0, base * (1.0 + 0.5 * (hit - 1)))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def hook_match(m: dict, ctx_terms: set) -> float:
|
|
68
|
+
"""#50:写记忆时预埋的钩子(词法近似)是否命中(0~1)。"""
|
|
69
|
+
hk = m.get("hooks")
|
|
70
|
+
if not isinstance(hk, dict):
|
|
71
|
+
return 0.0
|
|
72
|
+
near = {str(x) for x in (hk.get("near") or [])}
|
|
73
|
+
far = hk.get("far") if isinstance(hk.get("far"), dict) else {}
|
|
74
|
+
far_terms = {str(x) for x in (far.get("terms") or [])}
|
|
75
|
+
inter = (near | far_terms) & ctx_terms
|
|
76
|
+
if not inter:
|
|
77
|
+
return 0.0
|
|
78
|
+
return min(1.0, len(inter) / max(1, len(near | far_terms) ** 0.5) / 3.0)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def decide(m: dict, ctx_terms: set, query: str, cfg: dict) -> tuple:
|
|
82
|
+
"""返回 (keep, factor, reason)。
|
|
83
|
+
|
|
84
|
+
keep —— False 表示"这条不该进任务上下文"(人格池且非自省查询)。
|
|
85
|
+
factor—— 分数乘性因子(1.0 表示不加权)。
|
|
86
|
+
"""
|
|
87
|
+
cfg = cfg or {}
|
|
88
|
+
if cfg.get("persona_pool", True) and is_persona_pool(m) and not is_self_query(query):
|
|
89
|
+
return False, 1.0, "persona-pool"
|
|
90
|
+
factor = 1.0
|
|
91
|
+
reason = ""
|
|
92
|
+
if cfg.get("delivery_trigger"):
|
|
93
|
+
t = trigger_match(m, ctx_terms)
|
|
94
|
+
if t:
|
|
95
|
+
factor *= (1.0 + TRIGGER_WEIGHT * t)
|
|
96
|
+
reason = "trigger"
|
|
97
|
+
if cfg.get("delivery_hooks"):
|
|
98
|
+
h = hook_match(m, ctx_terms)
|
|
99
|
+
if h:
|
|
100
|
+
factor *= (1.0 + HOOK_WEIGHT * h)
|
|
101
|
+
reason = (reason + "+hooks") if reason else "hooks"
|
|
102
|
+
return True, factor, reason
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def attach_hooks(text: str, kind: str, topic: str = "") -> dict:
|
|
106
|
+
"""写记忆时生成钩子(只对 mistake/insight 有意义:它们最容易"重复踩坑")。"""
|
|
107
|
+
if str(kind or "") not in ("mistake", "insight"):
|
|
108
|
+
return {}
|
|
109
|
+
t = _terms(text)
|
|
110
|
+
# 近钩:文本里较长的词(更像具体对象);远钩:话题 + 同样的词(跨会话匹配)
|
|
111
|
+
near = sorted({x for x in t if len(x) >= 2}, key=len, reverse=True)[:6]
|
|
112
|
+
return {"near": near, "far": {"topic": str(topic or ""), "terms": near[:4]}}
|
package/scripts/dream.py
CHANGED
|
@@ -117,7 +117,36 @@ def replay_recent(limit: int = _REPLAY_MAX) -> list:
|
|
|
117
117
|
except Exception:
|
|
118
118
|
pass
|
|
119
119
|
items.sort(key=lambda x: x["ts"], reverse=True)
|
|
120
|
-
|
|
120
|
+
# §2 do-later(优先级重放):原来纯按时间截断——"昨晚 2 小时全调同一个 bug"时,
|
|
121
|
+
# 重放集被同质噪音占满,做梦等于对着一堆碎碎念做聚类。
|
|
122
|
+
# 这里做两道**只读**裁剪(不改库、不丢数据,只是选哪几条进梦):
|
|
123
|
+
# ① 与已选条目 jaccard ≥ 0.75 的跳过(同一件事换个说法);
|
|
124
|
+
# ② 同一 kind 最多占一半,避免单一类型霸榜;
|
|
125
|
+
# ③ 裁完不够 limit 时按原顺序回填,保证"条数不缩水"。
|
|
126
|
+
_lim = max(1, int(limit))
|
|
127
|
+
try:
|
|
128
|
+
from mem_score import jaccard as _jac, terms as _terms
|
|
129
|
+
_cap = max(1, _lim // 2 + 1)
|
|
130
|
+
_picked, _kept_terms, _kind_n, _rest = [], [], {}, []
|
|
131
|
+
for it in items:
|
|
132
|
+
if len(_picked) >= _lim:
|
|
133
|
+
_rest.append(it)
|
|
134
|
+
continue
|
|
135
|
+
_t = _terms(it.get("text") or "")
|
|
136
|
+
_dup = any(_jac(_t, kt) >= 0.75 for kt in _kept_terms)
|
|
137
|
+
if _dup or _kind_n.get(it.get("kind"), 0) >= _cap:
|
|
138
|
+
_rest.append(it)
|
|
139
|
+
continue
|
|
140
|
+
_picked.append(it)
|
|
141
|
+
_kept_terms.append(_t)
|
|
142
|
+
_kind_n[it.get("kind")] = _kind_n.get(it.get("kind"), 0) + 1
|
|
143
|
+
for it in _rest:
|
|
144
|
+
if len(_picked) >= _lim:
|
|
145
|
+
break
|
|
146
|
+
_picked.append(it)
|
|
147
|
+
return _picked[:_lim]
|
|
148
|
+
except Exception:
|
|
149
|
+
return items[:_lim]
|
|
121
150
|
|
|
122
151
|
|
|
123
152
|
def build_handoff(items: list, mode: str = "") -> dict:
|
|
@@ -1044,11 +1073,20 @@ def apply_dream(result: dict) -> dict:
|
|
|
1044
1073
|
rec["links"].append(old["id"])
|
|
1045
1074
|
applied.setdefault("superseded", []).append(old["id"])
|
|
1046
1075
|
# #19 留一组"合并前 → 合并后"对照,供事后抽检 AI 有没有改坏原意
|
|
1047
|
-
|
|
1076
|
+
_vp = {
|
|
1048
1077
|
"new_id": rec["id"],
|
|
1049
1078
|
"after": text,
|
|
1050
1079
|
"before": [{"id": old["id"], "text": str(old.get("text", ""))}],
|
|
1051
|
-
}
|
|
1080
|
+
}
|
|
1081
|
+
# §2 do-now #1:顺手算硬锚保留率(数字/版本/路径/日期/否定词/引号实体),
|
|
1082
|
+
# 让"压缩后丢了什么"从"只能人工看3组"变成可量化、可告警的数字。
|
|
1083
|
+
try:
|
|
1084
|
+
import anchor_retention as _ar
|
|
1085
|
+
_vp["anchor_retention"] = _ar.compare(
|
|
1086
|
+
str(old.get("text", "")), text)
|
|
1087
|
+
except Exception:
|
|
1088
|
+
pass
|
|
1089
|
+
_verify_pairs.append(_vp)
|
|
1052
1090
|
records.append(rec)
|
|
1053
1091
|
applied["memories"] += 1
|
|
1054
1092
|
for sid in rec["links"]:
|
package/scripts/emotion.py
CHANGED
|
@@ -437,14 +437,18 @@ def feel(name: str, intensity: float = 0.6, why: str = "",
|
|
|
437
437
|
rows = read_jsonl(HOME / "emotions.jsonl")
|
|
438
438
|
rows.append(ev)
|
|
439
439
|
write_jsonl(HOME / "emotions.jsonl", rows)
|
|
440
|
-
# ——
|
|
441
|
-
#
|
|
442
|
-
# 害怕想求稳。幅度按情绪强度缩放,强弱波动才真正影响欲望。
|
|
440
|
+
# —— 七情牵动六欲与感情状态机(自动微调)——
|
|
441
|
+
# 情绪大类映射到欲望与独立感情向量(亲和度 A、信任度 T、冲突 C、长期倾向 S)
|
|
443
442
|
grp = emotion_group(name)
|
|
444
443
|
if grp in DESIRE_EMO_MAP:
|
|
445
444
|
scale = 0.5 + 0.5 * eff # 强度 0~1 → 缩放 0.5~1.0
|
|
446
445
|
desire_nudge({k: round(v * scale, 2)
|
|
447
446
|
for k, v in DESIRE_EMO_MAP[grp].items()})
|
|
447
|
+
# 牵动更新独立感情状态机
|
|
448
|
+
try:
|
|
449
|
+
affection_nudge_from_emotion(name, eff)
|
|
450
|
+
except Exception as _e_aff:
|
|
451
|
+
log_event("mood", f"感情状态机更新失败:{_e_aff}", level="warn")
|
|
448
452
|
# 心境沉淀:把这次情绪事件折进 EMA 心境账(下一刻的"心情"就有了惯性)
|
|
449
453
|
mood_record_ema(mood_now())
|
|
450
454
|
return ev
|
|
@@ -572,6 +576,12 @@ def _apply_label_gate(v: float, a: float, active, base_label: str,
|
|
|
572
576
|
"pending_events": len(active or [])})
|
|
573
577
|
_save_gate(st)
|
|
574
578
|
return base_label
|
|
579
|
+
# 回归中性(平静)无需门控粘滞:如果当下的真实感受和主导情绪已经回到平静,不该被上一个情绪(如失落)死死卡住
|
|
580
|
+
if base_label in _NEUTRAL_LABELS:
|
|
581
|
+
st.update({"label": base_label, "valence": round(v, 3),
|
|
582
|
+
"pending": "", "count": 0, "pending_events": 0})
|
|
583
|
+
_save_gate(st)
|
|
584
|
+
return base_label
|
|
575
585
|
delta = abs(v - cur_v) if cur_v is not None else 1.0
|
|
576
586
|
if base_label == cur:
|
|
577
587
|
# 方向没变:清掉待定,同步当前值(继续慢慢累积)
|
|
@@ -666,7 +676,10 @@ def mood_now(at: float | None = None) -> dict:
|
|
|
666
676
|
if _neg_mult > 1.0 and _num(ev.get("valence"), 0) < 0:
|
|
667
677
|
half *= _neg_mult # 负面更耐放:半衰期变长 → 衰减更慢
|
|
668
678
|
w = _num(ev.get("intensity"), 0.5) * (0.5 ** (age_h / half))
|
|
669
|
-
|
|
679
|
+
# 遗留微波截断门槛��
|
|
680
|
+
# 如果事件权重已经衰减到 0.05 以下(余波已微乎其微),不再作为活跃事件维持负面/特殊标签,
|
|
681
|
+
# 否则几天前的一条小情绪会因为浮点数残留一直占据 active[0],导致概览卡片永远卡在旧情绪。
|
|
682
|
+
if w < 0.05:
|
|
670
683
|
continue
|
|
671
684
|
_g = emotion_group(ev.get("emotion", ""))
|
|
672
685
|
_until = _cool.get(_g)
|
|
@@ -1347,10 +1360,21 @@ def auto_appraise(text: str, config: dict | None = None) -> dict | None:
|
|
|
1347
1360
|
else "感动" if "感动" in t else "满足")
|
|
1348
1361
|
if emotion not in EMOTIONS:
|
|
1349
1362
|
return None
|
|
1363
|
+
# 提取对话中真正触发该情绪的那句话作为事由(不超 60 字),避免空泛
|
|
1364
|
+
sample_quote = ""
|
|
1365
|
+
# 优先找包含命中词的那句话
|
|
1366
|
+
for sent in re.split(r"[。!?\n;;!?]", t):
|
|
1367
|
+
s_clean = sent.strip()
|
|
1368
|
+
if any(h in s_clean for h in hits):
|
|
1369
|
+
sample_quote = s_clean[:60]
|
|
1370
|
+
break
|
|
1371
|
+
if not sample_quote:
|
|
1372
|
+
sample_quote = t[:60]
|
|
1373
|
+
|
|
1374
|
+
why_desc = f"对话触发「{'、'.join(hits[:3])}」(原话:“{sample_quote}”)"
|
|
1350
1375
|
feel(emotion, intensity=intensity,
|
|
1351
|
-
why=
|
|
1352
|
-
|
|
1353
|
-
about="对话", genesis=True)
|
|
1376
|
+
why=why_desc,
|
|
1377
|
+
about="用户对话", genesis=True)
|
|
1354
1378
|
return {"emotion": emotion, "intensity": intensity,
|
|
1355
1379
|
"polarity": polarity, "hits": hits[:3]}
|
|
1356
1380
|
|
|
@@ -1437,27 +1461,182 @@ def inner_voice() -> str:
|
|
|
1437
1461
|
return f"此刻是{label},还行"
|
|
1438
1462
|
|
|
1439
1463
|
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1464
|
+
# ---------------------------------------------------------------- 独立感情状态机(Affection System)
|
|
1465
|
+
# 借鉴用户设计的《独立感情算法》:
|
|
1466
|
+
# 瞬时情绪波动大(七情),但长期情感与羁绊是平滑沉淀的。
|
|
1467
|
+
# 模块1:持续变量 A(t) 亲和度 0~100、T(t) 信任度 0~100、C(t) 冲突标记 0/1、S(t) 长期情感倾向 [-1, 1]
|
|
1468
|
+
# 模块2:与七情六欲双向牵动——喜/爱提升亲和信任,怒/恶/悲伤加重冲突与信任磨损;
|
|
1469
|
+
# 连接欲被满足加深亲和,安全欲受挫激发防御;久不见自然淡泊回归基线。
|
|
1470
|
+
|
|
1471
|
+
AFFECTION_ALPHA = 0.92 # 长期感情遗忘/平滑系数(0.92 意味着长期感情平稳,不随一句话反转)
|
|
1472
|
+
AFFECTION_DECAY_PER_DAY = 0.3 # 长期静默每天向中性基线(50)自然回落 0.3 分
|
|
1473
|
+
|
|
1474
|
+
# 七情对感情向量的牵动强度 (affinity_delta, trust_delta, conflict_flag)
|
|
1475
|
+
AFFECTION_EMO_MAP = {
|
|
1476
|
+
"喜": (1.5, 1.0, 0),
|
|
1477
|
+
"爱": (2.5, 1.5, 0),
|
|
1478
|
+
"怒": (-2.0, -2.5, 1),
|
|
1479
|
+
"恶": (-2.5, -2.0, 1),
|
|
1480
|
+
"惧": (-0.5, -1.5, 0),
|
|
1481
|
+
"哀": (0.5, -0.5, 0), # 悲伤寻求安慰,亲和微增但信心受挫
|
|
1482
|
+
"欲": (1.0, 0.5, 0),
|
|
1483
|
+
"静": (0.0, 0.0, 0),
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
def affection_state(at: float | None = None) -> dict:
|
|
1488
|
+
"""读取当前独立感情状态机。未初始化自动给中性基线。"""
|
|
1489
|
+
p = load_persona()
|
|
1490
|
+
st = p.get("state") or {}
|
|
1491
|
+
aff = st.get("affection") or {}
|
|
1492
|
+
now = at or now_ts()
|
|
1493
|
+
|
|
1494
|
+
# 默认值
|
|
1495
|
+
affinity = _num(aff.get("affinity"), 60.0) # A(t) 亲和度 0~100
|
|
1496
|
+
trust = _num(aff.get("trust"), 65.0) # T(t) 信任度 0~100
|
|
1497
|
+
conflict = bool(aff.get("conflict", False)) # C(t) 冲突标记
|
|
1498
|
+
s_trend = _num(aff.get("trend"), 0.2) # S(t) 长期倾向 [-1, 1]
|
|
1499
|
+
updated = _num(aff.get("updated"), now)
|
|
1500
|
+
|
|
1501
|
+
# 模块3:自然衰减(长期静默变淡,但负向衰减慢)
|
|
1502
|
+
days = max(0.0, (now - updated) / DAY)
|
|
1503
|
+
if days > 0.5:
|
|
1504
|
+
# 向中性基线 50 回归
|
|
1505
|
+
for k, cur_val in (("affinity", affinity), ("trust", trust)):
|
|
1506
|
+
gap = 50.0 - cur_val
|
|
1507
|
+
step = min(abs(gap), days * AFFECTION_DECAY_PER_DAY)
|
|
1508
|
+
new_val = cur_val + (step if gap > 0 else -step)
|
|
1509
|
+
if k == "affinity": affinity = round(new_val, 2)
|
|
1510
|
+
if k == "trust": trust = round(new_val, 2)
|
|
1511
|
+
# S(t) 向 0 回归
|
|
1512
|
+
s_step = min(abs(s_trend), days * 0.05)
|
|
1513
|
+
s_trend = round(s_trend + (-s_step if s_trend > 0 else s_step), 3)
|
|
1514
|
+
|
|
1515
|
+
return {
|
|
1516
|
+
"affinity": affinity,
|
|
1517
|
+
"trust": trust,
|
|
1518
|
+
"conflict": conflict,
|
|
1519
|
+
"trend": s_trend,
|
|
1520
|
+
"updated": updated,
|
|
1521
|
+
"summary": _affection_summary(affinity, trust, conflict, s_trend)
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
def _affection_summary(a: float, t: float, c: bool, s: float) -> str:
|
|
1526
|
+
if c:
|
|
1527
|
+
return "当前处于分歧/冲突态(优先理性与客观依据,避免激化情绪)"
|
|
1528
|
+
if a >= 80 and t >= 80:
|
|
1529
|
+
return "深度信任与亲近(默契呼应,深度共情,减少说教)"
|
|
1530
|
+
if a >= 70:
|
|
1531
|
+
return "好感亲和(自然热情,主动理解)"
|
|
1532
|
+
if a <= 35:
|
|
1533
|
+
return "略显疏离(保持礼貌客气距离感)"
|
|
1534
|
+
if t <= 40:
|
|
1535
|
+
return "审慎防备(多拿事实说话,验证前提)"
|
|
1536
|
+
return "稳健平淡的信赖状态"
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
def affection_nudge_from_emotion(emo_name: str, intensity: float = 0.5) -> dict:
|
|
1540
|
+
"""由七情六欲牵动更新独立感情状态机。"""
|
|
1541
|
+
if READONLY:
|
|
1542
|
+
return affection_state()
|
|
1543
|
+
grp = emotion_group(emo_name)
|
|
1544
|
+
delta_a, delta_t, conf = AFFECTION_EMO_MAP.get(grp, (0.0, 0.0, 0))
|
|
1545
|
+
scale = 0.5 + 0.5 * max(0.0, min(1.0, float(intensity)))
|
|
1546
|
+
delta_a *= scale
|
|
1547
|
+
delta_t *= scale
|
|
1548
|
+
v, _ = _emotion_coord(emo_name)
|
|
1549
|
+
|
|
1550
|
+
now = now_ts()
|
|
1551
|
+
with _locked(HOME / "persona.json"):
|
|
1552
|
+
p = load_persona()
|
|
1553
|
+
st = p.setdefault("state", {})
|
|
1554
|
+
cur = st.get("affection") or {}
|
|
1555
|
+
|
|
1556
|
+
# 读当前值(结算衰减后)
|
|
1557
|
+
base_state = affection_state(now)
|
|
1558
|
+
a = base_state["affinity"]
|
|
1559
|
+
t = base_state["trust"]
|
|
1560
|
+
s = base_state["trend"]
|
|
1561
|
+
|
|
1562
|
+
# 更新 S(t) = alpha * S_{t-1} + (1 - alpha) * E_t
|
|
1563
|
+
s_new = round(AFFECTION_ALPHA * s + (1.0 - AFFECTION_ALPHA) * v, 3)
|
|
1564
|
+
|
|
1565
|
+
# 更新 A(t) 与 T(t)(边际递减饱和上限)
|
|
1566
|
+
if delta_a > 0:
|
|
1567
|
+
margin = (100.0 - a) / 50.0 # 接近 100 增益递减
|
|
1568
|
+
a = min(100.0, a + delta_a * max(0.2, margin))
|
|
1569
|
+
else:
|
|
1570
|
+
# 负向事件影响更深(负向权重更大)
|
|
1571
|
+
a = max(0.0, a + delta_a * 1.25)
|
|
1572
|
+
|
|
1573
|
+
if delta_t > 0:
|
|
1574
|
+
margin = (100.0 - t) / 50.0
|
|
1575
|
+
t = min(100.0, t + delta_t * max(0.2, margin))
|
|
1576
|
+
else:
|
|
1577
|
+
t = max(0.0, t + delta_t * 1.3)
|
|
1578
|
+
|
|
1579
|
+
# 冲突标记
|
|
1580
|
+
if conf == 1 and intensity >= 0.6:
|
|
1581
|
+
c_new = True
|
|
1582
|
+
elif v > 0.4 and intensity >= 0.5:
|
|
1583
|
+
# 正面积极沟通可消解冲突
|
|
1584
|
+
c_new = False
|
|
1585
|
+
else:
|
|
1586
|
+
c_new = base_state["conflict"]
|
|
1587
|
+
|
|
1588
|
+
aff_data = {
|
|
1589
|
+
"affinity": round(a, 1),
|
|
1590
|
+
"trust": round(t, 1),
|
|
1591
|
+
"conflict": c_new,
|
|
1592
|
+
"trend": s_new,
|
|
1593
|
+
"updated": now
|
|
1594
|
+
}
|
|
1595
|
+
st["affection"] = aff_data
|
|
1596
|
+
atomic_json(HOME / "persona.json", p)
|
|
1597
|
+
return aff_data
|
|
1598
|
+
|
|
1443
1599
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
所以 genesis=True 基本就是"自动生成、反映真实对话 / 共情 / 评价"的那些事件,
|
|
1448
|
-
这才是用户想看的心情变化。
|
|
1600
|
+
def emotion_timeline(limit: int = 50, all_events: bool = True) -> list:
|
|
1601
|
+
"""心情流水:取最近 limit 条情绪事件(支持包含手动 feel、认知评价、自动生成),
|
|
1602
|
+
每条带时间、标签、强度、分类、极性、来源标记与简短原因——面板 emotion 页签的心情时间线用。
|
|
1449
1603
|
"""
|
|
1450
|
-
|
|
1604
|
+
all_rows = emotion_events(limit=limit * 3)
|
|
1605
|
+
if not all_events:
|
|
1606
|
+
rows = [r for r in all_rows if r.get("genesis")]
|
|
1607
|
+
else:
|
|
1608
|
+
rows = all_rows
|
|
1451
1609
|
rows = rows[:limit]
|
|
1452
|
-
|
|
1453
|
-
|
|
1610
|
+
res = []
|
|
1611
|
+
for r in rows:
|
|
1612
|
+
why_str = str(r.get("why") or "")
|
|
1613
|
+
# 如果是 OCC 或带有评价事件,把触发的真实上下文事件拼入,避免只留抽象分类
|
|
1614
|
+
ev_ctx = ""
|
|
1615
|
+
evaluation = r.get("evaluation")
|
|
1616
|
+
if isinstance(evaluation, dict) and evaluation.get("event"):
|
|
1617
|
+
ev_ctx = str(evaluation.get("event")).strip()
|
|
1618
|
+
elif r.get("about"):
|
|
1619
|
+
ev_ctx = str(r.get("about")).strip()
|
|
1620
|
+
|
|
1621
|
+
if ev_ctx:
|
|
1622
|
+
if why_str and not why_str.endswith(ev_ctx):
|
|
1623
|
+
full_why = f"{why_str} (事由:{ev_ctx})"
|
|
1624
|
+
else:
|
|
1625
|
+
full_why = ev_ctx
|
|
1626
|
+
else:
|
|
1627
|
+
full_why = why_str
|
|
1628
|
+
|
|
1629
|
+
res.append({
|
|
1454
1630
|
"ts": r.get("ts", 0),
|
|
1455
1631
|
"time": fmt_time(r.get("ts", 0)) if _num(r.get("ts"), 0) else "",
|
|
1456
1632
|
"label": r.get("emotion", ""),
|
|
1457
1633
|
"intensity": round(_num(r.get("intensity"), 0), 2),
|
|
1458
|
-
"
|
|
1459
|
-
"
|
|
1634
|
+
"valence": round(_num(r.get("valence"), 0), 2),
|
|
1635
|
+
"category": r.get("category", "") or emotion_group(r.get("emotion", "")),
|
|
1636
|
+
"why": full_why[:160],
|
|
1460
1637
|
"about": r.get("about", ""),
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1638
|
+
"source": "auto" if r.get("genesis") else ("occ" if str(r.get("why", "")).startswith("OCC:") else "manual"),
|
|
1639
|
+
})
|
|
1640
|
+
return res
|
|
1641
|
+
|
|
1642
|
+
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""缺口记忆(gap memory,#51,§11 六)。
|
|
4
|
+
|
|
5
|
+
普通记忆存"答案/结论",这里存**当时没想通的地方**:
|
|
6
|
+
|
|
7
|
+
gap_type 缺口类型(思维缺口 / 能力缺口 / 信息缺口)
|
|
8
|
+
unsolved_branch 当时卡在什么地方
|
|
9
|
+
reject_reason 为什么当时没有落地
|
|
10
|
+
latent_potential 未来满足什么条件才可以重启这条分支
|
|
11
|
+
maturity 成熟度 0~1(后台按时间/新线索上涨)
|
|
12
|
+
|
|
13
|
+
为什么有用:人格成长的驱动力不只来自新输入,也来自"过去遗留的未完成支线"——
|
|
14
|
+
缺口成熟到阈值就自己浮出来提醒:"很久以前你在这里卡住了,现在的你也许能重新走。"
|
|
15
|
+
|
|
16
|
+
设计约束:
|
|
17
|
+
· 不新开存储:仍是 `kind=gap` 的记忆,能 recall、能淡忘、能归档;
|
|
18
|
+
· 不改 `remember()` 签名(它被全项目高频调用)——先写再补字段,读改写放在写锁里;
|
|
19
|
+
· `maturity` 只涨不降(缺口要么被解决=标记 done,要么一直留着等)。
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import json
|
|
24
|
+
|
|
25
|
+
import brain # 必须走 brain:它才是把各子模块命名空间回灌的入口(
|
|
26
|
+
# 单独 import memory 会缺 compile_persona 之类的跨模块名字,实测 NameError)
|
|
27
|
+
import core
|
|
28
|
+
memory = brain # load_all/save_all/remember 都从 brain 取
|
|
29
|
+
from core import DAY, _num, now_ts
|
|
30
|
+
|
|
31
|
+
MATURITY_INIT = 0.1
|
|
32
|
+
MATURITY_CAP = 0.9
|
|
33
|
+
SURFACE_THRESHOLD = 0.6
|
|
34
|
+
GAP_KIND = "gap"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def add(text: str, gap_type: str = "思维缺口", unsolved_branch: str = "",
|
|
38
|
+
reject_reason: str = "", latent_potential: str = "",
|
|
39
|
+
maturity: float = MATURITY_INIT, tags=None, importance: float = 0.5) -> str:
|
|
40
|
+
"""写入一条缺口记忆,返回 id。"""
|
|
41
|
+
res = memory.remember(
|
|
42
|
+
f"[缺口] {text}",
|
|
43
|
+
kind=GAP_KIND,
|
|
44
|
+
importance=importance,
|
|
45
|
+
tags=["gap", *(tags or [])],
|
|
46
|
+
source="manual",
|
|
47
|
+
)
|
|
48
|
+
# remember() 返回的是 tuple(record, 动作),不是 id;且 kind 会被内部归一(gap→fact),
|
|
49
|
+
# 所以这里取 id + 在补字段的同一次写锁里把 kind 一并改回。这两点都踩过。
|
|
50
|
+
mid = ""
|
|
51
|
+
if isinstance(res, tuple) and res:
|
|
52
|
+
first = res[0]
|
|
53
|
+
mid = (first.get("id") if isinstance(first, dict) else str(first)) or ""
|
|
54
|
+
elif isinstance(res, dict):
|
|
55
|
+
mid = res.get("id") or ""
|
|
56
|
+
else:
|
|
57
|
+
mid = str(res or "")
|
|
58
|
+
if not mid:
|
|
59
|
+
raise RuntimeError(f"remember() 没返回可用 id:{res!r}")
|
|
60
|
+
with core._locked(core.HOME / "hippocampus.jsonl"):
|
|
61
|
+
recs = memory.load_all()
|
|
62
|
+
for m in recs:
|
|
63
|
+
if m.get("id") == mid:
|
|
64
|
+
m["kind"] = GAP_KIND # 覆盖 remember 的归一结果
|
|
65
|
+
m["gap_type"] = gap_type
|
|
66
|
+
m["unsolved_branch"] = str(unsolved_branch or "")[:400]
|
|
67
|
+
m["reject_reason"] = str(reject_reason or "")[:400]
|
|
68
|
+
m["latent_potential"] = str(latent_potential or "")[:400]
|
|
69
|
+
m["maturity"] = min(MATURITY_CAP, max(0.0, float(maturity)))
|
|
70
|
+
m["gap_open"] = True
|
|
71
|
+
break
|
|
72
|
+
memory.save_all(recs)
|
|
73
|
+
return mid
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def list_gaps(include_closed: bool = False) -> list:
|
|
77
|
+
rows = [m for m in memory.load_all() if str(m.get("kind") or "") == GAP_KIND]
|
|
78
|
+
if not include_closed:
|
|
79
|
+
rows = [m for m in rows if m.get("gap_open", True)]
|
|
80
|
+
return sorted(rows, key=lambda m: -_num(m.get("maturity"), 0.0))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def age(bump: float = 0.05, min_days: int = 7, cap: float = MATURITY_CAP,
|
|
84
|
+
dry_run: bool = False) -> dict:
|
|
85
|
+
"""让"放置够久"的缺口缓慢成熟(只涨不降)。
|
|
86
|
+
|
|
87
|
+
为什么按时间:现在没有"新能力/新工具"这类可靠信号(§11 已说明缺信号),
|
|
88
|
+
时间是最朴素也最不容易造假的代理——放久了的坑,值得再想一次。
|
|
89
|
+
"""
|
|
90
|
+
if core.READONLY and not dry_run:
|
|
91
|
+
raise PermissionError("记忆库当前只读,无法更新缺口。")
|
|
92
|
+
now = now_ts()
|
|
93
|
+
aged = 0
|
|
94
|
+
touched = []
|
|
95
|
+
with core._locked(core.HOME / "hippocampus.jsonl"):
|
|
96
|
+
recs = memory.load_all()
|
|
97
|
+
for m in recs:
|
|
98
|
+
if str(m.get("kind") or "") != GAP_KIND or not m.get("gap_open", True):
|
|
99
|
+
continue
|
|
100
|
+
created = _num(m.get("created"), now)
|
|
101
|
+
if (now - created) < int(min_days) * DAY:
|
|
102
|
+
continue
|
|
103
|
+
cur = _num(m.get("maturity"), MATURITY_INIT)
|
|
104
|
+
nxt = min(cap, cur + float(bump))
|
|
105
|
+
if nxt > cur + 1e-9:
|
|
106
|
+
m["maturity"] = round(nxt, 3)
|
|
107
|
+
m["matured_at"] = now
|
|
108
|
+
aged += 1
|
|
109
|
+
touched.append({"id": m.get("id"), "from": round(cur, 3), "to": m["maturity"]})
|
|
110
|
+
if aged and not dry_run:
|
|
111
|
+
memory.save_all(recs)
|
|
112
|
+
return {"aged": aged, "dry_run": dry_run, "items": touched[:20]}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def surface(threshold: float = SURFACE_THRESHOLD) -> list:
|
|
116
|
+
"""成熟度到阈值的缺口——该浮出来提醒"当年卡在哪"。"""
|
|
117
|
+
return [m for m in list_gaps()
|
|
118
|
+
if _num(m.get("maturity"), 0.0) >= float(threshold)]
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def close(memory_id: str, how: str = "") -> bool:
|
|
122
|
+
"""标记缺口已解决(不删原文,留作演化痕迹)。"""
|
|
123
|
+
with core._locked(core.HOME / "hippocampus.jsonl"):
|
|
124
|
+
recs = memory.load_all()
|
|
125
|
+
hit = False
|
|
126
|
+
for m in recs:
|
|
127
|
+
if m.get("id") == memory_id and str(m.get("kind") or "") == GAP_KIND:
|
|
128
|
+
m["gap_open"] = False
|
|
129
|
+
m["gap_closed_at"] = now_ts()
|
|
130
|
+
if how:
|
|
131
|
+
m["gap_closed_how"] = str(how)[:300]
|
|
132
|
+
hit = True
|
|
133
|
+
break
|
|
134
|
+
if hit:
|
|
135
|
+
memory.save_all(recs)
|
|
136
|
+
return hit
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def render(rows: list) -> list[str]:
|
|
140
|
+
if not rows:
|
|
141
|
+
return ["(没有缺口记忆)"]
|
|
142
|
+
out = []
|
|
143
|
+
for m in rows:
|
|
144
|
+
out.append(f"{m.get('id')} 成熟 {round(_num(m.get('maturity'), 0) * 100)}% "
|
|
145
|
+
f"[{m.get('gap_type') or '缺口'}] {(m.get('text') or '')[:60]}")
|
|
146
|
+
for key, label in (("unsolved_branch", "卡在"), ("reject_reason", "当时没做"),
|
|
147
|
+
("latent_potential", "重启条件")):
|
|
148
|
+
v = (m.get(key) or "").strip()
|
|
149
|
+
if v:
|
|
150
|
+
out.append(f" {label}:{v[:70]}")
|
|
151
|
+
return out
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def run(args) -> int:
|
|
155
|
+
action = getattr(args, "gap_action", None) or "list"
|
|
156
|
+
if action == "add":
|
|
157
|
+
mid = add(args.text, gap_type=args.gap_type or "思维缺口",
|
|
158
|
+
unsolved_branch=args.unsolved or "", reject_reason=args.reject or "",
|
|
159
|
+
latent_potential=args.potential or "",
|
|
160
|
+
maturity=float(getattr(args, "maturity", MATURITY_INIT) or MATURITY_INIT))
|
|
161
|
+
print(f"已记下缺口:{mid}")
|
|
162
|
+
return 0
|
|
163
|
+
if action == "age":
|
|
164
|
+
r = age(bump=float(getattr(args, "bump", 0.05) or 0.05),
|
|
165
|
+
min_days=int(getattr(args, "min_days", 7) or 7),
|
|
166
|
+
dry_run=bool(getattr(args, "dry_run", False)))
|
|
167
|
+
print(f"成熟度更新 {r['aged']} 条" + ("(干跑)" if r["dry_run"] else ""))
|
|
168
|
+
for it in r["items"][:8]:
|
|
169
|
+
print(f" {it['id']} {it['from']} → {it['to']}")
|
|
170
|
+
return 0
|
|
171
|
+
if action == "surface":
|
|
172
|
+
rows = surface(float(getattr(args, "threshold", SURFACE_THRESHOLD) or SURFACE_THRESHOLD))
|
|
173
|
+
if not rows:
|
|
174
|
+
print(f"还没有成熟到 {SURFACE_THRESHOLD:.0%} 的缺口。")
|
|
175
|
+
return 0
|
|
176
|
+
print("这些坑,现在的你也许能重新走:")
|
|
177
|
+
for line in render(rows):
|
|
178
|
+
print(line)
|
|
179
|
+
return 0
|
|
180
|
+
if action == "close":
|
|
181
|
+
ok = close(args.id, how=getattr(args, "how", "") or "")
|
|
182
|
+
print("已关闭" if ok else "没找到这个缺口")
|
|
183
|
+
return 0 if ok else 1
|
|
184
|
+
for line in render(list_gaps()):
|
|
185
|
+
print(line)
|
|
186
|
+
return 0
|